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

ASP Session arrays without reloading whole array into local one-Read!

Status
Not open for further replies.

BeanDog

Programmer
Jul 15, 2000
60
US
I had this wierd idea. Everywhere I read, it says that the only way to store an array in a Session is like this:

Dim x(400)
x(3) = 3
x(4) = 5
Session("x") = x

'later
x = Session("x")
Response.Write x(3)
Response.Write x(4)

Right? But I've made this little snippet of code:

function GetSessionArray(aname, idx)
GetSessionArray = Session(aname & idx)
end function
sub SetSessionArray(aname, idx, val)
Session(aname & idx) = val
end sub

So I can go like this:

SetSessionArray("x", 3, 3)
SetSessionArray("x", 4, 6)

'later
for i = 1 to 400
Response.Write GetSessionArray("x", i)
next

What do you think? [sig][/sig]
 
although your method works, you're not using arrays.

Plus, every session variable uses memory. If your pseudo-array has 1000 values, you need 1000 session variables. It wouldn't take too many users to bring your server to its knees.

a good idea, but my suggestion is to go with the single session variable. [sig]<p>nick bulka<br><a href=mailto: > </a><br>[/sig]
 
Look at the VBScript functions Split() and Join(). This uses a string with delimiters to fetch/put into arrays. It is also easy to debug and faster.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top