<div class="meta" robots="noindex">

</div>

Method

# Ubound

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `Arrays.LastIndex<arrays.lastindex>` as a replacement.

</div>

## Description

Returns the upper bound of the array (the index of the last element). Arrays are 0-based.

## Usage

*result* = **Ubound**(*array*\[,*dimension*\])

**OR**

*result* = *array*.**Ubound**

| Part      | Type                               | Description                                                                                                    |
|-----------|------------------------------------|----------------------------------------------------------------------------------------------------------------|
| result    | `Integer</api/data_types/integer>` | The index of the last element in the array specified.                                                          |
| array     | Array of any data type             | The array whose last element number you want.                                                                  |
| dimension | `Integer</api/data_types/integer>` | Relevant only for multi-dimensional arrays. Used to specify the dimension for which you want the last element. |

## Notes

The <span class="title-ref">Ubound</span> function is used to determine the last element of an array, but it can also be used to determine the size of an array. It may appear at first that the last element number and the size of the array are the same but in fact they are not. All arrays have a zero element. In some cases element zero is used and in other cases it is not. You will need to keep this in mind when using the <span class="title-ref">Ubound</span> function to determine the number of values you have in the array. For example, if the array is zero-based, then element zero is used to store a value and you will have to add one to the value returned by the <span class="title-ref">Ubound</span> function to get the number of values in the array.

All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646.

For multi-dimensional arrays, <span class="title-ref">Ubound</span> 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.

<div class="note">

<div class="title">

Note

</div>

For mult-dimensional arrays, you must use the global <span class="title-ref">Ubound</span> method and not the array method.

</div>

## Sample code

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

``` xojo
For i As Integer = 0 To Ubound(Names)
  If Names(i) = "X" Then
    Names(i) = "Y"
  End If
Next
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following code returns -1 because the newly-declared array has no elements:

``` xojo
Dim i() As Integer
Dim j As Integer
j = Ubound(i)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following code uses the alternative syntax to get the value:

``` xojo
Dim myArray(5) As Integer
Dim lastElementIndex, numberOfElements As Integer
lastElementIndex = myArray.Ubound
numberOfElements = myArray.Ubound + 1
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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).

``` xojo
Dim i, j As Integer
Dim aNames (5, 3) As String
i = Ubound(aNames)
j = Ubound(aNames, 2)
```

## Compatibility

All project types on all supported operating systems.

## See also

`Dim</api/language/dim>` statement; `Array</api/language/array>`, `String<string.fromarray>`, `String<string.split>` functions; `Arrays<arrays.add>`, `Arrays.IndexOf<arrays.indexof>`, `Arrays<arrays.addat>`, `Pop<arrays.pop>`, `Redim</api/language/redim>`, `Arrays<arrays.removeat>`, `Shuffle</api/language/shuffle>`, `Sort<arrays.sort>`, `Sortwith<arrays.sortwith>` methods; `ParamArray</api/language/paramarray>` keyword; `Arrays</api/language/arrays>` concept
