Codefixer - ASP tutorials, resources and software
ASP.NET 3.5/2.0 Hosting – Click Here
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Saturday 10 May
MembersPro PayPal - ASP Membership software

DiscountASP.NET – ASP.NET 3.5/2.0 Hosting


ASP Partner ASP Partner ASP Partner more partners...

ASP Arrays

In short arrays are variables that can store more than one value. They are used to store a series of related information.
Lets create an array called 'myArray' that will hold the names of 7 soccer teams.

Arrays in ASP/VBScript have a zero based index. This means that the first item in the array starts at 0.

<%
'Lets create our Array. First lets declare our Array variable
Dim myArray(6)

myArray(0)="spurs"
myArray(1)="celtic"
myArray(2)="ipswich"
myArray(3)="liverpool"
myArray(4)="man utd"
myArray(5)="ac milan"
myArray(6)="juventus"
'Now lets create a loop moving through the array and printing out the values
'In the loop below we will simply substitute the value of i in myArray(i)
'for the first loop through i will be 0, then 1 and so on until it passes through 6
For i=0 to 6
response.write myArray(i) & "<br>"
Next     'move on to the next value of i
%>

Output:

spurs
celtic
ipswich
liverpool
man utd
ac milan
juventus

In the example code above we have defined values for each individual array element on separate lines. Another way to create an array especially for smaller arrays is to define the whole array in one line with each element separated by a comma.

<%
Dim myArray
myArray = Array("spurs","celtic","ipswich","brazil")
%>

Again we could loop through the array and print out the values in each array element.

<%
Dim myArray
myArray = Array("spurs","celtic","ipswich","brazil")
For i=0 to 3
response.write myArray(i) & "<br>"
Next     'move on to the next value of i
%>

Assigning an array size as in the example code below with a variable will result in an error. You have to use an integer unless it's a dynamic array.

<%
myArraySize=10
Dim myArray(myArraySize)
%>

In part 2 read about 'Array Functions'
In part 3 read about 'Multidimensional Arrays'
In part 4 read about 'Dynamic Arrays'



LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software