M
marston.gould
I have two rather large arrays (150,000 x 50) or so each
The first element of each row is a reference value.
I need to 1) check to see if each reference value in the 2nd array is
contained in the first. If it is then I need to go to that row in each
array and add the values in columns 2-50, if not, I need to append (or
insert) the values from the 2nd array into the first.
I know that the reference values are unique in each set of arrays (e.g.
no two rows contain the same reference value in any one array). I also
know that I can keep the 1st array sorted by reference number as items
are appended to it.
Both of the latter are through some sorting routines I have graciously
obtained from others.
Right now, I have a routine that loops through each array ....
But the problem with this procedure is that most of the comparisons are
not used and thus it wastes a lot of time. I'm looking for a faster way
to say immediately check to see if the reference value from the
SecondArray exists in the FirstArray, if so, then go to that location
and do a summation of all the columns (except the reference) and if
not, add the items from the SecondArray into the First.
For i = LBound(SecondArray,1) to Ubound(SecondArray,1)
check = false
For j = LBound(FirstArray,1) to UBound(FirstArray,1)
If FirstArray(j,1) = SecondArray(i,1) Then
check = true
For k = 2 to 50
FirstArray(j,k) = FirstArray(j,k) + SecondArray(i,k)
Next k
End If
Next j
If check Is false Then
ResizeArray FirstArray, Ubound(FirstArray,1)+1, 50
For k = 1 to 50
FirstArray(Ubound(FirstArray,1),k) = SecondArray(i,k)
Next k
QuickSort FirstArray,Lbound(FirstArray,1),LBound(FirstArray,1),
UBoundFirstArray,1),True
Next i
Thanks is Advance,
Marston
The first element of each row is a reference value.
I need to 1) check to see if each reference value in the 2nd array is
contained in the first. If it is then I need to go to that row in each
array and add the values in columns 2-50, if not, I need to append (or
insert) the values from the 2nd array into the first.
I know that the reference values are unique in each set of arrays (e.g.
no two rows contain the same reference value in any one array). I also
know that I can keep the 1st array sorted by reference number as items
are appended to it.
Both of the latter are through some sorting routines I have graciously
obtained from others.
Right now, I have a routine that loops through each array ....
But the problem with this procedure is that most of the comparisons are
not used and thus it wastes a lot of time. I'm looking for a faster way
to say immediately check to see if the reference value from the
SecondArray exists in the FirstArray, if so, then go to that location
and do a summation of all the columns (except the reference) and if
not, add the items from the SecondArray into the First.
For i = LBound(SecondArray,1) to Ubound(SecondArray,1)
check = false
For j = LBound(FirstArray,1) to UBound(FirstArray,1)
If FirstArray(j,1) = SecondArray(i,1) Then
check = true
For k = 2 to 50
FirstArray(j,k) = FirstArray(j,k) + SecondArray(i,k)
Next k
End If
Next j
If check Is false Then
ResizeArray FirstArray, Ubound(FirstArray,1)+1, 50
For k = 1 to 50
FirstArray(Ubound(FirstArray,1),k) = SecondArray(i,k)
Next k
QuickSort FirstArray,Lbound(FirstArray,1),LBound(FirstArray,1),
UBoundFirstArray,1),True
Next i
Thanks is Advance,
Marston