Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Storing an array in a Session variable

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,158
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Storing an array in a Session variable
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Storing an array in a Session variable - 6/13/2001 12:06:55 AM   
  peach24

 

Posts: 7
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
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 ?


jac-the-man (Visitor)
Feb 6, 2001

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!
 
 
Post #: 1
 
 Re: Storing an array in a Session variable - 6/13/2001 12:09:43 AM   
  anton

 

Posts: 11
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
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?

(in reply to peach24)
 
 
Post #: 2
 
 RE: Re: Storing an array in a Session variable - 12/23/2006 3:11:55 AM   
  Disco Patrick

 

Posts: 3
Score: 0
Joined: 12/23/2006
Status: offline
I'm having a similar problem to peach24's.

I can store an array inside a session variable, no problem... but I'm having trouble bringing the session variable back into an array variable. I get the same error message as peach24.

As a beginner to programming language, I have been encouraged to always use Option Explicit.

I have something of an understanding of using variables as go-betweens when typecasting from one type to another.

Can someone reiterate the steps I should take please?

   arrBasketItems = Session("sesarrBasketItems")

(in reply to anton)
 
 
Post #: 3
 
 RE: Re: Storing an array in a Session variable - 12/23/2006 4:30:58 AM   
  Disco Patrick

 

Posts: 3
Score: 0
Joined: 12/23/2006
Status: offline
In reply to myself, I solved the problem by using the following code.

I think there are two important things involved: the index, and the loop.

Here is the working code:

      'transfer the contents of the session variable into the regular variable...
       For iLoop = LBound(Session("sesarrBasketItems")) to UBound(Session("sesarrBasketItems"))
           arrBasketItems(iLoop) = Session("sesarrBasketItems")(iLoop)
       Next

       'and then print the contents of the array in the format "array index" : "array contents"
       For iLoop = LBound(arrBasketItems) to UBound(arrBasketItems)
           Response.Write iLoop & ": " & arrBasketItems(iLoop) & "<BR>"
       Next

Thanks to Sams "Teach Yourself Active Server Pages 3.0 In 21 Days" book for it's assistance in that one.

(in reply to Disco Patrick)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Storing an array in a Session variable Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts