Results 1 to 10 of 10

Thread: difficult - list, split, search?? <solved>

  1. #1

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472

    difficult - list, split, search?? <solved>

    I have a listbox which contains a lot of documents and file titles which can range to be anything just about.

    I need to be able to search the listbox with my string but not search word for word same case, but to search each letter in the item on the entire list.

    For instance... say im looking for "Machine" and in my list I have

    Fox runs fast
    big brown bear
    great_white dear
    redmachine of time
    etc...

    I need to be able to pick up "machine" from the 4th item down...
    Since I had no idea how to do this, I tried to split each item (by the spaces) then search for the parts using:

    Code:
    Private Sub Command1_Click()
    For i = 0 To List1.ListCount - 1
    List1.List(i) = Split(List1.List(i), " ")
    If Text1.Text = List1.List(i) Then
    List1.Selected(i) = True
    Exit For
    End If
    Next
    End Sub
    but not fully sure on how I can split each one and if possible, it needs to be more of a defined way of doing it, eg the way I showed at the start - but if someone knows how I can search it using my split idea with the spaces, that would be great as well

    Thanks
    sac
    Last edited by Sacofjoea; Jun 15th, 2002 at 03:00 PM.

  2. #2

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    also this does not work:

    Code:
    For i = 0 To List1.ListCount - 1
    spltme = List1.List(i)
    MsgBox spltme
    compairme = Split(spltme, " ")
    If Text1.text = compairme Then
    List1.Selected(i) = True
    Exit For
    End If
    Next
    which I tried to put it into a variable then compair it, but i get a 'Type Mismatch' when I attempt to compair it or even try to view the variable 'compairme'

  3. #3

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    argh, perhaps i should learn how to use commands before I attempt them lol

    Code:
    Dim Compairme() As String
    For i = 0 To List1.ListCount - 1
    spltme = List1.List(i)
    chrs = Len(spltme)
    Compairme = Split(spltme, " ")
    For z = 0 To chrs
        If Text1.text = Compairme(z) Then
            List1.Selected(i) = True
            Exit For
        End If
    Next z
    Next
    prob now is, 'Subscript out of range' ?? at the comparison part with text1.text and compairme(z)

    im sleepy must be why im catching these things like a min after i post

  4. #4

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    ok the prob that isn't working is because im finding all of the chars in the string when I need to be finding all of the words seperated by spaces (or so I think is why)

    gonna leave it at that and get some sleep
    any help appreciated

    sac

  5. #5

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    so anyone have any ideas??

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    A few words... since you like trying things out (and searching). Learn about the Instr function.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    thanks, works very well

    Code:
    For i = 0 To List1.ListCount - 1
    spltme = List1.List(i)
    'strng = what you are searching for...
    Compairme = InStr(spltme, strng)
    'if your string is found...
    If Compairme > 0 Then
        List1.Selected(i) = True
        Exit For
    End If
    Next i
    Last edited by Sacofjoea; Jun 15th, 2002 at 02:59 PM.

  8. #8
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I knew you would figure it out!!

    Good work!!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    And I guess you've learnt much more than if I would have written you the code.... haven't you?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10

    Thread Starter
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    lol well didn't want anyone to write the code, just needed an idea/method of doing it - which you gave me
    sac

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