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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop through session 1

Status
Not open for further replies.

gagz

Programmer
Nov 21, 2002
333
US
I have a bunch of session vars:

Code:
session("var0")
session("var1")
session("var2")
session("var3")
session("var4")

I want to loop through them until I see that they don't exist anymore (ie, var5, in this case).

this is how i'm attempting it, but I seem to be in an infinite loop.

Code:
Dim iCount As Integer = 0

While (Session(&quot;RFP&quot; & iCount.ToString) <> &quot;&quot;)
    'some code here...
    iCount = +iCount
End While

Is there something wrong with that?

Thanks.
 
gagz

Instead of having a separate session variable for each item, Create an Array and store that as a session variable.

This way you can access the size of your Session array (the number of items stored) simply by using the UBOUND Command, and you dont have to worry to looping indefinitely.

Here is an example, where im populating an array from a recordset and storing it as a session var, so that upon reloads of the page i dont have to query against the database each time.

... populate 'dsResults' dataset (not shown here) ...

Dim strArray(dsResults.Tables(0).Rows.Count() - 1) As String
Dim intCount As Integer

For intCount = 0 To UBound(strArray)

strArray(intPCCount) = dsResults.Tables(0).Rows(intCount)(&quot;field&quot;)

Next intPCCount
Session(&quot;MySessionArray&quot;) = strArray


I think you will find this easier then dealing with a lot of separate session vars.

S.

(The more ASP.NET I do, the more Javascript I find myself using)
 
hmm... i'm trying this... but no having much luck:

Code:
'for testing purposes
Dim arrTest(3)

arrTest(0) = &quot;123456||gold&quot;
arrTest(1) = &quot;12345||gold&quot;
arrTest(2) = &quot;12346||silver&quot;

Session(&quot;RFPVenues&quot;) = arrTest

Dim arrSession(3) As String
arrSession = Session(&quot;RFPVenues&quot;)

so this should work right?

I get: Specified cast is not valid.

any thoughts? For some reason i'm in array hell today [evil].

 
You are puttin the array into the session properly but to get it out is a bit different.

Dim arrSession() As String
arrSession = Session(&quot;RFPVenues&quot;)


This will get the array out of session. I can't recall off the top of my head but you can't specify the size of the array before you get it out of session. If you want to add an item to the array use this command

ReDim Preserve selectedSites(newsize of array)


This will preserve the old data and add new elements to the array up to the size you specified. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
arg! still says 'specified cast not valid'... i've commented everything else out so I can't understand whats going on...

but.... this does...
Code:
Dim x

For x = 0 To Session(&quot;RFPVenues&quot;).Length - 1
    strWhereGold &= Session(&quot;RFPVenues&quot;).Length
Next

prints out 4444... (which is the length). so i ask, is it worth trying to get it into a local array? i imagine so, for adding to it... but i can't get that piece to work!
 
Dim arrTest(3)
Did you keep this line? You need to specify what type of variable is going into the array. I think that should solve your problems. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Bingo... I can't believe i missed that... star for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top