Link to home
Start Free TrialLog in
Avatar of juststeve
juststeve

asked on

Session variable Name/Key problem

I was working on figuring out how to include a loop's counter's incrementer in the name of a session var. On the way there I constructed a loop that initialized and displayed both the value of the session var and the name of the session var.

I solved my most immediate problem...I can name a session variable by concatenating the loop's counter with a prefix (session("var" & i) = i) but when I try to write the name of a session variable (via its KEY) strange things happen.

<%

for i = 1 to 10

session("var" & cstr(i)) = i
response.write "<p>" & i & ". Contents of the session var: " & session("var" & i) & " <br>Session Name is: " & session.Contents.key(i) & "</p>"

next

%>

Output of the above code is at:

http://216.64.209.102/testloop.asp

Why is the name (KEY) of the session var correct on the 1st iteraction (var1) but not correct on the rest?

thankx
--steve...
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Works fine for me... ;-)
Avatar of juststeve
juststeve

ASKER

good lord...now it does. every time I ran it while composing the question I got:

1. Contents of the session var: 1
Session Name is: var1

2. Contents of the session var: 2
Session Name is: -1

3. Contents of the session var: 3
Session Name is: -2

4. Contents of the session var: 4
Session Name is: -3

5. Contents of the session var: 5
Session Name is: -4

6. Contents of the session var: 6
Session Name is: -5

7. Contents of the session var: 7
Session Name is: 0

8. Contents of the session var: 8
Session Name is: 1

9. Contents of the session var: 9
Session Name is: 2

10. Contents of the session var: 10
Session Name is: 3

That was across a number different versions of the code. For example...I changed the loop to 1 to 5 to see if the neg numbers changed thier pattern. They didn't. They just stopped earlier.

And I was working against the server remotely just like from here.

Ya gotta believe me. I saw strangeness.

Points go to whoever devises the best reason for my vision of strangeness. Drug-induced theories exempted.

thankx
--steve...

Works for me, too. How are you setting the Session variable?
ASKER CERTIFIED SOLUTION
Avatar of dgorin
dgorin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thankx for the snippet dgorin...that'll come in handy in the future I'm sure. Feel free to post the rest of that diagnostic if it's not too much trouble.

robbert...the output I pasted was created by the snippet of code in the original message. For whatever reason...on multiple hits against several variations of that code I got that output. Later, (with a reboot in-between), after the first 'works for me', I started getting the correct output as all you folks have seen.

So I'm a bit baffled but I can live with that...which is a good thing being its a frequent condition.

thankx for the time folks.
--steve...
Hey dgorin, what town are you in?
I'd rather not post the name here, but I see we're pretty close (I looked at your web site).  I'll send you an email from your site.
Which one?  ;-)
mgfic.com, but there's no email address
I'min the process of moving that site, the Host has pretty much SHUT DOWN.  My temecularodrun.com site is hosted there too, pe.net said I can use their DNS servers if I want to, I already have everything else available and set-up at home, servers, router, multiple static IP's, 756 up and down...

mgfranz@pe.net