Click to See Complete Forum and Search --> : array - help!!!!!!!!
Nolan@skm
October 1st, 2001, 09:00 AM
I am using ASP and trying to add a recordset to an array - arytree1dim(0) = rst.fields("hello"). The problem is that I do not no how many records there will be until after the query is run. Therefore, I cannot declare the array like "Dim aryTree1Dim(4)" as it may have any number of records. Is there a way to use an array like this without declaring its length.
THANKS.
Cakkie
October 1st, 2001, 09:06 AM
You can ReDim an array, or in english, resize it.
Dim arr() as string
Redim arr(20)
' OR
Redim Preserve(25)
Of course, you could easely replace the 20 or 25 by the number of records in your recordset, by replacing it by rst.recordcount (or something like that). If you use the preserver keyword, the content of the array will be preserved, if not, the array is cleared.
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Nolan@skm
October 1st, 2001, 09:27 AM
when I use the recordcount as the size of the array I get the following error:
Expected integer constant
Dim aryTree1Dim(rsrec.recordcount)
And I use Redim I get the following error:
This array is fixed or temporarily locked
Cakkie
October 1st, 2001, 09:31 AM
When declaring the array, make sure not to give a size, only assign a size when using ReDim.
' no size here
Dim SomeArray() as string
' Size goes here
Redim SomeArray(rst.recordcount)
Tom Cannaerts
slisse@planetinternet.be
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.