Reputation: 91
I have 2 ListBoxes. ListBox1 is populated with 5 selected numbers from a CheckedListBox(LotteryBox) and ListBox2 is populated with random numbers 1-99. I want to find a way to verify if the numbers in the two ListBoxes match. For Example, if they matched one number. It'll say "You've matched one number". and so on. I think I'm on the right path with:
Dim Matched As Integer = 0
If ListBox2.Contains((LotteryBox.SelectedItem)) Then Matched += 1
If ListBox2.Contains((LotteryBox.SelectedItem)) Then Matched += 1
If ListBox2.Contains((LotteryBox.SelectedItem)) Then Matched += 1
If ListBox2.Contains((LotteryBox.SelectedItem)) Then Matched += 1
If ListBox2.Contains((LotteryBox.SelectedItem)) Then Matched += 1
But how do I differentiate between the five numbers selected in the LotteryBox?
Upvotes: 0
Views: 42
Reputation: 2015
Try looping trough the listbox1 that is populated from lotterybox. Somrthing like this (I didn't set up the objects to test this.)
For listItem = 0 To Listbox1.ListCount - 1
if ListBox2.Contains(listbox1.List(listItem)) Then Matched = Matched + 1
Next listitem
Upvotes: -1