I need to compare two arrays to see if they are different in any way. Once it determined that they are different than I need to execute some logic to send an e-mail.
In a form on QueryOpen I need to loop through data in a multi value field and store the data in a variable. Then when the document is saved I loop through the same field again to see if any changes have been made. If so, I get the names listed in the field and kick out a new e-mail…otherwise do nothing.
I am using lotus script and have been creating a global var array that I can check on postsave, but have not gotten really far and keep getting type mismatch errors.
What is the correct way to do this? Can I just compare them like two vars?
If array1 = array2 then
Or do I need to loop through the data first and assign it to a var and compare those?
Subject: Best way to Compare arrays?
post the code you have so far
Use the Join function to create 2 string variables then compare the strings and if they are different then you know that some value in one of the array’s has changed.
Subject: RE: Best way to Compare arrays?
Been looking for the forums and was able to get a better idea of what I should do.
I need to get the current list of items on post-open event convert them to a string and then compare that with the items on Post-Save (convert those to string) and compare them. Is that correct?
Some code I was working on below
Dim Found As Variant
Dim AssigneeGroups As Variant
Dim newval() As String
AssigneeSource = doc.Assignee
AssigneeSource = Join(AssigneeSource)
AssigneeNew = uidoc.FieldGetText(“Assignee”)
AssigneeNew = Split(AssigneeNew, “;”)
ind = 0
Forall p In AssigneeNew
found = Instr(AssigneeSource, Cstr(p))
If found = 0 Then
ind = ind + 1
Redim Preserve newval(ind) As String
newval(ind) = p
End If
End Forall
AssigneeGroups = Join(newval)
Msgbox AssigneeGroups
Subject: RE: Best way to Compare arrays?
You need to clarify your requirements.
In your original posting you said, that you want to detect, if the arrays “are different in any way”. Changes to the order of values make to array “different in any way” for sure. So, if you want to detect this kind of changes as well, stick with what Paul told you: Just join both multi-value fields and do a simple string comparison.
If the order of values is not a concern, you need a more complex logic. You’ll have to loop through the new values and see, if any of them is missing in the original values. However, in this case it makes no sense at all to join the original values into a string. Likewise, it makes no sense to retrieve the values through a UI method
AssigneeNew = uidoc.FieldGetText(“Assignee”)
and then split the result, when
uidoc.doc.Assignee
would just return the array you need. Have a look a the ArrayGetIndex function for finding new values.