Results 1 to 8 of 8

Thread: *Resolved * Looping If lstbox Not Visible

  1. #1

    Thread Starter
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163

    *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.

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    VB Code:
    1. For x = 0 To List1.ListCount - 1
    2. If Text1.Text Like List1.List(x) Then
    3. 'do something
    4. End If
    5. Next

    I trust you can make it invisible.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You could loop through the values but you don't need to.
    VB Code:
    1. Public Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _
    2.                       (ByVal hwnd As Long, _
    3.                        ByVal wMsg As Long, _
    4.                        ByVal wParam As Long, _
    5.                        ByVal lParam As String) As Long
    6. Public Const CB_FINDSTRING = &H14C ' This is for a combobox
    7. Public Const LB_FINDSTRING = &H18F
    8.  
    9.         Dim lngRetVal As Long
    10.  
    11.         lngRetVal = SendMessageString MyListBox.hwnd, _
    12.                                       LB_FINDSTRING, -1&, _
    13.                                       Text1.Text)
    14.         ' lngRetVal is the ListIndex
    15.         If lngRetVal > -1& Then
    16.             ' It's in the list and lngRetVal is the ListIndex
    17.         Else
    18.             ' It's not in the list
    19.         End If

  4. #4

    Thread Starter
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163
    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.

  5. #5
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    what are tmp and lst values?

  6. #6

    Thread Starter
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163
    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.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. txtReason.Text = Trim(UCase(txtReason.Text))
    2.     For i = 0 To lstReason.ListCount - 1
    3.         lst = lstReason.List(i)
    4.         cnt = InStrRev(lst, ":")
    5.         lst = Left(lst, cnt - 1)
    6.         If tmp = lst Then
    7.             bPass = True
    8.             Exit For
    9.         Else
    10.             bPass = False
    11.         End If
    12.     Next i
    13.    
    14.     If Not bPass Then
    15.         lblMsg.Caption = txtReason.Text & "is not a valid Reason"
    16.         txtReason.SetFocus
    17.     End If

  8. #8

    Thread Starter
    Addicted Member Renee K's Avatar
    Join Date
    Jun 2002
    Posts
    163
    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
  •  



Click Here to Expand Forum to Full Width