• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Find if itemdata value in listbox matches current variable

I have a piece of code which is pulling a value from an SQL table and assigning it to a variable called MVID.  I also have a listbox called lstAxis which has multiple select set on.  The 1st item in the listbox is "ALL" and after that it is populated with data which has a numeric value for each item's .itemdata.

What I need to do is run some code if the MVID variable matches EXACTLY a seleted item's .itemdata value or the ALL item.

I have looked at instr but that seems to throw up false negatives for instance if MVID = 2 then the code runs if the item's .itemdata is 2 or 222 or 123 etc.

Thanks in advance for your help  
0
simonwait
Asked:
simonwait
  • 2
1 Solution
 
ZhaolaiCommented:
Try this:
 
 If MVID = your item's .ItemData Then
 
0
 
simonwaitAuthor Commented:
But I need to check multiple items in the list as there could be several selected.  Is there a way of looping?
0
 
ZhaolaiCommented:
Try this:

    Dim i As Integer
    For i = 0 To List1.ListCount - 1
        If List1.Selected(i) Then
            If List1.ItemData(i) = MVID Then
                'match found
            End If
        End If
    Next

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now