PDA

View Full Version : ASP: Using Session Variable as Array


mattboy_slim
10-02-2009, 08:28 PM
I have a session variable (session("sess_categories")) that has a value of the following:
6, 16, 3, 7, 4, 5

I want to write out each individual item of the "array" like such:

For Each item In session("sess_categories")
response.write(item & "<br/>")
next


However, when i do this, I get the followingn error:

Microsoft VBScript runtime error '800a01c3'

Object not a collection


Does anybody have any suggestions?

Thanks in advance,
Matt

mattboy_slim
10-02-2009, 09:14 PM
Nevermind, got it.



Dim var_categories
var_categories = Split(Session("sess_categories"),",")
For Each item in var_categories
response.write(item & "<br/>")
Next

Old Pedant
10-03-2009, 12:08 AM
May or may not be right.

If that string came from (for example) Request("nameOfSetOfCheckboxes") then there will be a COMMA *and* a SPACE between each pair, so you should use
var_categories = Split(Session("sess_categories"),", ") ' COMMA-SPACE

Can make a difference in some situations.