Problem storing an array in a Session variable

Results 1 to 2 of 2

Thread: Problem storing an array in a Session variable

  1. #1
    Trevor Gryffyn Guest

    Default Problem storing an array in a Session variable

    Ok, I&#039m writing a shopping cart application that&#039s going to use Session variables to store some information (I need to store the SKU, Quantity and Color.. otherwise I&#039d just use a dictionary object). I use the following code to check to see if a cart has already been set up. This is just some test code because I&#039m getting a TYPE MISMATCH error when I try to assign Cart to Session("cart").<BR><BR>When there&#039s no Session active, then Cart is VarType 8204 and Session("cart") is type 0. After running this through once, then they&#039re both type 8204 but I still get a type mismatch.<BR><BR>If VarType(Session("cart")) &#060;&#062; 0 Then<BR> ReDim Cart(ubound(Session("cart")),aNumFields)<BR> response.write "Cart=" & VarType(cart) & " SessionCart=" & VarType(Session("cart"))<BR> Cart = Session("cart")<BR>Else<BR> ReDim Cart(0, aNumFields)<BR> Session("cart") = cart<BR>End If<BR><BR><BR>Not the most elegant code, but this thing&#039s driving me insane. I&#039ve only been doing ASP&#039s for about a week, but have a pretty good grasp on a few other scripting languages.<BR><BR>Anyone care to enlighten this ignorant soul and save me some frustration? Thanks in advance for the help.<BR><BR>I guess either post here or drop me an email at<BR><BR>Thanks again.<BR><BR>Trevor Gryffyn<BR>

  2. #2
    Trevor Gryffyn Guest

    Default RE: Problem storing an array in a Session variable

    Ok, found the answer. I was Dim&#039ing CART as an array but then trying to use Session("cart") as a variant or something.<BR><BR>If I change it from:<BR><BR>Dim Cart()<BR><BR>ReDim Cart(x,y)<BR><BR>to:<BR><BR>Dim Cart<BR><BR>ReDim Cart(x,y)<BR><BR>Then it works fine.<BR><BR>Kudos to Paschal Nee on the Active Server Pages mailing list off of for the answer.<BR><BR>Just thought I&#039d share.<BR><BR>Trevor Gryffyn<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts