Go to: Articles List

Arrays How To Part 2 : Functions related to arrays explained
Part 1 | Part 2 | Part 3 | Part 4

There are three main functions related to Arrays that you should be aware of: LBound(), UBound(), and Split(). I will define each and explain when to use each of them.

LBound(ArrayName[, ArrayDimension])
- Returns the lowest element available in an array, usually 0.
- ArrayName is any valid array
- ArrayDimension is an option parameter, it specifies which dimension of the array you want to find the lower bound of.
- 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.

UBound(ArrayName[, ArrayDimension])
- Returns the highest element available in an array.
- ArrayName is any valid array
- ArrayDimension is an option parameter, it specifies which dimension of the array you want to find the upper bound of.
- 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 (remember zero base) then the upper bound would be 9.

Split(StringToSplit[, DelimiterToUse, HowMany])
- Returns a one dimensional array
- StringToSplit is any valid string
- DelimiterToUse is the character that you want the string to be split by.
- HowMany is the number of elements you want to limit the array to.
- DelimiterToUse and HowMany are optional parameters.
- If you leave out the DelimterToUse, the function uses a space to split the string.

Example:

Dim MyString, MyArray
MyString = "apples,oranges,grapes"
MyArray = Split(MyString, ",")


Result:
A one dimensional array called MyArray with 3 elements.