juststeve
asked on
Variable in a 2D array def.
I trying to set up a 2D array where the 1st dim should be equal to the number of database records returned and the 2nd dim is a constant...the number of fields.
My reasoning is that I should be able to express the 1st dim as a variable and within the iteration have:
ReDim Preserve myarray(counter, 5)
Here's the code I'm using:
aindex=1
dim q(aIndex,5)
for aIndex = 1 to rec_count
redim preserve q(aIndex,5)
Microsoft VBScript compilation error '800a0402'
Expected integer constant
/quiz.asp, line 78
dim q(aIndex,5)
------^
If I hardcode the first dim to:
dim q(5,5) '5 happens to be known to be max possible
the error falls to the redim as:
Microsoft VBScript runtime error '800a0009'
Subscript out of range
/quiz.asp, line 87
I can get my page to work if I don't try to re-dim and I hardcode the 1st dim to my largest known recordset. But I'd like to understand the process. I've seen variables used in 2D arrays elsewhere.
thankx
--steve...
My reasoning is that I should be able to express the 1st dim as a variable and within the iteration have:
ReDim Preserve myarray(counter, 5)
Here's the code I'm using:
aindex=1
dim q(aIndex,5)
for aIndex = 1 to rec_count
redim preserve q(aIndex,5)
Microsoft VBScript compilation error '800a0402'
Expected integer constant
/quiz.asp, line 78
dim q(aIndex,5)
------^
If I hardcode the first dim to:
dim q(5,5) '5 happens to be known to be max possible
the error falls to the redim as:
Microsoft VBScript runtime error '800a0009'
Subscript out of range
/quiz.asp, line 87
I can get my page to work if I don't try to re-dim and I hardcode the 1st dim to my largest known recordset. But I'd like to understand the process. I've seen variables used in 2D arrays elsewhere.
thankx
--steve...
you can only change the last dimension in an array...
-->>> ReDim Preserve myarray(5, counter)
btw, you don't need to create such an array yourself....
try this:
theArray = theRecordset.getRows
try this:
theArray = theRecordset.getRows
ASKER
I've been meaning to have a look at getRows cuz I know there's some performance advantages. Perhaps you can help me with that....
As soon as I've retrieved my recordset I iterate through each record and stored the fields in the 2D array:
q(aIndex,1) = rsAnswers("QuizAnswer")
q(aIndex,2) = rsAnswers("QuizAnswerID")
q(aIndex,3) = rsAnswers("Result")
q(aIndex,4) = rsAnswers("Response")
Next I fold those values into the page's HTML, then iterate to get the next record and so on. Then I deallocate the recordset.
What will getRows gain me? It's specific to ASP3.0 isn't it? or is it ADO 2.6? IOW, in lots of corporate installations they only use NT4sp6 - is getRows availible there?
thankx
--steve...
As soon as I've retrieved my recordset I iterate through each record and stored the fields in the 2D array:
q(aIndex,1) = rsAnswers("QuizAnswer")
q(aIndex,2) = rsAnswers("QuizAnswerID")
q(aIndex,3) = rsAnswers("Result")
q(aIndex,4) = rsAnswers("Response")
Next I fold those values into the page's HTML, then iterate to get the next record and so on. Then I deallocate the recordset.
What will getRows gain me? It's specific to ASP3.0 isn't it? or is it ADO 2.6? IOW, in lots of corporate installations they only use NT4sp6 - is getRows availible there?
thankx
--steve...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you need more help, post your code and i will alter it, so it uses getRows...