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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing an array in a Session variable

Status
Not open for further replies.

smyttie

Technical User
Jan 24, 2001
1
BE
This code I put in my GLOBAL.ASA file (It is executed, I've checked) :
'--------------------------------------
Sub Session_OnStart
Dim Cart_Content()
ReDim Cart_Content(1,3)
Cart_Content(0,1) = "Init"
Cart_Content(0,2) = "Init"
Cart_Content(0,3) = "Init"
Session("Sess_Cart_Content") = Cart_Content
End Sub
'--------------------------------------

Then in my asp page I use this code :
'--------------------------------------
Dim Cart_Content(), Add_Item

Cart_Content = Session("Sess_Cart_Content")

Add_Item = UBound(Cart_Content,1) + 1

ReDim Preserve Cart_Content(Add_Item,3)

Cart_Content(Add_Item,1) = Article
Cart_Content(Add_Item,2) = Entry
Cart_Content(Add_Item,3) = Size
Session("Cart_Content") = Cart_Content

End Sub
'--------------------------------------

Considering the ASP manuals and samples I've checked it should work, but I always get a 'Type Mismatch'

error in the line 'Cart_Content=Session("Sess_Cart_Content")'

Can anyone help me out ?
 
Don't Dim Cart_Content in the asp page. Let asp/vbscript type the variable from a variant to an array. Use a second variable as the dynamic array and load it up with the contents of Cart_Content and then re-dim as necessary. Cart_Content will act as a "go-between" variable.

Also, keep in mind that an array of variants is not the same as a variant array!

JAC
 
Actually, you should Dim Cart_Content ( especially if you have Option Explicit turned on ) just don't dim it as a dynamic array.

VBScript is pretty weak in the data structure department!
It's all going to be C# someday, right?

JAC
 
Good God I hope not! :-( They never have to knock if your door is always open.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top