Arrays.FirstRowIndex

From Xojo Documentation

Method

Returns the index of the first row of the array.

Usage

result = array.FirstRowIndex

Part Type Description
result Integer The index of the first element in the array specified.

If the passed array has no elements, result is set to -1.

array Array of any data type The array whose last element number you want.
dimension Integer Relevant only for multi-dimensional arrays. Used to specify the dimension for which you want the last element.

The first dimension is numbered 1. If passed -1, it will return the number of dimensions in the array. If passed a non-existent dimension, it will cause an OutOfBoundsException error.

Notes

The FirstRowIndex function is used to determine the first element of an array. This is especially useful for writing code that loops through arrays so that you don't have to be aware of whether an array begins at 0 or 1 (they all begin at 0).

Arrays can have a maximum index value of 2,147,483,646.

Sample Code

This code loops through an array and replaces each occurrence of X in an array with Y.

For i As Integer = names.FirstRowIndex To names.LastRowIndex
If Names(i) = "X" Then
Names(i) = "Y"
End If
Next

See Also

Var statement; Arrays concept, ParamArray keyword