Results 1 to 3 of 3

Thread: searching list boxes

  1. #1
    suck_my_wognuts
    Guest

    Question searching list boxes

    on a form i have a listbox a textbox and a command button.
    the listbox is full of 6 digit numbers. I want to be able to enter a 6 digit number into the text box then press the button and it will find the 6 digit number in the listbox, then return the index or if the 6 digit number is in the list.+

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    what the hell is a wognut ?

    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
    3. Private Const LB_FINDSTRING = &H18F
    4.  
    5. Private Sub Form_Load()
    6. With List1
    7. .Clear
    8. .AddItem "CPU"
    9. .AddItem "RAM"
    10. .AddItem "ROM"
    11. .AddItem "Cache"
    12. .AddItem "Motherboard"
    13. .AddItem "Hard Disk"
    14. .AddItem "Floppy Disk"
    15. End With
    16. End Sub
    17.  
    18.  
    19. Private Sub Text1_Change()
    20. List1.ListIndex = SendMessage(List1.hWnd, LB_FINDSTRING, -1, ByVal Text1.Text)
    21. Text1.Text = List1.Text
    22. End Sub
    -= a peet post =-

  3. #3
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    Private Sub cmdFind_Click()
    Dim i As Integer
    Dim myIndex As Integer

    myIndex = -1
    For i = 0 To lstReceiver.ListCount - 1
    lstReceiver.ListIndex = i
    If lstReceiver = txtReceiver Then
    myIndex = i
    MsgBox "found it at " & cstr(myIndex)
    Exit For
    End If
    Next i

    If myIndex = -1 Then
    MsgBox "couldn't find the $^#%& thing!"
    End If

    End Sub

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