Declaring
Arrays
Multi Dimensional Arrays Lbound() Function
UBound()
Function
Split()
function

Arrays in ASP follow the exact same form and rules as those arrays in VBScript. You can create an array of specific size or you can create a dynamic sized array. Arrays are used
to store a series of related data items ,which are related by index number at
the end.Arrays in ASP have a zero based index. This means that the first item
in the array is strArray(0).


Asp – Declaring arrays

Arrays are declared
in the same way as variables declared ,using the keyword Dim.But there
is an extra parameter at the end which specifies the size of the array.

Dim
strArray(3)

strArray(0) = “apple”


strArray(1) = “orange”


strArray(2) = “grapes”

If
you don’t know the number of items in your array then you can create dynamic
array.

Dim
strArray()

Then later you can specify the number of
items using the keyword Redim.

Dim
strArray()

ReDim strArray(2)

strArray(0) = “apple”


strArray(1) = “orange”


strArray(2) = “grapes”


The size of arrays in ASP can be changed while still maintaining
the data that is currently in them by using the following keyword:ReDimPreserve

Dim
strArray(1)

strArray(0) = “apple”


strArray(1) = “orange”


ReDim Preserve strArray(2)


strArray(2) = “grapes”

If you are creating
a small array you can also create it like this:

Dim
strArray

strArray = Array(“grapes”,”oranges”,”apples”)

Top




Asp Multidimensional Arrays

We can keep information
of two dimensional nature in a two dimensional arrays.We can declare it using
following syntax:

Dim
strArray(4,4)

strArray(0,0) = “apple”


strArray(0,1) = “orange


……..

It is a two dimensional
array of size 5 by 5 and hold 25 elements.In VBscript we can declare arrays
up to of 60 dimensional.

Top




Asp – LBound() Function

It returns
the lowest element available in an array, usually 0.The syntax is:

LBound(ArrayName)

Where ArrayName
is any valid array.In multidimensional arrays you should specify array dimension.The
syntax is:

LBound(ArrayName,
ArrayDimension)

 ArrayDimension
defaults to 1, so if you are checking a 1 dimensional array or you want to check
the first dimension you can leave this out.

Top




Asp – UBound() Function

It returns the
highest element available in an array.Th syntax is:

UBound(ArrayName)

Where ArrayName is any valid array.In multidimensional arrays
you should specify array dimension.The syntax is:

UBound(ArrayName ArrayDimension)

ArrayDimension
defaults to 1, so if you are checking a 1 dimensional array or you want to check
the first dimension you can leave this out. If your array has 10 elements 
then the upper bound would be 9.

Top




Asp – Split() function

The syntax is
:

Split(StringToSplit)

Where StringToSplit
is any valid string.It  returns a one dimensional array.

Eg:

<%

Dim MyString, strArray


MyString = “This is an example”


strArray = Split(MyString,)


%>

The result is
an array of size 4.strArray(0) = This ,strArray(1) = is
,strArray(2) = an ,strArray(3) = example

In the above example
the function uses a space to split the string.Also we can the specify character
that we want the string to be split by and the number of elements we want to
limit the array to.The syntax is :

Split(StringToSplit
,SplitByTheCharecter, NumberOfElements)

 If you leave
out the SplitByTheCharecter, the function uses a space to split the string.

Eg:
<%

Dim MyString, strArray


MyString = “apples,oranges,grapes,peaches”


strArray = Split(MyString, “,”)


%>

Result in a one
dimensional array called strArray with 4 elements.

Top



 


 

Leave a Comment