Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Session variable Name/Key problem

Posted on 2001-06-09
11
Medium Priority
?
265 Views
Last Modified: 2011-10-03
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...
0
Comment
Question by:juststeve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 18

Expert Comment

by:mgfranz
ID: 6171517
Works fine for me... ;-)
0
 

Author Comment

by:juststeve
ID: 6171542
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...

0
 
LVL 15

Expert Comment

by:robbert
ID: 6171694
Works for me, too. How are you setting the Session variable?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
dgorin earned 200 total points
ID: 6171771
You could use For Each ... Next to iterate through your session object.  Here's a partial snip from an asp diagnostic page I use.

<%
...
for each sItem in Session.Contents
     Response.Write "<LI>Session(" & sItem & ") = "
     Response.write VarType(Session.Contents(sItem))
     Select case varType(Session.Contents(sItem))
     case 2, 3, 4, 5, 6, 7, 8, 11, 12, 17
     Response.Write " " & Session.Contents(sItem) & "</LI>"
     case else
     'NADA
     end select
next
...
%>
0
 

Author Comment

by:juststeve
ID: 6172399
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...
0
 
LVL 5

Expert Comment

by:dgorin
ID: 6172700
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6175646
Hey dgorin, what town are you in?
0
 
LVL 5

Expert Comment

by:dgorin
ID: 6176029
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.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6177253
Which one?  ;-)
0
 
LVL 5

Expert Comment

by:dgorin
ID: 6177683
mgfic.com, but there's no email address
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 6177842
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question