Finding array limits

davesmith202

Employee of Access World
Local time
Today, 09:45
Joined
Jul 20, 2001
Messages
522
I have a couple of nested loops as follows:

Code:
For i = 0 To UBound(myarr2)
'Loads of other code...etc etc
For intBatch = i To i + Me.ContentGroupSize - 1
myText=myText & myarr2(intBatch)
Next intBatch
i = i + Me.ContentGroupSize - 1
Next i

The code cycles through fine if the batch size divides nicely into the length of myarr2. But when it doesn't, I get a "Subscript out of range" error. Looks like when it looks at myarr2(intBatch), if the value of intBatch is higher than the array size, it fails.

How can I modify the inner loop so that it only cycles through enough times without going beyond the array size?

Thanks,

Dave
 
Change it to a Do While setup where you can setup multiple parameters vs For... next where you only have the one...
 
Something like this?

Code:
For i = 0 To UBound(myarr2)
'Loads of other code...etc etc
intBatch=i
Do
myText=myText & myarr2(intBatch)
intBatch = i + Me.ContentGroupSize - 1
While intBatch=UBound(myarr2)
i = i + intBatch 
Next i
 

Users who are viewing this thread

Back
Top Bottom