difference in arrays

Hi all,

I picked up this function from the internet and I am trying to modify it to do the following:
I have the following fields on the form:

testdate1 = multivalued date fields which has all the testdates for the period
testdate2 = testdate1, computed to itself and set to the value of 1 if null(testdate1 which will never change), with this field, I am always trying to keep a complete list of testdate1 in case some test dates gets deleted from it. This way also using the next function we will be able to erase all dates which are the same in testdate1 and testdate2 and keep the reminder which are those dates that got deleted at some stage of testdate1
resultdate = list of those deleted dates from testdate1 and are found in testdate2

Here's the function and I'll place the sentence "my modifications" next to those lines that I am modifying. Could you pls help me clarify if this will work. I have attempted to get it to work and it didn't so maybe I am setting wrong variables


Function DifferentArrayItems (a1 As Variant, a2 As Variant) As Variant
'** return an array that has all the elements in array a1
'** array a2 that are different

my modifications

a1 = doc.testdate1(0)
a2 = doc.testdate2(0)



On Error Goto processError
Dim returnArray As Variant
Dim tempList List As Variant
Dim count As Integer


my modifications
returnarray = doc.resultdate(0)

'** convert a2 into a list, for easier searching
If Isscalar(a2) Then
tempList(a2) = a2
Else
Forall stuff In a2
tempList(stuff) = stuff
count = count + 1
End Forall
End If
'** initialize the return array
Redim returnArray(0 To count)
'** check all the elements in a1 against the new list we made
count = 0
If Isscalar(a1) Then
If Iselement(tempList(a1)) Then
Erase tempList(a1)
Else
returnArray(count) = a1
count = count + 1
End If
Else
Forall element In a1
If Iselement(tempList(element)) Then
Erase tempList(element)
Else
returnArray(count) = element
count = count + 1
End If
'** make sure we have room in the returnArray
If (count = Ubound(returnArray)) Then
Redim Preserve returnArray(0 To count + 50)
End If
End Forall
End If
'** now add anything that's still left in tempList, which will be
'** things in a2 that weren't in a1
Forall leftover In tempList
'** Listtag always returns a String, so we want to use the
'** list element instead
'returnArray(count) = Listtag(leftover)
returnArray(count) = leftover
count = count + 1
'** make sure we have room in the returnArray
If (count = Ubound(returnArray)) Then
Redim Preserve returnArray(0 To count + 50)
End If
End Forall
'** resize the return array down, so it will have the right
'** number of elements
If (count = 0) Then
Erase returnArray
Else
Redim Preserve returnArray(0 To count - 1)
End If
'** give the returnArray back to the user
DifferentArrayItems = returnArray
Exit Function
processError:
Print "Error " & Err & ": " & Error$
Redim returnArray(0)
Erase returnArray

my modifications, redim array, otherwise, i get the using uninitialized dynamic array error

Redim Preserve returnArray(0 To count + 50)

DifferentArrayItems = returnArray
Exit Function
End Function


Thank you in advance

varvouraAsked:
Who is Participating?
 
SysExpertCommented:
With no  connection to the actual formulas, I would suggest that you make sure that you never hit the 32 K limit of the field holding the old test dates ( history ).

Yo may need to archive yearly and recreate depending on testing frequency.

I hope this helps !

0
 
varvouraAuthor Commented:
one more modification

If I declare a third array a3 as variant, could I then set the value of differentarrayitems to that array at the end

for example,

DifferentArrayItems = returnArray
dim d3 as variant
d3 = doc.resultdate(0)
d3 = differentarrayitems
Exit Function
End Function



0
 
varvouraAuthor Commented:

Thanks for your advise, I'll keep that in mind.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.