PDA

View Full Version : Shopping Cart Exercise - gone bad


ecnarongi
04-14-2004, 04:58 PM
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Dim i,j
Redim inventory(3,3)

for i = 0 to 3
inventory(i,i) = i + 20
next

Session("cart") = inventory

inventory = Session("cart")

with response
for j = 0 to 3
.write inventory(j,j) & "<br>"
next
end with
%>
<% response.end %>

what I am trying to do here is just make an array and assign it to a session variable. Then retrieve that information from the session variable and output all of its values to the screen, as an example of how a cart would work.

If my approach is wrong please tell me, and show me the right path to the answer. All help is appreciated, thanks.

----- update ------

the above code doesn't work b/c I reuse the inventory variable without Redimming it. If I were to use another variable instead of inventory to output to the screen it would work. Thanks to all who viewed with intensions to help.

ecnarongi
04-16-2004, 04:09 AM
ok I am now having a problem. My cart is not "Preserving" all the items that were put into them before, the only item that shows is the last item entered. The reason why, is because I am not preserving the cart that was present before and I am rewritting the cart each time an items is entered. I need help preserving the the cart, all help is appreciated. Thanks.

<%@LANGUAGE="VBSCRIPT"%>
<%
Dim qnty,pset,game,name,price,senti,numitems

with Request
qnty = .Form("qnty")
pset = .Form("set")
game = .Form("game")
name = .Form("name")
price= .Form("price")
senti= .Form("senti")
end with

Session("numitems") = Session("numitems") + 1
Session("price") = Session("price") + price
numitems = Session("numitems")

Redim Preserve inventory(4,numitems)

if senti = "multi" then
inventory(0,numitems) = qnty
inventory(1,numitems) = pset
inventory(2,numitems) = game
inventory(3,numitems) = name
inventory(4,numitems) = price
end if

Session("Cart") = inventory
%>
<% response.end %>

ecnarongi
04-17-2004, 04:26 PM
----------------- update ---------------------

<%
Dim qnty,pset,game,name,price,senti,numitems,inventory,maxitems

with Request
qnty = .Form("qnty")
pset = .Form("set")
game = .Form("game")
name = .Form("name")
price= .Form("price")
senti= .Form("senti")
end with

maxitems = 5
Session("numitems") = Session("numitems") + 1
Session("price") = Session("price") + price
numitems = Session("numitems")
inventory = Session("Cart")

Redim Preserve inventory(maxitems,numitems)

if senti = "multi" then
inventory(0,numitems) = qnty
inventory(1,numitems) = pset
inventory(2,numitems) = game
inventory(3,numitems) = name
inventory(4,numitems) = price
end if

Session("Cart") = inventory
%>

the above code seems to be set up right but now I get that my redimming of inventory throws an error of:

Microsoft VBScript runtime error '800a0009'

Subscript out of range

---------------- update ----------------------

I found the problem the actual issue is not with the above code it's with my global.asa file the variable assignments were messed up. :thumbsup: