This tutorial shows you how to put your arrays in a session variable so you will be able to carry them from page to page throughout your site.
First you must declare your array in a declaration statement
The number in the () is how many array elements you want to include in your array.
Next you set each index of the array to what you wish to store. In this case we are going to store "Hello " in index 1 and "World" in index 2.
Code:
arrMyArray(0) = "Hello"
arrMyArray(1) = " World"
Now we are ready to make it into a session variable so it can be used throughout the site. Remember you have already defined your array so there is no need to tell the session variable how many elements it needs to store.
Code:
Session("arrMyArray") = arrMyArray Finally we are going to create a simple for...next loop to write the array to the page. The function Ubound gets the number of array elements. This function is very handy incase you need to increase or decrease your array size because you do not have to change anything in your code except for the number of elements in your declaration statement.
Code:
for i = 0 to Ubound(arrMyArray)
response.write Session("arrMyArray")(i)
next Once your done with these steps Hello World should display on your page. The full code block is listed below for easy reference.
Code:
Dim arrMyArray(2)
arrMyArray(0) = "Hello"
arrMyArray(1) = " World"
Session("arrMyArray") = arrMyArray
for i = 0 to Ubound(arrMyArray)
response.write Session("arrMyArray")(i)
next Tutorial Written by
Ryan Wischmeyer
Indianapolis, IN