|
-
Oct 10th, 2002, 01:54 PM
#1
Thread Starter
Addicted Member
*Resolved * Looping If lstbox Not Visible
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.
Last edited by Renee K; Oct 10th, 2002 at 02:35 PM.
.·*¨) ¸.·*¨) ¸.·*¨*
(¸.*´ ¸.·´*'~*Renee~* (¸.*´~*
Funny how the little things can stop you dead in your tracks. 
-
Oct 10th, 2002, 01:59 PM
#2
So Unbanned
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.
-
Oct 10th, 2002, 02:00 PM
#3
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
-
Oct 10th, 2002, 02:07 PM
#4
Thread Starter
Addicted Member
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]
.·*¨) ¸.·*¨) ¸.·*¨*
(¸.*´ ¸.·´*'~*Renee~* (¸.*´~*
Funny how the little things can stop you dead in your tracks. 
-
Oct 10th, 2002, 02:08 PM
#5
So Unbanned
what are tmp and lst values?
-
Oct 10th, 2002, 02:13 PM
#6
Thread Starter
Addicted Member
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.
.·*¨) ¸.·*¨) ¸.·*¨*
(¸.*´ ¸.·´*'~*Renee~* (¸.*´~*
Funny how the little things can stop you dead in your tracks. 
-
Oct 10th, 2002, 02:13 PM
#7
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
-
Oct 10th, 2002, 02:34 PM
#8
Thread Starter
Addicted Member
Thank you it works great.
.·*¨) ¸.·*¨) ¸.·*¨*
(¸.*´ ¸.·´*'~*Renee~* (¸.*´~*
Funny how the little things can stop you dead in your tracks. 
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
|