[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Variable in a 2D array def.

Posted on 2001-06-10
6
Medium Priority
?
378 Views
Last Modified: 2012-08-14
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...
0
Comment
Question by:juststeve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 11

Expert Comment

by:ASPGuru
ID: 6173121
you can only change the last dimension in an array...
0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 6173124
-->>> ReDim Preserve myarray(5, counter)
0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 6173126
btw, you don't need to create such an array yourself....


try this:

theArray = theRecordset.getRows

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:juststeve
ID: 6173516
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...
0
 
LVL 11

Accepted Solution

by:
ASPGuru earned 400 total points
ID: 6173598
getRows is ADO since the first days....

getRows will give you an 2D array where the first index selects the field and the second selects the record...

look at this example:

' First get the Data
Set RS = Conn.execute("SELECT f1,f2,f3 FROM table WHERE ...")
thaArray = RS.getRows
RS.close : Set RS = Nothing
Conn.close: Set Conn = Nothing

'then: work with it..
for i = 0 to ubound(theArray,2) ' for every record...
   response.write "f1:" theArray(0,i) & "<br>"
   response.write "f2:" theArray(1,i) & "<br>"
   response.write "f3:" theArray(2,i) & "<br>"
next
0
 
LVL 11

Expert Comment

by:ASPGuru
ID: 6173603
if you need more help, post your code and i will alter it, so it uses getRows...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question