Subject: session level array syntax requested
Posted By: lcsgeek Post Date: 1/26/2004 10:26:33 AM
Is this the syntax to declare a session level array?

global.asa
Sub Session_OnStart
 Session.myArray()
End Sub
Reply By: pgtips Reply Date: 1/26/2004 10:43:56 AM
No, the Session object is a bit quirky with arrays.  To put an array in there you have to define and populate your own array variable, then you do:
Session("myArrayKey") = myArrayVariable

Likewise if you want to change anything in an array which is stored in the Session you first have to pull the array out of the Session into your own array variable, then you change your array variable, then you write the whole array back into the Session overwriting the existing array.

hth
Phil
Reply By: lcsgeek Reply Date: 1/26/2004 11:10:53 AM
Thanks Phil, but your way seems cumbersome.  Check this out.


global.asa
<SCRIPT LANGUAGE="VBSCript" RUNAT="Server" >
Sub Session_OnStart
Session.myArray()
End Sub
</SCRIPT>


some asp page code
dim loopCount
loopCount = 1
If Request.QueryString.Count > 0 Then
For Each Item in Request.QueryString
Session("myArray("&loopCount&")") = Request.QueryString(Item)
Response.Write(Session("myArray("&loopCount&")") & "<br />")
loopCount = loopCount + 1
Next
Else
Response.Write("No Items in yourArray")
End If
Reply By: lcsgeek Reply Date: 1/26/2004 3:50:34 PM
Greetings Phil,
The crow I'm eating right now is gross.  I'm not sure why the code works for me but I'm sure something is wrong with it.
Reply By: pgtips Reply Date: 1/27/2004 5:47:08 AM
quote:
Originally posted by lcsgeek

Thanks Phil, but your way seems cumbersome.  Check this out.


global.asa
<SCRIPT LANGUAGE="VBSCript" RUNAT="Server" >
Sub Session_OnStart
Session.myArray()
End Sub
</SCRIPT>


some asp page code
dim loopCount
loopCount = 1
If Request.QueryString.Count > 0 Then
For Each Item in Request.QueryString
Session("myArray("&loopCount&")") = Request.QueryString(Item)
Response.Write(Session("myArray("&loopCount&")") & "<br />")
loopCount = loopCount + 1
Next
Else
Response.Write("No Items in yourArray")
End If



Yes it is cumbersome - I didn't claim it was pretty , but your loop doesn't create an array in the Session, it just creates multiple scalar values under the keys myArray1, myArray2 etc.

Go to topic 9004

Return to index page 962
Return to index page 961
Return to index page 960
Return to index page 959
Return to index page 958
Return to index page 957
Return to index page 956
Return to index page 955
Return to index page 954
Return to index page 953