asptoday_discuss thread: Re: Using a variable in a For Next and placing it in a Session variable
Mark,
Here's one way to do it.
Inside the for loop, declare a new variable that will hold the session
variable name.
For i =3D 0 to 9
Dim strCurrentSessionVariableID
Dim strCurrentSessionVariableQTY
Then set the value of the variable using the counter
strCurrentSessionVariableID =3D "cart(0," + Cstr(i) + ")"
strCurrentSessionVariableQTY =3D "cart(1," + Cstr(i) + ")"
Now you should be able to set your ID and QTY variables.
ID =3D Session(strCurrentSessionVariableID )
Qty =3D Session(strCurrentSessionVariableQTY)
Now the rest of the code should work
Good Luck!
Rich
----- Original Message -----
From: "Mark Berry" <mbfromit@h...>
To: "ASPToday Discuss" <asptoday_discuss@p...>
Sent: Thursday, August 30, 2001 11:34 PM
Subject: [asptoday_discuss] Using a variable in a For Next and placing
it in a Session variable
> Here is the code I am having problems with
>
> <%
> For i =3D 0 to 9
> ID =3D Session("cart(0,i)")
> Qty =3D Session("cart(1,i)")
> %>
> <tr>
> <td><%=3DID%></td>
> <td><%=3DQty%></td>
> </tr>
> <% next %>
> </table>
>
> The variable "i" is not seen inside the Quotation marks in
> Session("cart(0,i)"), if I use a number, it works fine. This is
> supposed to be a shopping cart, and I am trying to write out to
> a table the values stored in the array named cart. The cart array
> was dim as Session("cart(1,9)") in global.asa
>
> In ASP 3.0 it says "Do not use a variable within quotation marks. But
how
> else are you going to loop through this array?
>
> Help!!
>
> Thanks!
>