Difference between revisions of "Arrays.LastIndex"
From Xojo Documentation
(Created page with "{{Deprecated | version=2020r2 | replacement=Arrays.LastIndex}} {{MethodBox | name=LastIndex | platform=all | scope=public | owner=Arrays | returntype=Integer | par...") |
(→Sample Code) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
{{MethodBox | {{MethodBox | ||
| name=LastIndex | | name=LastIndex | ||
Line 7: | Line 6: | ||
| returntype=[[Integer]] | | returntype=[[Integer]] | ||
| parameters=Optional dimension As [[Integer]] = 1 | | parameters=Optional dimension As [[Integer]] = 1 | ||
− | | newinversion= | + | | newinversion=2020r2 |
}} | }} | ||
{{Description | {{Description | ||
Line 13: | Line 12: | ||
== Usage == | == Usage == | ||
− | ''result'' = ''array''.''' | + | ''result'' = ''array''.'''LastIndex'''(index) |
{| class="genericTable" | {| class="genericTable" | ||
Line 31: | Line 30: | ||
|dimension | |dimension | ||
|[[Integer]] | |[[Integer]] | ||
− | |Relevant only for multi-dimensional arrays. Used to specify the dimension for which you want the last | + | |Relevant only for multi-dimensional arrays. Used to specify the dimension for which you want the last index. |
The first dimension is numbered 1. If passed a non-existent dimension, it raises an [[OutOfBoundsException]] error. | The first dimension is numbered 1. If passed a non-existent dimension, it raises an [[OutOfBoundsException]] error. | ||
|- | |- | ||
Line 39: | Line 38: | ||
All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646. | All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646. | ||
− | For multi-dimensional arrays, | + | For multi-dimensional arrays, LastIndex returns the index of the last element of the dimension you specify, or, if you do not specify a dimension, it returns the value for the first dimension. The first dimension is numbered 1. |
== Sample Code == | == Sample Code == | ||
Line 61: | Line 60: | ||
<rbcode> | <rbcode> | ||
Var i, j As Integer | Var i, j As Integer | ||
− | Var aNames (5, 3) As String | + | Var aNames(5, 3) As String |
i = aNames.LastIndex | i = aNames.LastIndex | ||
j = aNames.LastIndex(2) | j = aNames.LastIndex(2) |
Latest revision as of 20:47, 1 December 2020
New in 2020r2
Supported for all project types and targets.
Returns the index of the last element in the array. The optional parameter allows you to get the last index of a specific dimension if the array is multi-dimensional.
Usage
result = array.LastIndex(index)
Part | Type | Description |
---|---|---|
result | Integer | The index of the last 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 index.
The first dimension is numbered 1. If passed a non-existent dimension, it raises an OutOfBoundsException error. |
Notes
All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646.
For multi-dimensional arrays, LastIndex returns the index of the last element of the dimension you specify, or, if you do not specify a dimension, it returns the value for the first dimension. The first dimension is numbered 1.
Sample Code
This code replaces each occurrence of X in an array with Y.
If names(i) = "X" Then
names(i) = "Y"
End If
Next
The following code returns -1 because the newly-declared array has no elements:
The following code of a 2-dimensional array returns 5 in the variable i and 3 in the variable j (remember that the first dimension is numbered 1).
See Also
Var statement; Arrays concept; ParamArray keyword, Arrays.FirstIndex method