Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Array in session object
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Array in session object

 Post Reply Post Reply
Author
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post Topic: Array in session object
    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.

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post Posted: 01 April 2003 at 2:12am
Thank you for that Andrew I will try it tonight
Back to Top
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post 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)
%>

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
ultramods View Drop Down
Groupie
Groupie
Avatar

Joined: 08 January 2003
Location: Scotland
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote ultramods Quote  Post ReplyReply Direct Link To This Post 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. 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.