List comparison in LS

Sorry, it’s probably an easy question, but I’m stuck anyway and can’t find help with the words I was searching for…

I have to check with LS if a field has changed. I have the old value in field OldPhases and the new value in field Phases. Both fields are multivalue.

I can check if Ubound of one field is higher than the other. But in case both are of equal length I still need to check, if the entries are identical. I don’t care about the order, so a:b:c and c:a:b would be the same to me.

Do I really need to move through all entries of one field and compare everyone with all entries of the other field? What a mess…

identical equal same similar

lists arrays fields

</search words>

Subject: list comparison in LS

Use Evaluate.

Subject: list comparison in LS

This function will tell you whether the two arrays are different by returning True (false if both arrays contain the same values, regardless of order), and will return the changes in the “out” arrays addedVals and removedVals:

Function GetDelta(oldVals As Variant, newVals As Variant, removedVals As Variant, addedVals As Variant) As Boolean

removedVals = Fulltrim(Arrayreplace(oldVals, newVals, ""))

addedVals = Fulltrim(Arrayreplace(newVals, oldVals, ""))

If (removedVals(0) = "") And (addedVals(0) = "") Then

	GetDelta = False

Else

	GetDelta = True

End If

End Function

Caveat: this will not work if the field can contain the same value more than once. In that case, you would need to do an element-by-element comparison, making sure that the number of occurences of each value is the same in each array.