Print Page | Close Window

Array in session object

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1517
Printed Date: 29 March 2026 at 10:26am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Array in session object
Posted By: ultramods
Subject: Array in session object
Date Posted: 31 March 2003 at 3:27pm

I would be appreciative if anyone could help me with my problem.

I want to have a button that if pressed will add a car ID to an array in a sesion object. Could any one help me with how i would create the array in the session object and also how would i update the array with new car ID's.




Replies:
Posted By: Bunce
Date Posted: 31 March 2003 at 8:24pm

Split it into two parts:

1) Adding / retrieveing an array from session scope
2) Adding items to an array

So to add items to an array:
aMyArray(3) = NewValue
(note: you may need to ReDim() the array depending on how you declared it)

To save an array to session scope:
session("aSavedArray") = aMyArray

To retrieve the array from session scope:
aMyArray()= session("aSavedArray")

This is only basic so there may be conversion / assignment issues, however if you search google for arrays in VBscript, you should get a number of helpful articles.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: ultramods
Date Posted: 01 April 2003 at 2:12am
Thank you for that Andrew I will try it tonight


Posted By: ultramods
Date Posted: 02 April 2003 at 4:12am

I have managed to add a carID to a to the first index of an array in a session. however when i try to calculate the length of the array so i know where to put the next ID i get the following error. I want to have one array with a max length of 5.

Microsoft VBScript runtime error '800a01c3'

Object not a collection

it refers to my for statement. everything works ok(i think) up to the for statement, however my array declarations may be wrong. I just can get it to work. could someone please offer dome assistance.

<%
OPTION EXPLICIT
Dim compareArray(4), carID, counter, compareArrays, counter2, compareArrays2

counter= 0
counter2 = 0
carID = REQUEST.FORM("compare")

IF SESSION("compareArray(0)")= "" THEN

 compareArray(0)= carID
 session("compareArray(0)") = compareArray(0)
 
 response.write("test " & session("compareArray(0)"))
END IF
response.write("test " & session("compareArray(0)"))

FOR EACH compareArrays IN session("compareArray")
  counter = counter + 1
 NEXT
response.write(counter)
%>



Posted By: Bunce
Date Posted: 02 April 2003 at 4:40pm

I don't think you can use an array as a collection.

Additionally, you should probably pull the array from session scope to a local variable if you are going to work with it.

Try reading an from an array using something like this:

For i = 0 to UBound(myArray,2) -1
   Response.write myArray(i)
   Counter = counter + 1
Next

Better check those indices and dimensions though. I always forget whether arrays are 0-based in VbScript or not.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: ultramods
Date Posted: 03 April 2003 at 11:49am

Thanks for that andrew, but still having problems.

Sorry to be a pest but how would i put the array in the session object into a local array. I have been trying for hours but keeps going round in circles



Posted By: ultramods
Date Posted: 03 April 2003 at 3:05pm

As Alan partridge one said "jurassic park". Cracked it after only about eight hours.

Thanks for you help with it Andrew. 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net