Forum Moderators: open

Message Too Old, No Replies

ASP string question

         

yankobb

10:24 pm on Mar 24, 2003 (gmt 0)

10+ Year Member



I have several session variables in the format Session("var1"), Session("var2"), Session("var3"), etc that I would like to check. How can I build a loop so that each session variable is checked in the loop? In other words something like this:

If Session("var*") = "test" then '* being a wildcard
...
End If

Obviously this doesn't work so what might be a solution to this problem? Thanks in advance.

WebJoe

11:22 pm on Mar 24, 2003 (gmt 0)

10+ Year Member



I havent tried it out but the use of an array could be useful:


Dim myArray(9) ' 10 being the number of elements in this zero-based var
Dim myCounter
Dim myFlag


myCounter = 0
myFlag = False


' your code


Do Until myArray(myCounter) = "Keyword"
If myCounter = 10 Then ' Keyword not found but end of array
myFlag = True
Exit Do
End If
myCounter = myCounter+1
Loop

yankobb

12:23 am on Mar 25, 2003 (gmt 0)

10+ Year Member



I'm a bit new to this so how would I pull these variables into the array? These variables are stored in the global.asa file.

duckhunter

5:01 am on Mar 25, 2003 (gmt 0)

10+ Year Member



Here you go. This will loop through the Session.Contents writing out the names and values:

Dim x
For x = 1 to Session.Contents.Count
response.Write x & ": " & Session.Contents.Key(x) & " = " & Session.Contents.Item(x) & "<BR>"
Next

P.S. Not sure why this array (Session.Contents) doesn't start with the ordinal 0? Key(0) is empty?

TheDave

10:05 pm on Mar 25, 2003 (gmt 0)

10+ Year Member



This should work too:

c=0
while c < 10
v = "var" & c
if session(v) = "test" then
c=c+1
wend

The "Var1" part of session("Var1") is just a string, so you can put a variable in there in it's place.