There are 3 VBScript functions that come in handy when working with arrays. These are the UBound, LBound and Split functions.
This function will return the 'index' of the highest element in an array. The index is basically the position of the element in the array. Arrays in ASP/VBScript have a zero based starting index.
Syntax: UBound(ArrayName)
- This function will return the highest element available in an
array.
- If your array has 10 elements (remember zero base) then the
upper bound would be 9.
Example:
Output: 3
Syntax: LBound(ArrayName)
- This function will return the lowest element available in an
array, in most cases 0.
Example:
Output: 0
The Split function is used to split (break up) a string of characters into an array.
Syntax: Split(String, Delimiter, Count)
- String is the string we will be splitting
- Delimiter is the character that you want the string to be split
by.
- Count is the number of elements you want to limit the array
to and is optional.
Example:
The Result would be an array called MyArray with 4 elements.
Again we could loop through the array and print out the values in each array element. In this example we'll also incorporate the UBound function.
Notice that in the code above we used the UBound Function which returns the index of the highest element in the array. In this case it's 3 so the For i loop will loop from 0 to 3.
In Part 1 read about 'Arrays'
In Part 3 read about 'Multidimensional
Arrays'
In part 4 read about 'Dynamic
Arrays'
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.
Get your best asp web hosting provider now and save 25%