Session Variable - array problem

N

Neil Jarman

Hi,

I need to create an array with a session variable.

According to thebook I'm using, the following should work, but if fails:

for each key in request.QueryString
if left(key,6) = "cboRun" then
iIndex = cint(mid (key,7))
response.Write(iIndex & "<br>")
session.Contents("iRunNo")(iIndex)=iIndex
end if
next

it is the (iIndex) part which fails. If I remove this, then I can create a
single session variable

Any suggestions where I'm going wrong.

Many thansk

NEIL
 
R

Rob Meade

...
for each key in request.QueryString
if left(key,6) = "cboRun" then
iIndex = cint(mid (key,7))
response.Write(iIndex & "<br>")
session.Contents("iRunNo")(iIndex)=iIndex
end if
next

it is the (iIndex) part which fails. If I remove this, then I can create a
single session variable

Any suggestions where I'm going wrong.

Hi Neil,

Not saying you're wrong - as I've not used Session.Contents before - but I
didn't see an example of its use the way you've tried to use it here:

http://www.w3schools.com/asp/asp_sessions.asp

(not suggesting this is the entire scope of this listed here mind!)..

I was able to get your example to work though when I changed it to read:

<%

for each key in request.QueryString

if left(key,6) = "cboRun" then

iIndex = cint(mid (key,7))

session.Contents("iRunNo") = iIndex ' this is the line I
changed

end if

next

Response.Write "And finally: " & Session("iRunNo")

%>

I'm sure you probably have anyway in your application - but obviously this
example doesn't have any kind of error catching around cboRun if the
querystring doesn't come back with what you expect...ie, if I changed it to
: cboRunMONKEY17 - suddenly there are errors where trying to cInt
stuff....just thought it worth mentioning...

Regards

Rob
 
M

Mark Schupp

To save an array in a session variable you have to create the array as a
local variable first then put it into a session variable. To access it later
you have to put it into a local variable again.

(note: from memory, may need some adjustments)

dim aIn(), aOut
dim i, key, iIndex

redim aIn( request.querystring.count ) 'make array big enough to hold all
params

i = 0
for each key in request.QueryString
if left(key,6) = "cboRun" then
iIndex = cint(mid (key,7))
response.Write(iIndex & "<br>")
aIn(i) = iIndex ' could use aIn(iIndex)=iIndex if that is what is
needed
i = i + 1
end if
next
redim preserve aIn( i-1 ) 'adjust upper bound to match count of desired
params
Session("iRunNo") = aIn

aOut = Session("iRunNo")
for i = 0 to ubound(aOut)
response.Write(aOut(i) & "<br>")
Next
 
N

Neil Jarman

Hi Mark,

Thanks for the help, I will test it tomorrow - typical that my book glossed
over that part!

Cheers,

NEIL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top