|
-
May 17th, 2001, 01:14 AM
#1
Thread Starter
Member
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
-
May 17th, 2001, 03:51 AM
#2
Fanatic Member
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]
-
May 17th, 2001, 07:36 AM
#3
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"
-
May 18th, 2001, 03:46 AM
#4
Fanatic Member
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]
-
May 18th, 2001, 06:11 AM
#5
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|