Re: Compare the values of two sorted arrays of variable size.



You're looking for aRay1 - aRay2 and aRay2 - aRay1:

'Assume aRay1 and aRay2
Dim aRay2m1, aRay1m2
'First we need a quick way to test whether an element is in aRay1
Set oDict = CreateObject("Scripting.Dictionary")
For i = LBound(aRay1) to UBound(aRay1)
If Not oDict.Exists(aRay1(i)) Then oDict.Add aRay1(i), True
Next
'This section computes all values in aRay2 not in aRay1
aRay2m1 = Array()
For i = LBound(aRay2) to UBound(aRay2)
If oDict.Exists(aRay2(i)) Then
oDict.Item(aRay2(i)) = False
Else
Append aRay2m1, aRay2(i)
End If
Next
'This section computes all values in aRay1 not in aRay2
aRay1m2 = Array()
For each i in oDict.Keys
If oDict.Item(i) Then Append aRay1m2, i
Next

Sub Append (byRef aRay, val)
If LBound(aRay)<UBound(aRay) Then
aRay = Array(val)
Else
Redim Preserve aRay(UBound(aRay)+1)
aRay(uBound(aRay)) = val
End If
End Sub

Csaba Gabor from Vienna

.