Results 1 to 5 of 5

Thread: search combobox for string

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Galt, Ca
    Posts
    47

    Talking search combobox for string

    can someone tell me how to search a combobox for a string, and if the string is found the combobox returns a value of true to a variable? I tried using the SendMessage API, but couldn't quite get it

    thanks

    -emptywords

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    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 CB_FINDSTRINGEXACT = &H158
    Private Const CB_ERR = (-1)
    
    
    Private Sub Command1_Click()
    Dim lRet&
    Dim sFstr$
        sFstr = "HELLO12" & vbNullChar
        lRet = SendMessage(Combo1.hwnd, CB_FINDSTRINGEXACT, -1, ByVal sFstr)
    End Sub
    
    Private Sub Form_Load()
    Dim i%
    For i = 1 To 20
        Combo1.AddItem "HELLO" & i
    Next i
    End Sub
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Megatron
    Guest
    Code:
    Function CBFindString(ByVal sIn As String, CBX As ComboBox) As Boolean
        For I = 0 To CBX.ListCount - 1
            If UCase(CBX.List(i)) = UCase(sIn) Then
                CBFindString = True
                Exit Function
            End If
        Next I
        CBFindString = False
    End Function
    Usage:
    Code:
    If CBFindString("MyString", Combo1) = True Then MsgBox "String found"

  4. #4
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Was my way any good or not Megatron?

    (just curious...)
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    WIN32API will be more advantage when the combo box item going bigger and bigger...

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