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
Printable View
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
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
Usage: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
Code:If CBFindString("MyString", Combo1) = True Then MsgBox "String found"
Was my way any good or not Megatron?
(just curious...)
WIN32API will be more advantage when the combo box item going bigger and bigger...