Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.: Array stored in Session :.

Status
Not open for further replies.

tfoulkes

Technical User
Dec 5, 2003
17
GB
Hi All,
I'm having problems with an Array being stored in a session variable.
It has no problem adding one element, but falls over when I try to add a second, saying there is a type mismatch on line 10.

On line 10 I am saying that if the session is not empty, make myArray equal to it. It obviously see's these 2 types as being incompatible.

Any help would be greatly appreciated, this is driving me mad!

I've put a copy online at
if you fancy a look...


Please find the code below:

<%
'variabels
Dim i, x, z
Dim rows, newrows
Dim myArray()
reDim myArray(3,0)
Dim product, quant, price

if not isEmpty(session("cart")) then 'if the session is empty
myArray=Session("cart") 'LINE 10 !!!
rows=UBound(myArray,2)
newrows=rows+1
End If

product = Request.Form("product")
quant = Request.Form("quant")
price = Request.Form("price")

if not product="" or not quant="" or not price="" then
reDim Preserve myArray(3,newrows) 'redimension the array
myArray(0,newrows)=product
myArray(1,newrows)=quant
myArray(2,newrows)=price
session("cart")=myArray
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>Session test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h4>::Session Variable Test::</h4>
<form id="frmarray" name="arrayform" method="post" action="session.asp">
<input type="text" id="product" name="product" /><br />
<input type="text" id="quant" name="quant" /><br />
<input type="text" id="price" name="price" /><br />
<input type="submit" id="submit" value="Go Baby Go" />
</form>
<%
if isEmpty(Session("cart")) then
Response.Write("nothing in cart")
else %>
<p>There are <%=rows %> elements in this array</p><%
for i = 0 to rows
for x = 0 to 2
Response.Write(":"&myArray(x,i)&" ")
next
Response.Write("<br/>")
next
End If
%>
<br /><a href="abandon.asp">abandon session</a>
</body>
</html>
 
Try taking off the parens
Change Dim myArray()
to
Dim myArray

To store an array in Session, the variable should be (I believe) a Variant that contains an array (Dim myArray), not an array of Variants (Dim myArray())


Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Thanks for your reply John,
I'll try this out later and see how I get on.

Tim
 
You can also take a look at the cart i've done using dictionary object

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thanks for your help guys,
I've managed to sort this with a redim and a redirect...

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top