I am starting to feel completely dumb when it comes to VB.Net coding. I am using Visual Studio 2010 and am trying to compare the numbers in 2 listboxes. If an item from list A matches an item from list B, I want it to add that item to List C. Once it has added the item to List C, remove those searched items from list A & B. Continue until it runs out of numbers to check.
If you are wondering what I am trying to do, I want to make a Common Factor list. I already have the Factoring list done, but got stuck here.
So far, my code looks like
Private Sub CommonFactors(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Common.Click
Dim BoolAdd As Boolean, i As Double, j As Double
BoolAdd = False
' lstFact1 & lstFact2 are the factor listboxes
' lstCommon is where the common factors are supposed to go
If lstFact1.Items.Count = 0 Then
Exit Sub
ElseIf lstFact2.Items.Count = 0 Then
Exit Sub
Else
For i = lstFact1.Items.Count - 1 To 0 Step -1
For j = 0 To lstFact2.Items.Count
If lstFact1.Items(i) = lstFact2.Items(j) Then
BoolAdd = True
Exit For
Else
BoolAdd = False
End If
Next j
If BoolAdd = True Then
lstCommon.Items.Add(lstFact1.Items(i))
lstFact1.Items.Remove(i)
lstFact2.Items.Remove(j)
End If
Next i
End If
End Sub
Thanks in advance for any help you can provide.