Classic ASP counter loop

KimKing
KimKing used Ask the Experts™
on
I'm having trouble writing a simple script. I need to have a number of variables named like A0, A1, A2, A3, etc. for a shopping cart checkout. But I can't find the right syntax to join the "A" part with the number part. Here's some code that doesn't work:
<%
i=0
while i < 10
u=cstr(i)
A&u=i
i=i+1
wend
response.Write(A0)
%>
Thanks, Kim
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
The best thing to do is to create an array variable.  Example below:

<%
i=0
while i < 10
A(i) = whatever value you're after
i=i+1
wend
response.Write(A(i))
%>

HTH,
Matt
Commented:
Use an array. They are designed for things like this.

But if you really must, you have to use Execute()


<%
Dim i, myArray(10)
i = 0
While i < 10
   myArray(i) = 1
   i = i + 1
Wend
Response.write myArray(0)
%>


<%
i=0
while i < 10
    u=cstr(i)
    Execute("A" & u & "=i")
    i=i+1
wend
response.Write(A0)
%>

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial