Reputation: 118271
Please find the below code:
Option Explicit
Dim TempArr
Dim ArrListChildDetails : Set ArrListChildDetails = CreateObject("System.Collections.ArrayList")
Now I have assigned some Range object to it:
ArrListChildDetails = ob3.Cells(ParentMatchRowNum,Width+1).Resize(, UBound(TempArr, 1) + 1)
TempArr=ArrListChildDetails.ToArray()
ArrListChildDetails .Sort();
Now Is it possivle to compare both the array,if their elements are same and same positions and the count also? Means any IsEql()
available in ArrayList Class?
Upvotes: 1
Views: 1326
Reputation: 42182
Quick and dirty solution but in most cases sufficient:
WScript.Echo Join(ArrListChildDetails.ToArray(),"|") = Join(ArrListChildDetails2.ToArray(),"|")
EDIT: some explanation: to compare two ArrayLists (or two arrays), convert to an array and join them together to a string separated by some special character not used in the arrays and then compare the strings, of course this is only usable for one dimensional arrays with valuetypes which can be stringified. If they have the same sumber of elements with the same content the comparison will return -1 (true) and 0 (false) otherwise
Upvotes: 1
Reputation: 38745
I don't know, where you got the IsEqual() from, but you can use the ArrayList/Object method .Equals() to determine whether one ArrayList is refered to by another name/variable (cf. VBScript's Is operator).
To check whether the count, the order, and the elements of two different ArrayLists are equal, you'll have to roll your own function. To get you started:
Option Explicit
Dim alA : Set alA = CreateObject("System.Collections.ArrayList")
Dim alB : Set alB = CreateObject("System.Collections.ArrayList")
Dim alC : Set alC = CreateObject("System.Collections.ArrayList")
Dim alA2 : Set alA2 = alA
alA.Add "one"
alA.Add "two"
alB.Add "one"
alB.Add "two"
alC.Add "one"
alC.Add "owt"
WScript.Echo "alA: ", Join(AlA.ToArray())
WScript.Echo "alA2:", Join(AlA2.ToArray())
WScript.Echo "alB: ", Join(AlB.ToArray())
WScript.Echo "alC: ", Join(AlC.ToArray())
WScript.Echo "alA.Equals(alA2):", CStr(alA.Equals(alA2))
WScript.Echo "alA.Equals(alB):" , CStr(alA.Equals(alB))
WScript.Echo "alA.Equals(alC):" , CStr(alA.Equals(alC))
WScript.Echo "ALEqual(alA, alA):", CStr(ALEqual(alA, alA))
WScript.Echo "ALEqual(alA, alA2):", CStr(ALEqual(alA, alA2))
WScript.Echo "ALEqual(alA, alB):", CStr(ALEqual(alA, alB))
WScript.Echo "ALEqual(alA, alC):", CStr(ALEqual(alA, alC))
Function ALEqual(alL, alR)
ALEqual = True
If alL Is AlR Then Exit Function
ALEqual = alL.Count = alR.Count
If ALEqual Then
Dim i
For i = 0 To alL.Count - 1
If alL(i) <> alR(i) Then
ALEqual = False
Exit Function
End If
Next
End If
End Function
output:
alA: one two
alA2: one two
alB: one two
alC: one owt
alA.Equals(alA2): Wahr
alA.Equals(alB): Falsch
alA.Equals(alC): Falsch
ALEqual(alA, alA): Wahr
ALEqual(alA, alA2): Wahr
ALEqual(alA, alB): Wahr
ALEqual(alA, alC): Falsch
Upvotes: 1