Save array in Session object 
Author Message
 Save array in Session object

I want to know that can I save arrays in Session object, so I can use in
other pages??

If so, how's it??

Best Regards,

Eric Yum



Sat, 05 Feb 2005 00:08:32 GMT  
 Save array in Session object

Quote:

> I want to know that can I save arrays in Session object, so I can use
> in other pages??

> If so, how's it??


<html>
<body>
<%
if(Session("myArray")){
  var myArray = Session("myArray");
  Response.Write("found myArray<br>");
  Response.Write("myArray[0] contains: " + myArray[0] + "<br>");
Quote:
}else{

  var myArray = ["aaa","bbb"];
  Session("myArray") = myArray;
  Response.Write("saved myArray<br>");
  Response.Write("Refresh the page to fetch it...<br>");
Quote:
}

%>
</body>
</html>

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 00:31:41 GMT  
 Save array in Session object
Dim sSample
Dim vSample
Dim i

sSample = "Hello,Test,Wow,Sweet,Cool"
vSample = Split(sSample, ",")

Session("Array") = vSample

For i = 0 to Ubound(Session("Array"))
    Response.Write(Session("Array")(i) & "<BR>")
Next


Quote:
> I want to know that can I save arrays in Session object, so I can use in
> other pages??

> If so, how's it??

> Best Regards,

> Eric Yum



Sat, 05 Feb 2005 05:16:29 GMT  
 Save array in Session object
Accessing the saved array as:

For i = 0 to Ubound(Session("Array"))
    Response.Write(Session("Array")(i) & "<BR>")
Next

returns a complete copy of the array on every reference to Session("Array").

Perhaps not a big issue on small arrays, but on larger arrays it is more efficent to get a local copy of the saved array and work with that...

savedArray = Session("Array")
If IsArray(savedArray) Then
    For i = 0 to Ubound(savedArray)
        Response.Write(savedArray(i) & "<BR>")
    Next
End If

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 05:39:42 GMT  
 Save array in Session object
Fair enough.   :)



Accessing the saved array as:

For i = 0 to Ubound(Session("Array"))
    Response.Write(Session("Array")(i) & "<BR>")
Next

returns a complete copy of the array on every reference to Session("Array").

Perhaps not a big issue on small arrays, but on larger arrays it is more
efficent to get a local copy of the saved array and work with that...

savedArray = Session("Array")
If IsArray(savedArray) Then
    For i = 0 to Ubound(savedArray)
        Response.Write(savedArray(i) & "<BR>")
    Next
End If

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 05:47:17 GMT  
 Save array in Session object

Quote:

> Fair enough.   :)

It's also necessary if the saved array is to be modified...

Session("Array")(i) = "new value"

won't update the Session copy of the array, but the following will...

savedArray = Session("Array")
.
.
.
savedArray(i) = "new value"
.
.
.
Session("Array") = savedArray

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--



Sat, 05 Feb 2005 22:45:26 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Split / combine dbases

2. Another Simple Questi

3. DAO, Delphi 2, dbLongBinary

4. Save array in Session object

5. Having trouble saving array in Session object

6. Save array in Session object

7. Saving Objects in Session variables

8. Vesa.bgi and mouse

9. For Delphi Developers.

10. How to delete an array only from the Session Object

11. Passing names of arrays stored in session object to function

 

 
Powered by phpBB® Forum Software