函数说明

UBound

返回(多维)数组中各维的大小。

UBound ( 数组 [, 维] )

 

参数

数组 目标数组。
[可选参数] 多维数组的指定维的大小。默认值为 1,表示第一维。若此参数为0,则返回数组的下标数(维数)。

 

返回值

成功: 返回数组各维的大小。
失败: 返回值为0,并把 @error 设为下列数值之一:
1 = 给定的“数组”并非数组。
2 = 数组维数无效。

 

注意

记住,UBound 返回的数值比数组最后一个元素的下标大1。

 

相关

Dim

 

示例


Dim $myArray[10][20]   ;含有从 0,0 到 9,19 的元素
$rows = UBound($myArray)
$cols = UBound($myArray, 2)
$dims = UBound($myArray, 0)

MsgBox(0, "给定的 " & $dims & " 维数组具有", _
    $rows & " 行, " & $cols & " 列 元素")

;显示 $myArray's 的内容
$output = ""
For $r = 0 to UBound($myArray,1) - 1
    $output = $output & @LF
    For $c = 0 to UBound($myArray,2) - 1
        $output = $output & $myArray[$r][$c] & " "
    Next
Next
MsgBox(4096,"数组元素的值", $output)