Returns the size of array dimensions or the number of keys in a map.
UBound ( Variable [, Dimension = 1] )
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. |
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 |
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].
Global/Local, ReDim, IsArray, IsMap
#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
#include <Array.au3>
_Example()
Func _Example()
ConsoleWrite("> $aTest_1_Empty_Array" & @CRLF)
Local $aTest_1_Empty_Array[]
ConsoleWrite(UBound($aTest_1_Empty_Array, $UBOUND_DIMENSIONS) & @CRLF)
ConsoleWrite(UBound($aTest_1_Empty_Array, $UBOUND_ROWS) & @CRLF)
ConsoleWrite(UBound($aTest_1_Empty_Array, $UBOUND_COLUMNS) & @CRLF)
ConsoleWrite("> $aTest_2_Empty_1D" & @CRLF)
Local $aTest_2_Empty_1D[0]
ConsoleWrite(UBound($aTest_2_Empty_1D, $UBOUND_DIMENSIONS) & @CRLF)
ConsoleWrite(UBound($aTest_2_Empty_1D, $UBOUND_ROWS) & @CRLF)
ConsoleWrite(UBound($aTest_2_Empty_1D, $UBOUND_COLUMNS) & @CRLF)
ConsoleWrite("> $aTest_3_Empty_2D" & @CRLF)
Local $aTest_3_Empty_2D[0][5]
ConsoleWrite(UBound($aTest_3_Empty_2D, $UBOUND_DIMENSIONS) & @CRLF)
ConsoleWrite(UBound($aTest_3_Empty_2D, $UBOUND_ROWS) & @CRLF)
ConsoleWrite(UBound($aTest_3_Empty_2D, $UBOUND_COLUMNS) & @CRLF)
ConsoleWrite("> $aTest_4_1D" & @CRLF)
Local $aTest_4_1D[] = [0, 1, 2]
ConsoleWrite(UBound($aTest_4_1D, $UBOUND_DIMENSIONS) & @CRLF)
ConsoleWrite(UBound($aTest_4_1D, $UBOUND_ROWS) & @CRLF)
ConsoleWrite(UBound($aTest_4_1D, $UBOUND_COLUMNS) & @CRLF)
ConsoleWrite("> $aTest_5_2D" & @CRLF)
Local $aTest_5_2D[][] = _ ; [[0, 1, 2], [3, 4, 5]]
[ _
[0, 1, 2], _
[3, 4, 5] _
]
ConsoleWrite(UBound($aTest_5_2D, $UBOUND_DIMENSIONS) & @CRLF)
ConsoleWrite(UBound($aTest_5_2D, $UBOUND_ROWS) & @CRLF)
ConsoleWrite(UBound($aTest_5_2D, $UBOUND_COLUMNS) & @CRLF)
ConsoleWrite("> $aTest_6_2D" & @CRLF)
Local $aTest_6_2D[][] = _ ; [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 1, 2]]
[ _
[0, 1, 2], _
[3, 4, 5], _
[6, 7, 8], _
[0, 1, 2] _
]
ConsoleWrite(UBound($aTest_6_2D, $UBOUND_DIMENSIONS) & @CRLF)
ConsoleWrite(UBound($aTest_6_2D, $UBOUND_ROWS) & @CRLF)
ConsoleWrite(UBound($aTest_6_2D, $UBOUND_COLUMNS) & @CRLF)
EndFunc ;==>_Example