Dynamic multi-dimentional arrays in VBScript

Need a Dynamic multi-dimentional array to load items from a database.
Example:
  ...
  dim tempArray()
  length1 = 1
  Set RS = MyConn.Execute(strSQL)
  while not RS.eof
    redim preserve tempArray(length,4)
    ...
    length = length + 1
  wend

But keep getting error:

  Subscript out of range

indicating the redim line.

When trying to declare a multi-dimentional array with a variable,
Example:
  dim temp2Array(length,4)
 
I get the error message:
  Expected integer constant

  /TemplateTesting/sendNewsletter2.asp,   line 75

  dim temp2Array(length,4)
  ---------------^

So it requires a constant!!  How can I get round this problem.  I have a database items, each with a dimention of four items which change from day to day depending on additions and deletions... so I need an array with a dynamic length and four dimentions.

thegurns






thegurnsAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
deightonConnect With a Mentor Commented:
you can only change the size of the last dimension wirth redim

You have to make it (4,length)

i.e swap rows with columns
0
 
deightonCommented:
Your restriciton is with the preserve keyword - otherwise you can redim (but lose the data)

This works though


                      dim tempArray()
                      length1 = 1
                      Set RS = MyConn.Execute(strSQL)
                      while not RS.eof
                        redim preserve tempArray(4,length)
                        ...
                        length = length + 1
                      wend
0
 
thegurnsAuthor Commented:
Thank you deighton... but what a palova!!!  Don't make it easy do they??
0
All Courses

From novice to tech pro — start learning today.