Dynamic Variable Names

J

Jas

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
 
A

Aaron Bertrand [MVP]

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/
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top