Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-24-2003, 06:49 PM   #1 (permalink)
rdove
Masked Moderator
 
rdove's Avatar
 
Join Date: May 2002
Location: Indianapolis, IN
Posts: 260
rdove is on a distinguished road
Session Arrays

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
Code:
Dim arrMyArray(2)
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
__________________
~Ryan

rdove is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
combining arrays Engineer Standard C, C++ 11 03-12-2005 10:23 AM
Dynamic Arrays, the 'right' way. Mr.Anderson Standard C, C++ 10 10-05-2004 06:00 AM
login session help please Namraw PHP 2 09-14-2004 03:26 PM
check if session variable is null? sde Java 3 07-07-2004 12:27 PM
session_start(): Cannot send session cookie learntophp PHP 2 06-18-2004 07:51 AM


All times are GMT -8. The time now is 08:26 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting