still researching this but....

# Thread: still researching this but....

1. Senior Member
Join Date
Dec 1969
Posts
299

## still researching this but....

can&#039;t find the answer. is there an easier way to find a variable in a 2-dim array instead of looping through it? I have an array of 6000 recs (converted from a RS) and have to loop through this array many times in one asp page. here&#039;s the part where i loop through the array:<BR><BR>For iRowLoop = 0 to UBound(arrVolumes, 2)<BR> &#039;Get year and compare with year (y) from beginning loop<BR> tcidd_ord = arrVolumes(0,iRowLoop)<BR> tcidd_ord = CStr(tcidd_ord)<BR> tcidd = arrT(cidd_id_ord,iRowLoop1)<BR> tcidd = CStr(tcidd)<BR><BR> tline_ord = arrVolumes(1,iRowLoop)<BR> tline_ord = CStr(tline_ord)<BR> tline = arrT(line_no_ord,iRowLoop1)<BR> tline = CStr(tline)<BR><BR> tyear_ord = arrVolumes(tvol_yr_no_ord,iRowLoop)<BR> tyear_ord = CStr(tyear_ord)<BR> <BR> &#039;If there is a match, put vol total in fvol <BR> If (tcidd_ord = tcidd) AND (tline_ord = tline) AND (tyear_ord = ty) Then<BR> ffound = True<BR> fvol = arrVolumes(tvol_total_ord,iRowLoop)<BR> tbase_99_val = arrVolumes(tbase_99_ord,iRowLoop)<BR> tbase_prev_val = arrVolumes(tbase_prev_yr_ord,iRowLoop)<BR> End If<BR>Next<BR><BR><BR>... takes forever to continuously loop through this array. would cut the time it takes to pull up the asp page by &#062;15minutes if i can eliminate continuously looping...

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## 15 minutes???

Ouch.<BR><BR>Why not alter your SELECT statement to make this more efficient?

3. Senior Member
Join Date
Dec 1969
Posts
299

## yup....

would love to but i can&#039;t. well, i should put it this way... i have a main loop that loops about 2000+ times... can&#039;t cut that down. want to but the requestor of this report insists it produce this many records on a page... anyways, the only way for me to cut down the loop (the 6000 loop one) is to get the recordset and populate the array with less records each 2000 time. querying for the recordset 2000 times takes just as much time as forgetting that and getting the recordset once with 6000+ records and looping through that 2000 times... a mess, huh?

4. Senior Member
Join Date
Dec 1969
Posts
2,930

## is the array sorted

and if so, is it sorted by the field you are searching through???

5. Senior Member
Join Date
Dec 1969
Posts
299

## good point but...

i eventually am using every element in that array so there will be a point i will have to loop up to 6000 to get that element.<BR><BR>i am also searching through 3 fields to get one. for instance here&#039;s an example of one entry in the array:<BR><BR>set up like:<BR>arrVolumes(0,1) = cidd_id<BR>arrVolumes(0,2) = line_no<BR>arrVolumes(0,3) = vol_yr<BR>arrVolumes(0,4) = base_price<BR><BR><BR>so... an example:<BR>arrVolumes(0,1) = 100<BR>arrVolumes(0,2) = 1<BR>arrVolumes(0,3) = 1999<BR>arrVolumes(0,4) = 5.00<BR><BR>So i&#039;m looping through the array comparing my cidd_id and line_no&#039;s and if there&#039;s a match, i&#039;m grabbing the vol_yr and base_price

6. Senior Member
Join Date
Dec 1969
Posts
2,930

## RE: good point but...

so if arrVolumes(0,1) = arrVolumes(0,2)<BR><BR>then you&#039;re grabbing arrVolumes(0,3) and arrVolumes(0,4)<BR><BR>??? <BR><BR>or are you seeing if the cidd_id and line_no are equal in 2 separate records? still need clarification

7. Senior Member
Join Date
Dec 1969
Posts
299

## close....

If (temp_cidd_id = arrVolumes(0,1)) and (temp_line_no = arrVolumes(0,2)) Then<BR><BR>grab arrVolumes(0,3) and arrVolumes(0,4)<BR><BR>... here&#039;s a thought. once a record is found in arrVolumes, is there a way to delete that full entry, like arrVolumes(100,x), in the array and redim it? that would make the array smaller as it goes and have less to loop in... would be great if that would work

8. Senior Member
Join Date
Dec 1969
Posts
2,930

## if they're not

sorted, than that&#039;s the best you can do, how you have it right now... deleting and redim(ension)ing would take longer than the way you do it now... see if you can order by cidd_id and line_no, because you could make this get done with one pass through the array if they&#039;re sorted...

9. Senior Member
Join Date
Dec 1969
Posts
299

## RE: if they're not

right, but i have to loop for each record i&#039;m getting from a previous loop. so the 6000+ loop starts all over again for each 2000+ record..

10. Senior Member
Join Date
Dec 1969
Posts
2,930

## RE: if they're not

jesus... you&#039;re looping 12 million times+. yell at whoever&#039;s making you do that... you don&#039;t need to... the only reason you would need to loop through 12 million times is if there were 12 million records... believe me, having my computer science degree tells me that you can easily do this faster, but sorting is the way to go, and you can leave that up to the dbms. go... YELL at him/her. tell him/her that klooj_it sent you.

#### Posting Permissions

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