Click to See Complete Forum and Search --> : Array Help


lmf232s
01-19-2005, 10:01 AM
Hey guys, i have a loop that loops 92 times give or take.
With in this loop i use about 9 arrays to hold data.
at the end of each record, i have to empty all the arrays
so that they do not keep that data and use it for the next record.

I am looking for a better way to clear out the arrays as i think this
is inefficient.

This is what i currently do

For i = 1 to 12
MyArray1(i) = ""
MyArray2(i) = ""
MyArray3(i) = ""
MyArray4(i) = ""
etc.
next

I do this for all 9 arrays.

that means that this for loop, loops 1104 times in total.

Whats a better way to do this.

russell
01-19-2005, 10:55 AM
instead of this

For i = 1 to 12
MyArray1(i) = ""
MyArray2(i) = ""
MyArray3(i) = ""
MyArray4(i) = ""
etc.
next

do this

Redim MyArray1(0)
Redim MyArray2(0)
Redim MyArray3(0)
etc.

it would be even better if you had an array of arrays, so that you could do it with one statement:

Set MyArray = Nothing

lmf232s
01-19-2005, 12:24 PM
russell,
i have tried that but it errors out and says that
This array is fixed or temporarily locked

russell
01-19-2005, 05:27 PM
how r u declaring it?

like this?

Dim myArray(100)

Or like this?

Dim myArray
myArray = Array(1,2,3,4...)

or what?

lmf232s
01-19-2005, 05:28 PM
Dim myArray(12)

russell
01-19-2005, 05:44 PM
try changing to

ReDim myArray(12)

or to

Dim myArray
ReDim myArray(12)

u can redim without ever dimming in the 1st place. this will prevent the array length from being "locked"

then the solution above will work

lmf232s
01-19-2005, 05:48 PM
that does it thanks,
Im not sure i will see a performance increase on this page but at least i can avoid looping a couple thousand times to clear out all the arrays.

Thanks.