Hello,
I have a textbox when double clicked displays a lstbox for a selection, but sometimes the user will manually enter something in the txtbox. So how can I loop through the lstbox to compare the entry to the txtbox without showing the lstbox.
Printable View
Hello,
I have a textbox when double clicked displays a lstbox for a selection, but sometimes the user will manually enter something in the txtbox. So how can I loop through the lstbox to compare the entry to the txtbox without showing the lstbox.
VB Code:
For x = 0 To List1.ListCount - 1 If Text1.Text Like List1.List(x) Then 'do something End If Next
I trust you can make it invisible.
You could loop through the values but you don't need to.
VB Code:
Public Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As String) As Long Public Const CB_FINDSTRING = &H14C ' This is for a combobox Public Const LB_FINDSTRING = &H18F Dim lngRetVal As Long lngRetVal = SendMessageString MyListBox.hwnd, _ LB_FINDSTRING, -1&, _ Text1.Text) ' lngRetVal is the ListIndex If lngRetVal > -1& Then ' It's in the list and lngRetVal is the ListIndex Else ' It's not in the list End If
Thank you for your replies, but can someone tell me why this won't work.
txtReason.Text = "DE"
lstReason has several items
but one is "DE: Description"
[code]
txtReason.Text = UCase(txtReason.Text)
For i = 0 To lstReason.ListCount - 1
tmp = Trim(txtReason.Text)
lst = lstReason.Text
cnt = InStrRev(lst, ":")
lst = Left(lst, cnt - 1)
If tmp = lst Then
bPass = True
GoTo Jump_Out
Else
bPass = False
End If
Next i
Jump_Out:
If Not bPass Then
lblMsg.Caption = txtReason.Text & "is not a valid Reason"
txtReason.SetFocus
End If
[code]
what are tmp and lst values?
Just variables to hold the value I could do it straight out, but I have a bad habit of doing things the hard way. I am trying to break up the string and pull the first 2 values to compare.
VB Code:
txtReason.Text = Trim(UCase(txtReason.Text)) For i = 0 To lstReason.ListCount - 1 lst = lstReason.List(i) cnt = InStrRev(lst, ":") lst = Left(lst, cnt - 1) If tmp = lst Then bPass = True Exit For Else bPass = False End If Next i If Not bPass Then lblMsg.Caption = txtReason.Text & "is not a valid Reason" txtReason.SetFocus End If
Thank you it works great.