Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2004, 11:26 AM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default session level array syntax requested

Is this the syntax to declare a session level array?

global.asa
Sub Session_OnStart
 Session.myArray()
End Sub
 
Old January 26th, 2004, 11:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old January 26th, 2004, 12:10 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old January 26th, 2004, 04:50 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old January 27th, 2004, 06:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Session State & Object Array jlrolin ASP.NET 2.0 Professional 4 June 20th, 2007 12:49 PM
SQL help requested mvoosten MySQL 4 March 18th, 2007 03:38 AM
The webpage you requested is not available offline cathiec ASP.NET 1.0 and 1.1 Basics 0 October 6th, 2005 09:35 AM
Page 73 - Array Syntax carlitio BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 August 18th, 2004 01:23 PM
Chap 5 capitals.ph (array syntax) growch BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 6 October 31st, 2003 12:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.