-
i have three listboxes:
one is filled with numbers(LONG).
the second is filled with numbers(LONG).
the numbers in the second could be duplicates
of what is in the first listbox, and even those
numbers may be listed more than twice.
how can i do a search using the number from the
first listbox and pulling the same number(s) from
the second listbox and add those that are found to
the third listbox.
this thing has me confused, plus fighting the flu while
trying to think...
thankx for all help,
larryn
-
Try this out:
Code:
For x = 0 To List1.ListCount - 1
For y = 0 To List2.ListCount - 1
If List1.List(x) = List2.List(x) Then Exit For
Next y
If y < List2.ListCount Then List3.AddItem List1.List(x)
Next x
-
that was pretty fast coding,
but the part:
Code:
If List1.List(x) = List2.List(x) Then Exit For
List2.List(x) does not loop through the list,
it stays on the first number for the times there
are numbers in the second listbox.
is there a way to get it to loop?
-
Uhh, kedaman, I dont think that will work. Normally in a For/Next loop you do something with the variable you are using for the loop counter, but your code in the "For y..." loop keeps checking the same thing. I think you might need to change it to this:
Code:
For x = 0 To List1.ListCount - 1
For y = 0 To List2.ListCount - 1
If List1.List(x) = List2.List(y) Then Exit For
Next y
If y < List2.ListCount Then List3.AddItem List1.List(x)
Next x
-
Sorry guys! hope that got clear now :)
-
you guys are great, thankx!