Results 1 to 5 of 5

Thread: VB5 - Searching List?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    VB5 - Searching List?

    This has probably been asked before somewhere so sorry if it has but i can't find it. How would i go about searching a list for a word?

    So i've got my list that loads from a text file but i want to be able to insert a word into a textarea and click a search button and it to highlight the list entry containing that word?

    Thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: VB5 - Searching List?

    What "list" would that be? Listbox, Combobox, some grid, multi line text, etc..
    In case you need to search Listbox or combo try this:
    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                    (ByVal hwnd As Long, ByVal wMsg As Long, _
                     ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_FINDSTRING = &H18F
    Private Const LB_FINDSTRINGEXACT = &H1A2
    Private Const CB_FINDSTRING = &H14C
    
    Private Sub Command1_Click()
    Dim strText As String
    
        '''strText = InputBox("Prompt", "Title", "search text")
        strText = Text1.Text
        List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
    
    End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: VB5 - Searching List?

    Thanks, yeh it's a Listbox just that code doesn't seem to highlight the searched text. I press the search button and it doesn't give an error but also doesn't do anything. All the names are right aswell? :S

  4. #4

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: VB5 - Searching List?

    Ooo it works, thanks once again!

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