by James McCord (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Thu 14th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Compare two list boxes and add the difference to a third. Uses conditional loops. Good for comparing values. Could be used to compare file
'Add a Command button named Command1
'Place this code in a form
Private Sub Command1_Click()
Dim x, y As Integer
Dim result As Boolean
'Set to false UNTIL it finds a match, then it's TRUE
result = False
For x = 0 To List1.ListCount - 1
For y = 0 To List2.ListCount - 1
If List1.List(x) = List2.List(y) Then
result = True
End If
Next y
If result = False Then
List3.AddItem List1.List(x)
End If
result = False
Next x
Compare2 'Now loop through list2
End Sub
Private Sub Form_Load()
' I added these values for testing
List1.AddItem "a"
List1.AddItem "b"
List1.AddItem "d"
List2.AddItem "a"
List2.AddItem "d"
List2.AddItem "f"
List2.AddItem "t"
End Sub
Private Sub Compare2()
Dim x, y As Integer
Dim result As Boolean
For x = 0 To List2.ListCount - 1
For y = 0 To List1.ListCount - 1
If List2.List(x) = List1.List(y) Then
result = True
End If
Next y
If result = False Then
List3.AddItem List2.List(x)
End If
result = False
Next x
End Sub
No comments have been posted about Compare two list boxes and add the difference to a third. Uses conditional loops. Good for comparin. Why not be the first to post a comment about Compare two list boxes and add the difference to a third. Uses conditional loops. Good for comparin.