469,327 Members | 1,277 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Session Variable - array problem

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

Jul 22 '05 #1
3 2770
"Neil Jarman" wrote ...
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

Jul 22 '05 #2
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

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

"Neil Jarman" <ne**@tNOiSPAMvPLEASEy.co.uk> wrote in message
news:cs*******************@news.demon.co.uk...
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

Jul 22 '05 #3
Hi Mark,

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

Cheers,

NEIL
"Mark Schupp" <no******@email.net> wrote in message
news:uq**************@TK2MSFTNGP11.phx.gbl...
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

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

"Neil Jarman" <ne**@tNOiSPAMvPLEASEy.co.uk> wrote in message
news:cs*******************@news.demon.co.uk...
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


Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul | last post: by
1 post views Thread by Sean Pinto | last post: by
7 posts views Thread by Nicole | last post: by
9 posts views Thread by bajopalabra | last post: by
4 posts views Thread by tma | last post: by
3 posts views Thread by Brad | last post: by
5 posts views Thread by Diffident | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.