What's wrong with this simple ReDim Preserve statement?

Why do I get the following error when I run the attached code?

Microsoft VBScript runtime error '800a0009'

Subscript out of range

/sign/usvp/SendApproval.asp, line 5

<%
Dim arTest
ReDim arTest(0,2)
arTest(0,2) = "test"
ReDim Preserve arTest(4,2)
arTest(1,2) = "test2"
Response.End()
%>

Open in new window

LVL 1
edenmachineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can only resize the last dimension of an multi-dimensional array.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
edenmachineAuthor Commented:
So then I need to switch it up to arTest(0)(2) or something instead?
0
edenmachineAuthor Commented:
This works fine by the way - but I lose the previous data of course:
<% 
Dim arTest
redim arTest(0,2)
arTest(0,2) = "test"
ReDim arTest(1,2)
arTest(1,2) = "test2"
response.End
%>

Open in new window

0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
what about this:
<%
Dim arTest
ReDim arTest(0 to 2, 0 to 0)
arTest(2,0) = "test"
ReDim Preserve arTest(0 to 2,0 to 4)
arTest(2,1) = "test2"
Response.End()
%>

Open in new window

0
Robberbaron (robr)Commented:
I keep getting caught when I forget to think.... happens all the time!

you must switch your dimensions around as angel has shown

instead of  asTest(x,y)    need to use arTest (y,x)     because only the second dimension can be redimed.

redim arTest(5,20)
for x=0 to 20
   for y=1 to 5
     arTest(y,x)=999
   next y
next x

redim preserve arTest(5,25)

0
edenmachineAuthor Commented:
Ahhhhhh - yes, sorry it's been four years since I've worked in VBScript and I totally forgot that you put columns before rows (cols,rows) in an array.  Boy - I'm rusty! :P  thanks all!
0
Robberbaron (robr)Commented:
no. its just when you want to redim that you need to do this,
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.