Results 1 to 9 of 9

Thread: filter thingy

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2017
    Posts
    10

    filter thingy

    trying to have all instances of a character typed in a textbox removed from a list box(the whole line).this is what i have so far:

    Code:
    Private Sub filter_Click()
       Dim i As Integer
         For i = 0 To List1.ListCount - 1
            If Right(List1.List(i), 1) = Text1.Text Then List1.RemoveItem (i)
          Next i
       Label1.Caption = List1.ListCount
    End Sub
    it kinda works(sometimes)but i can't fix it.pretty sure it's the "if right" part is the problem but it's way beyond my skills.only been doing this less than a week.thanks for any help.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,538

    Re: filter thingy

    Hard to determine exactly what you are doing? Can you give us an example of what the list items may contain and what Text1 may contain?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2017
    Posts
    10

    Re: filter thingy

    Quote Originally Posted by LaVolpe View Post
    Hard to determine exactly what you are doing? Can you give us an example of what the list items may contain and what Text1 may contain?

    list might contain:

    person@mail.com
    127.0.0.1
    #rep

    depending on what file the person wants to load into the list box.i'm mainly using it for proxy addresses.the text box would have what the person wants removed.like any line that has "#,@,*,%," etc.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,538

    Re: filter thingy

    So, the textbox is a comma-delimited filter of sorts? I assume you are splitting the textbox and processing each 'token'?

    Sounds like you want to compare the start of the listbox items to the current token, i.e.,
    If Left$(List1.List(i), Len(sToken)) = sToken Then ' hit

    Or if any part of the list item can match:
    If InStr(List1.List(i), sToken) > 0 Then ' hit

    Note: That if looking for an exact match or partial match at the beginning of the list items, APIs can be far faster to find hits. Search forum for these key words: LB_FINDSTRING and LB_FINDSTRINGEXACT. The API usage cannot do partial matches unless the match starts at the beginning of the list item.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2017
    Posts
    10

    Re: filter thingy

    Quote Originally Posted by LaVolpe View Post
    So, the textbox is a comma-delimited filter of sorts? I assume you are splitting the textbox and processing each 'token'?

    Sounds like you want to compare the start of the listbox items to the current token, i.e.,
    If Left$(List1.List(i), Len(sToken)) = sToken Then ' hit

    Or if any part of the list item can match:
    If InStr(List1.List(i), sToken) > 0 Then ' hit

    Note: That if looking for an exact match or partial match at the beginning of the list items, APIs can be far faster to find hits. Search forum for these key words: LB_FINDSTRING and LB_FINDSTRINGEXACT. The API usage cannot do partial matches unless the match starts at the beginning of the list item.



    wow,way over my head lol.to simplify:a person loads their text file into List1 and there items that contain the character "@"......they type "@" in Text1 and every line that has "@" is removed.sorry i didn't explain it better before.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,538

    Re: filter thingy

    Sounds like you want to compare the start of the listbox items to the current token, i.e.,
    Code:
    If Left$(List1.List(i), Len(Text1.Text) = Text1.Text Then ' hit
    Above is likely what you are looking for. When you gave the textbox content example of "#,@,*,%," I was interpreting that as the textbox value, not what you appear to be clarifying which would be interpreted as "#", "@", "*", etc.

    Edited: After re-reading your last post, this line "they type "@" in Text1 and every line that has "@" is removed". You are looking for the 2nd example I posted in my previous reply
    Code:
    If InStr(List1.List(i), Text1.Text) > 0 Then ' hit
    Tip: If case-sensitivity is not wanted:
    Code:
    If InStr(1, List1.List(i), Text1.Text, vbTextCompare) > 0 Then ' hit
    Last edited by LaVolpe; Jul 1st, 2017 at 10:13 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2017
    Posts
    10

    Re: filter thingy

    Quote Originally Posted by LaVolpe View Post
    Sounds like you want to compare the start of the listbox items to the current token, i.e.,
    Code:
    If Left$(List1.List(i), Len(Text1.Text) = Text1.Text Then ' hit
    Above is likely what you are looking for. When you gave the textbox content example of "#,@,*,%," I was interpreting that as the textbox value, not what you appear to be clarifying which would be interpreted as "#", "@", "*", etc.

    Edited: After re-reading your last post, this line "they type "@" in Text1 and every line that has "@" is removed". You are looking for the 2nd example I posted in my previous reply
    Code:
    If InStr(List1.List(i), Text1.Text) > 0 Then ' hit
    Tip: If case-sensitivity is not wanted:
    Code:
    If InStr(1, List1.List(i), Text1.Text, vbTextCompare) > 0 Then ' hit



    replaced:

    Code:
    Private Sub filter_Click()
       Dim i As Integer
         For i = 0 To List1.ListCount - 1
            If Right(List1.List(i), 1) = Text1.Text Then List1.RemoveItem (i)
          Next i
       Label1.Caption = List1.ListCount
    End Sub


    with:
    Code:
    Private Sub filt_Click()
        Dim i As Integer
           For i = 0 To List1.ListCount - 1
        If Left$(List1.List(i), Len(Text1.Text) = Text1.Text Then ' hit
           Next i
         Label1.Caption = List1.ListCount
       End Sub

    couldn't get it to work....

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,538

    Re: filter thingy

    No offense, but I just gave you a replacement for this part of your original code: If Right(List1.List(i), 1) = Text1.Text
    Why it didn't work, because you are not doing anything once your determined a hit. In fact, you should have gotten an error: no End If

    Re-read my edited text in previous reply. You'll want to use the InStr() function to find partial matches anywhere in the list item. For example, Left() won't work if @ is in the middle of the text. InStr() will work.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2017
    Posts
    10

    Re: filter thingy

    Quote Originally Posted by LaVolpe View Post
    No offense, but I just gave you a replacement for this part of your original code: If Right(List1.List(i), 1) = Text1.Text
    Why it didn't work, because you are not doing anything once your determined a hit. In fact, you should have gotten an error: no End If

    Re-read my edited text in previous reply. You'll want to use the InStr() function to find partial matches anywhere in the list item. For example, Left() won't work if @ is in the middle of the text. InStr() will work.



    ok,thanks for your help.i'm sure if i go through all the previous posts i'll get it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width