|
-
Jun 17th, 2000, 10:12 AM
#1
Thread Starter
Junior Member
Hello i what to compare 2 list box and msg the user that item that are not in the 2 listbox this is what i have up to now but i am stuck
any idea ?

thank's 
For i = 0 To List1.ListCount - 1
For X = 0 To List2.ListCount
If List1.List(i) = List2.List(X) Then
Else
MsgBox List1.List(i)
End If
Next X
Next i
-
Jun 17th, 2000, 12:03 PM
#2
I might be able to help you with this, but I am not sure what it is you want to do. Could you state your problem more clearly?
"It's cold gin time again ..."
Check out my website here.
-
Jun 17th, 2000, 09:09 PM
#3
Thread Starter
Junior Member
o.k this is what i what to do !
i have list1: with ithem
Hello1
Hello2
Hello3
i have list2: with ithem
Hello1
Hello2
Hello3
Hello4
i what to Msgbox the Hello4 since the item is only in one listbox
-
Jun 17th, 2000, 10:06 PM
#4
OK, I think I've got you covered. Try this example:
Put two listboxes on the form. IMPORTANT: Make sure the SORTED property of both is set to TRUE.
Put a command button on your form (caption might be "Compare").
Copy and paste this code into your form:
Code:
Option Explicit
Private Sub Form_Load()
With List1
.AddItem "aardvark"
.AddItem "bird"
.AddItem "dog"
.AddItem "elephant"
.AddItem "hippo"
End With
With List2
.AddItem "aardvark"
.AddItem "bird"
.AddItem "cat"
.AddItem "dog"
.AddItem "hippo"
.AddItem "rhino"
End With
End Sub
Private Sub Command1_Click()
Dim intList1X As Integer
Dim intList2X As Integer
Dim intI As Integer
intList1X = 0
intList2X = 0
Do Until intList1X > (List1.ListCount - 1) Or intList2X > (List2.ListCount - 1)
If List1.List(intList1X) = List2.List(intList2X) Then
' We have a match, so just look at the next item
' in each box (by advancing the index for each)
intList1X = intList1X + 1
intList2X = intList2X + 1
ElseIf List1.List(intList1X) < List2.List(intList2X) Then
' This is a situation where we have an item in List1
' that is not in List2. Display a message, and only
' advance the index for List1
MsgBox "The item '" & List1.List(intList1X) _
& "' is in List1 but not in List2."
intList1X = intList1X + 1
Else
' The only other condition we could have here is that
' List1.List(intList1X) > List2.List(intList2X).
' This is a situation where we have an item in List2
' that is not in List1. Display a message, and only
' advance the index for List2.
MsgBox "The item '" & List2.List(intList2X) _
& "' is in List2 but not in List1."
intList2X = intList2X + 1
End If
Loop
' At this point, we have looked at all of the items in at least one
' of the lists. Any remaining items in either list have no match.
' To display these, loop thru the remaining items of each list,
' starting with the last value of our index variable. The loop for the
' list whose items we have exhausted will never execute.
For intI = intList1X To List1.ListCount - 1
MsgBox "The item '" & List1.List(intI) _
& "' is in List1 but not in List2."
Next
For intI = intList2X To List2.ListCount - 1
MsgBox "The item '" & List2.List(intI) _
& "' is in List2 but not in List1."
Next
End Sub
Good luck. Please post again to let me know if this is what you need.
"It's cold gin time again ..."
Check out my website here.
-
Jun 24th, 2000, 11:22 PM
#5
Thread Starter
Junior Member
Hey thank's But i only to compare one listbox
and i given eache item a new index:
List1.AddItem text1.text
List1.ItemData(List1.NewIndex) = Text2.Tet
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|