Function Reference


UBound

Returns the size of array dimensions or the number of keys in a map.

UBound ( Variable [, Dimension = 1] )

Parameters

Variable An array or map variable
Dimension [optional] For an array - Which dimension size to return:
    $UBOUND_DIMENSIONS (0) = Number of subscripts in the array
    $UBOUND_ROWS (1) = Number of rows in the array (default)
    $UBOUND_COLUMNS (2) = Number of columns in the array
For arrays with more than 2 dimensions, just use the corresponding integer
For a map - this parameter is ignored and the number of keys is returned

Constants are defined in AutoItConstants.au3.

Return Value

Success: the size of the array dimension or the number of keys within a map.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 = Array: Variable is not an array or map
2 = Dimension is invalid

Remarks

Remember that for arrays the value returned is one greater than the index of the last element in the dimension as the count starts at [0].

Related

Global/Local, ReDim, IsArray

Example

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3> ; Required for _ArrayDisplay.

Example()

Func Example()
    Local $aArray[10][20]
    Local $iRows = UBound($aArray, $UBOUND_ROWS) ; Total number of rows. In this example it will be 10.
    Local $iCols = UBound($aArray, $UBOUND_COLUMNS) ; Total number of columns. In this example it will be 20.
    Local $iDimension = UBound($aArray, $UBOUND_DIMENSIONS) ; The dimension of the array e.g. 1/2/3 dimensional.

    MsgBox($MB_SYSTEMMODAL, "", "The array is a " & $iDimension & " dimensional array with " & _
            $iRows & " row(s) & " & $iCols & " column(s).")

    ; Fill the array with data.
    For $i = 0 To $iRows - 1
        For $j = 0 To $iCols - 1
            $aArray[$i][$j] = "Row: " & $i & " - Col: " & $j
        Next
    Next
    _ArrayDisplay($aArray)
EndFunc   ;==>Example