Efficient compare of two arrays?

# Thread: Efficient compare of two arrays?

1. Junior Member
Join Date
Dec 1969
Posts
8

## Efficient compare of two arrays?

Hello, <BR><BR>I need to compare two different two-dimensional arrays. Both of which have a column that stores an employee ID (empID). I need to pull a value from the first array where the empID matches the empID of the second array. I&#039;ve included an example of the two arrays below if that will help any.<BR><BR>rateArray<BR>(0,0) = 17 <BR>(1,0) = \$150.00<BR>(0,1) = 19<BR>(1,1) = \$175.00<BR>...<BR><BR>timeArray<BR>(0,0) = 17<BR>(1,0) = 1.5 hours<BR>(0,1) = 17<BR>(1,1) = 2 hours<BR>(0,2) = 17<BR>(1,2) = 1 hours<BR>(0,3) = 19<BR>(1,3) = 5 hours<BR>(0,4) = 19<BR>(1,4) = 2.5 hours<BR>...<BR><BR>Basically I&#039;m trying to multiply the rate for a person by the time each person put in and then find the dollar sum each person has accumulated. The rateArray has each empID only once, while the timeArray could contain each empID multiple times.<BR><BR>Any help or advice is greatly appreciated. <BR><BR>Thanks,<BR><BR>Leo

2. Senior Member
Join Date
Dec 1969
Posts
213

## RE: Efficient compare of two arrays?

It looks like it may be more efficient to store the rates in a dictionary object, where the employee ID is the key and the rate is the value. Then you can loop through your time array like so:<BR><BR>For i = 0 to ubound(timeArray,2)<BR>id = timeArray(0, i)<BR>hours = timeArray(1, i)<BR>sometotal = sometotal + hours * objRate.Item(id)<BR>Next i<BR><BR>This is pretty sloppy but I hope it gives you some help.

3. Junior Member
Join Date
Dec 1969
Posts
8

## RE: Efficient compare of two arrays?

Excellent, that worked much much better than what I&#039;ve been attempting. I did some "group bys" in the select generating the timeArray, so now it&#039;s calculating the sumtotal for me. <BR><BR>Thanks for the help!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•