Dynamic Variable Names

Discussion in 'ASP General' started by Jas, Feb 10, 2004.

  1. Jas

    Jas Guest

    Hi All

    I guess I should just have tried this to see if it works but I don't have
    access to a machine running IIS and can't test it and I am itching for an
    answer.

    I want to use dynamic variable names in one of my pages.

    I store a field called year in one of my table. For each year I want to
    create a session variable for that year name perhaphs like the code below.

    While not rs.eof
    strVarId = strVarId & rs("year")
    session(strVarId) = True
    rs.movenext
    Wend

    the value in the recordset will be

    2002
    2003
    2004
    2005

    hence I want 4 session variables like

    strVarId2002
    strVarId2003
    strVarId2004
    strVarId2005

    Will this work?

    Thanks

    Jas
     
    Jas, Feb 10, 2004
    #1
    1. Advertising

  2. Jas

    Jas Guest

    can you give an example aaron

    thanks

    "Aaron Bertrand [MVP]" <> wrote in message
    news:u7PiZ#...
    > Ugh, why? Use an array.
    >
    > --
    > Aaron Bertrand
    > SQL Server MVP
    > http://www.aspfaq.com/
    >
    >
    >
    >
    > "Jas" <> wrote in message
    > news:...
    > > Hi All
    > >
    > > I guess I should just have tried this to see if it works but I don't

    have
    > > access to a machine running IIS and can't test it and I am itching for

    an
    > > answer.
    > >
    > > I want to use dynamic variable names in one of my pages.
    > >
    > > I store a field called year in one of my table. For each year I want to
    > > create a session variable for that year name perhaphs like the code

    below.
    > >
    > > While not rs.eof
    > > strVarId = strVarId & rs("year")
    > > session(strVarId) = True
    > > rs.movenext
    > > Wend
    > >
    > > the value in the recordset will be
    > >
    > > 2002
    > > 2003
    > > 2004
    > > 2005
    > >
    > > hence I want 4 session variables like
    > >
    > > strVarId2002
    > > strVarId2003
    > > strVarId2004
    > > strVarId2005
    > >
    > > Will this work?
    > >
    > > Thanks
    > >
    > > Jas
    > >
    > >

    >
    >
     
    Jas, Feb 10, 2004
    #2
    1. Advertising

  3. Ugh, why? Use an array.

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "Jas" <> wrote in message
    news:...
    > Hi All
    >
    > I guess I should just have tried this to see if it works but I don't have
    > access to a machine running IIS and can't test it and I am itching for an
    > answer.
    >
    > I want to use dynamic variable names in one of my pages.
    >
    > I store a field called year in one of my table. For each year I want to
    > create a session variable for that year name perhaphs like the code below.
    >
    > While not rs.eof
    > strVarId = strVarId & rs("year")
    > session(strVarId) = True
    > rs.movenext
    > Wend
    >
    > the value in the recordset will be
    >
    > 2002
    > 2003
    > 2004
    > 2005
    >
    > hence I want 4 session variables like
    >
    > strVarId2002
    > strVarId2003
    > strVarId2004
    > strVarId2005
    >
    > Will this work?
    >
    > Thanks
    >
    > Jas
    >
    >
     
    Aaron Bertrand [MVP], Feb 10, 2004
    #3
  4. if not rs.eof then
    minYear = 2099
    maxYear = 0
    dim years(2010) ' how high?
    ' ...
    do while not rs.eof
    if minYear > rs("year") then minYear = rs("year")
    if maxYear < rs("year") then maxYear = rs("year")
    years(rs("year")) = True
    rs.movenext
    loop
    session("minYear") = minYear
    session("maxYear") = maxYear
    session("years") = years
    end if

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/




    "Jas" <> wrote in message
    news:uY#...
    > can you give an example aaron
    >
    > thanks
    >
    > "Aaron Bertrand [MVP]" <> wrote in message
    > news:u7PiZ#...
    > > Ugh, why? Use an array.
    > >
    > > --
    > > Aaron Bertrand
    > > SQL Server MVP
    > > http://www.aspfaq.com/
    > >
    > >
    > >
    > >
    > > "Jas" <> wrote in message
    > > news:...
    > > > Hi All
    > > >
    > > > I guess I should just have tried this to see if it works but I don't

    > have
    > > > access to a machine running IIS and can't test it and I am itching for

    > an
    > > > answer.
    > > >
    > > > I want to use dynamic variable names in one of my pages.
    > > >
    > > > I store a field called year in one of my table. For each year I want

    to
    > > > create a session variable for that year name perhaphs like the code

    > below.
    > > >
    > > > While not rs.eof
    > > > strVarId = strVarId & rs("year")
    > > > session(strVarId) = True
    > > > rs.movenext
    > > > Wend
    > > >
    > > > the value in the recordset will be
    > > >
    > > > 2002
    > > > 2003
    > > > 2004
    > > > 2005
    > > >
    > > > hence I want 4 session variables like
    > > >
    > > > strVarId2002
    > > > strVarId2003
    > > > strVarId2004
    > > > strVarId2005
    > > >
    > > > Will this work?
    > > >
    > > > Thanks
    > > >
    > > > Jas
    > > >
    > > >

    > >
    > >

    >
    >
     
    Aaron Bertrand [MVP], Feb 10, 2004
    #4
  5. Jas

    Bullschmidt Guest

    Bullschmidt, Feb 12, 2004
    #5
    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. Replies:
    2
    Views:
    8,324
    cesarjusto
    Jul 15, 2010
  2. wanwan
    Replies:
    3
    Views:
    439
    Alex Martelli
    Oct 14, 2005
  3. News123
    Replies:
    2
    Views:
    471
    John Machin
    Nov 26, 2008
  4. Steve Holden

    Re: Dynamic variable names

    Steve Holden, Feb 7, 2010, in forum: Python
    Replies:
    0
    Views:
    384
    Steve Holden
    Feb 7, 2010
  5. Peter Buckley
    Replies:
    5
    Views:
    207
    matt neuburg
    Feb 27, 2009
Loading...

Share This Page