vb比对两个listbox中不同值
Private Sub Command1_Click()
Dim t As String, j As Long, s As String, lst1 As Object, lst2 As Object, t1 As String
List3.Clear
If List1.ListCount >= List2.ListCount Then
Set lst2 = List1
Set lst1 = List2
Else
Set lst1 = List1
Set lst2 = List2
End If
For j = 0 To lst1.ListCount - 1
t = t & "{" & lst1.List(j) & "}"
Next
Debug.Print t
For j = 0 To lst2.ListCount - 1
s = "{" & lst2.List(j) & "}"
If InStr(t, s) > 0 Then
Else
If InStr(t1, s) <= 0 Then
List3.AddItem lst2.List(j)
t1 = t1 & s
End If
End If
Next
End Sub
Private Sub Form_Load()
List1.AddItem "ssdsd1"
List1.AddItem "ssds21"
List1.AddItem "ssd3d1"
List1.AddItem "ss23dsd1"
List1.AddItem "ss3d1"
List2.AddItem "ssdsd1"
List2.AddItem "ssds21"
List2.AddItem "ssd31d1"
List2.AddItem "ss23dsd1"
List2.AddItem "ss31d1"
List2.AddItem "ss301d1"
List2.AddItem "ss31d1"
Command1.Caption = "找出不同"
End Sub