Hi i am having two arrays "A" and "B". "A" is from Master form which contains active seller list. Another array "B" contains the the sellers list collected from Weblist.
Now i want to compare two arrays and confirm whether all elements from array "A" also available in array "B". Here i used below code and confirm. But i am struggling in one point to produce the fail results. So please give me the logic.
For i = 0 to Ubound(A)-1
For j = 0 to Ubound(B)-1
If A(i)<>"" and A(i) = B(j) then
But this code produces Fail result even in Pass scenarios.
So please give me some solution.
Public function CompareArrays( aArray1, aArray2 )
bReturn = true
If UBound( aArray1) = UBound( aArray2) Then
For i = 1 to UBound( aArray1 )
If aArray1(i) <> aArray2(i) Then
bReturn = false
bReturn = false
CompareArrays = bReturn
This would definitely fail as your programming logic is wrong. You are comparing one element of an array with all other elements and then you are deciding the pass and fail during the inner comparison only.
Look in the below post and i guess you would find some code to compare 2 arrays
''this function will compare both arrays returns the difference from second to a text file... you can ognore if you want a difference text file
Const FOR_WRITING = 2
strOutputFile = "C:\test\Differences.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strOutputFile) Then
Set objOutputFile = objFso.OpenTextFile(strOutputFile,FOR_WRITING)
Set objOutputFile = objFso.CreateTextFile(strOutputFile)
For Each strElementFirst In arrFirst
blnExistsInSecond = False
For Each strElementSecond In arrSecond
If strElementFirst = strElementSecond Then
blnExistsInSecond = True
If Not blnExistsInSecond Then
objOutputFile.WriteLine strElementFirst & " does not exist in the second array"
Set objOutputFile = Nothing
Set objFso = Nothing<hr noshade size="1">