PDA

View Full Version : Global Arrays


NancyJ
04-12-2005, 04:12 PM
I'm trying to store a global array of productID's and quantities but I'm having problems.
Basically we have a small number of products but not all stored on the same page, the user puts in the number they want then moves on to the next page and I need to be able to store that information until they're done.

This is what I've got so far

-global.asa


<script language="vbscript" runat="server">

sub Session_OnStart



Dim gProducts
Dim gProducts_numRows

Set gProducts = Server.CreateObject("ADODB.Recordset")
gProducts.ActiveConnection = "dsn=Octopus;"
gProducts.Source = "SELECT * FROM Products"
gProducts.CursorType = 0
gProducts.CursorLocation = 2
gProducts.LockType = 1
gProducts.Open()

gProducts_numRows = 0

while not gProducts.eof
gCounter = gCounter+1
gProducts.movenext
wend

gProducts.movefirst

redim gOrder(gCounter, 2)

for i = 0 to gCounter-1
gOrder(i, 0) = gProducts("ID")
gOrder(i, 1) = 0
gProducts.movenext
next
gProducts.movefirst
session("order") = gOrder
session("counter") = gCounter
end sub

Sub Session_OnEnd

gProducts.close()

end sub
</script>


script that stores the info


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
reDim tempOrder(session("counter"), 2)
tempOrder = session("order")
for j = 1 to request.form.count
for each name in request.form
for i = 0 to session("counter")
if tempOrder(i, 0) = name then
tempOrder(i, 1) = request.form(name)
response.write tempOrder(i,0) & ": " & tempOrder(i,1)
end if
next
next
next
session("order") = tempOrder%>



the global.asa seems to be ok but I get a type mismatch on tempOrder = session("order")

Bullschmidt
04-13-2005, 09:51 AM
Perhaps this may hopefully give you some ideas:

Classic ASP Design Tips - Shopping Cart
http://www.bullschmidt.com/devtip-shoppingcart.asp

I generally think of a shopping cart as a fancy name for a session array. And here is a good resource that includes how to use session arrays:

Session Object
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/ref_vbom_seso.asp

And here are some more shopping cart resources:

Shopping Cart Sample
http://www.asp101.com/samples/viewasp.asp?file=shopping%2Easp

Welcome to the fake volleyball store
http://www.aspfaq.com/cart

And if you don't want to "roll your own," this resource has a list of free and commercial shopping cart components, as well as some pure ASP shopping carts:

Where can I get a shopping cart for my web site? - 4/11/2002
http://www.aspfaq.com/show.asp?id=2225