Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Session Variable - array problem

Reply
Thread Tools

Session Variable - array problem

 
 
Neil Jarman
Guest
Posts: n/a
 
      01-19-2005
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



 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      01-19-2005
"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



 
Reply With Quote
 
 
 
 
Mark Schupp
Guest
Posts: n/a
 
      01-19-2005
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" <(E-Mail Removed)> wrote in message
news:csmbqh$3f5$1$(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
Neil Jarman
Guest
Posts: n/a
 
      01-19-2005
Hi Mark,

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

Cheers,

NEIL


"Mark Schupp" <(E-Mail Removed)> wrote in message
news:uqHJllm$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:csmbqh$3f5$1$(E-Mail Removed)...
> > 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
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System Session Variable VS. Own-declared 'Session' Variable chowchho ASP .Net 7 03-28-2008 02:38 PM
Session Timeout problems-web.confg session state and IIS session s =?Utf-8?B?Um9iSEs=?= ASP .Net 4 04-11-2007 04:52 PM
s there a way to set a session variable by session ID? admiller97@gmail.com ASP .Net 1 11-14-2005 05:13 PM
Session State - What does it take to establish one single ASP.NET session per "browser session" Jeff Smythe ASP .Net 3 01-02-2004 04:10 AM
How can I "know" the difference between a session timed out and a session that did session.abort? Jazzis ASP General 2 09-23-2003 07:16 AM



Advertisments