Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can You Build a Session Variable?

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I want to build several session variables dynamically, but I'm not sure on the syntax or even if you can do it.

For example, here's what I'd like:

fnet_path1
fnet_path2
....
fnet_pathx

where x is a number to be determined. Here's what I had, but I don't think Session() allows substitutions other than a name in quotes.


for m=1 to 2 'this is just a sample to see if it works
strFilename = "fnet_path" & i
Session(strFilename) = Server.URLEncode(objDocument.GetCachedFile())
next


But I have an application that shows all session vars and they are not there.
What am I doing wrong? I'm a relative newbie to ASP and would like to steer
clear of arrays if I could.

Thanks,
scripter73


Change Your Thinking, Change Your Life.
 
I have made some changes to your code . I think this will help you to understand how to create session variables dynamically .


For m=1 to 2

strFilename = "fnet_path" & m
Session(strFilename&m)=m 'U can assign any value here
Response.Write Session(strFilename&m) &&quot;<br>&quot;
Next


Good Luck [peace]
 
This code:
Code:
For m=1 to 2   
    strFilename = &quot;fnet_path&quot; & m 
    Session(strFilename&m)=m  'U can assign any value here
    Response.Write Session(strFilename&m) &&quot;<br>&quot;
Next
... isn't quite right, though it *will* run. But if m = &quot;Fred&quot; it makes Session variable:
Code:
Session(&quot;fnet_pathFredFred&quot;)
... am I missing something?

Also, always use spaces around the & concatentation operator. You'll thank me when you have something like:
Code:
strJB123 = strOtherThang&objWidget.StringProp
When VBScript sees: &o... you are telling it you have an octal literal (like &o2734). An &h... gets you in trouble 'cause you have told VBScript you have a hex literal.

So use those spaces! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top