ReDim Problem

W

Wayne Wengert

I am trying to add one column to an existing array (code below). The ReDim
command gives the error:
-----------------------------------------------
Microsoft VBScript runtime error '800a0009'

Subscript out of range

/ListCGShowsGrouped.asp, line 58

------------------------------------------------

The Response.Write shows that the array has 9 rows and 3 cols (it displays 8
and 2) before the redim and I want a 9 x 4 after the redim.

What am I doing wrong here?



============ Code ===============

........
aryShows = myRS.GetRows
intRows = Ubound(aryShows,2)
intCols = Ubound(aryShows,1)
MyRS.Close

Response.Write("Rows: " & introws & " - Cols: " & intcols & "<br>")
Redim Preserve aryShows(intCols + 1, introws)
 
C

Chris Barber

You can only redimension the last dimension of an array.

<quote source="google search">
When using multi dimensional arrays, it is only possible to redim the last
dimension.

Say you array looks like this:

Dim myArr()
Redim myArr(5,5)

You will be able to do

Redim myArr(5,10)

But you won't be able to do

Redim myArr(10,5)

This behaviour is by design, so you can't get around it...
</quote>

Hope this helps (or not of course).

Chris.

I am trying to add one column to an existing array (code below). The ReDim
command gives the error:
-----------------------------------------------
Microsoft VBScript runtime error '800a0009'

Subscript out of range

/ListCGShowsGrouped.asp, line 58

------------------------------------------------

The Response.Write shows that the array has 9 rows and 3 cols (it displays 8
and 2) before the redim and I want a 9 x 4 after the redim.

What am I doing wrong here?



============ Code ===============

........
aryShows = myRS.GetRows
intRows = Ubound(aryShows,2)
intCols = Ubound(aryShows,1)
MyRS.Close

Response.Write("Rows: " & introws & " - Cols: " & intcols & "<br>")
Redim Preserve aryShows(intCols + 1, introws)
 
W

Wayne Wengert

Thanks Chris. Now that you remind me of that I do remember reading that
before - I forgot about that (senility!). Oh well, I'll do it the hard way.

Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top