faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems : Arrays

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

277 of 293 people (95%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I store an array in a session variable?
How can I store an array in a session variable?

Sep 17th, 2003 11:45
Adam Baruch, unknown unknown, lungor


Dim arrMyArray(2)
arrMyArray(0) = "Hello"
arrMyArray(1) = " there!"
Session("arrMyArray") = arrMyArray
------------------------------------
Now this might look as an easy way to use (display) arrays stored as 
session, but in fact this will NOT work:
If IsArray(Session("arrMyArray")) Then
        Response.Write Session("arrMyArray")(0)
        Response.Write Session("arrMyArray")(1)
End If
Output:
Hello there!
You must again use a arrMyArray and then write from it.
---------------------
A piece of advice: I noticed that you cannot change an array thatīs 
stored in a session variable directly, like this:
Session("arrMyArray")(0) = "Happy"
Session("arrMyArray")(1) = " birthday!"
The new values to the array will not be stored in the session array for 
some strange reason.
Instead you need to assign the session-array to a local variable and 
then change it, like this:
Dim tmpArray
tmpArray = Session("arrMyArray")
tmpArray(0) = "Happy"
tmpArray(1) = " birthday!"
Session("arrMyArray") = tmpArray



© 1999-2004 Synop Pty Ltd