Comparing 2 Arrays Both Ways

Brianroyal
11-03-2004, 10:02 AM
Hi guys need some newbie help. I have looked all over the web and in all the books I have for a solution to this to no avail. What I have is an application that gets filenames from a specific directory; stores them into an array and also gets filenames out of a text file that is created in another program and stores those in an array. What my dilemma is is that I need to compare the first array with the second array and then compare the second array with the first array and put the data that is not the same from the first comparison into a listbox and then get the data from the second comparison and put it into a second listbox so that I know which one has different data. I hope this makes sense. I am having so much trouble learning about arrays and such. Thanks for any and all help guys.

rufen101
11-03-2004, 11:23 AM
Take a look at this code.


Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim found As Boolean

'List all the fileName from the first array that are not in the second one
For i = 0 To UBound(tab1)
found = False
For j = 0 To UBound(tab2)
If tab1(i) = tab2(j) Then
found = True
Exit For
End If
Next j
If Not found Then
List1.AddItem tab1(i)
End If
Next i

'List all the fileName from the second array that are not in the first one
For i = 0 To UBound(tab2)
found = False
For j = 0 To UBound(tab1)
If tab2(i) = tab1(j) Then
found = True
Exit For
End If
Next j
If Not found Then
List2.AddItem tab2(i)
End If
Next i

End Sub

Brianroyal
11-03-2004, 04:21 PM
Hey thnx for your help!!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum