Session Variable - array problem

Discussion in 'ASP General' started by Neil Jarman, Jan 19, 2005.

  1. Neil Jarman

    Neil Jarman Guest

    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
     
    Neil Jarman, Jan 19, 2005
    #1
    1. Advertising

  2. Neil Jarman

    Rob Meade Guest

    "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
     
    Rob Meade, Jan 19, 2005
    #2
    1. Advertising

  3. Neil Jarman

    Mark Schupp Guest

    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" <> wrote in message
    news:csmbqh$3f5$1$...
    > 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
    >
    >
    >
     
    Mark Schupp, Jan 19, 2005
    #3
  4. Neil Jarman

    Neil Jarman Guest

    Hi Mark,

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

    Cheers,

    NEIL


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

    >
    >
     
    Neil Jarman, Jan 19, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Smythe
    Replies:
    3
    Views:
    1,326
    Jeff Smythe
    Jan 2, 2004
  2. Replies:
    1
    Views:
    1,095
    Bruce Barker
    Nov 14, 2005
  3. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,419
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  4. chowchho
    Replies:
    7
    Views:
    662
    Patrice
    Mar 28, 2008
  5. Jazzis
    Replies:
    2
    Views:
    279
    Jazzis
    Sep 23, 2003
Loading...

Share This Page