Results 1 to 3 of 3

Thread: List Box Question

  1. #1

    Thread Starter
    Member JPRoy392's Avatar
    Join Date
    Aug 2000
    Posts
    50

    Question

    I need to know if any occurance of a list box contains the string "Black". So far, I found out to find the first occurance, but if there are multiple items in a list box, I don't want to test each individual item in a list. There must be an easier way. My code so far:

    Code:
     If Ink.List(0) = "Black" Then
                MsgBox "test succeed"
     End If
    I don't want to:
    Code:
     If Ink.List(0) = "Black" or Ink.List(1) = "Black" Then
                MsgBox "test succeed"
     End If
    Thank you for any help.
    Jim

    "...head is all empty and I don't care..."

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You don't want to check each listbox entry individualy, but how about a loop to check it? it's not that much work!

    Code:
    Private Sub Form_Load()
    Static x As Long
    'Add some stuff
    List1.AddItem "jop"
    List1.AddItem "JPRoy392"
    List1.AddItem "black"
    List1.AddItem "white"
    List1.AddItem "green"
    
    'Loop trough all listItems
    For x = 0 To List1.ListCount
    If List1.List(x) = "black" Then
    'If black then show
    MsgBox "Listbox item " & x & " is black"
    End If
    Next
    End Sub
    Have fun!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Oh and if you really insist not checking all the listbox items you always have the api!

    http://www.mvps.org/vbnet/code/lista...glistitems.htm

    Hope I was of any help to you!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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