返回(多維)數(shù)組中各維的大小。
UBound ( 數(shù)組 [, 維] )
參數(shù)
數(shù)組 | 目標(biāo)數(shù)組。 |
維 | [可選參數(shù)] 多維數(shù)組的指定維的大小。默認(rèn)值為 1,表示第一維。若此參數(shù)為0,則返回數(shù)組的下標(biāo)數(shù)(維數(shù))。 |
返回值
成功: | 返回數(shù)組各維的大小。 |
失。 | 返回值為0,并把 @error 設(shè)為下列數(shù)值之一: |
1 = 給定的“數(shù)組”并非數(shù)組。 | |
2 = 數(shù)組維數(shù)無效。 |
注意
記住,UBound 返回的數(shù)值比數(shù)組最后一個元素的下標(biāo)大1。
相關(guān)
Dim
示例
Dim $myArray[10][20] ;含有從 0,0 到 9,19 的元素
$rows = UBound($myArray)
$cols = UBound($myArray, 2)
$dims = UBound($myArray, 0)
MsgBox(0, "給定的 " & $dims & " 維數(shù)組具有", _
$rows & " 行, " & $cols & " 列 元素")
;顯示 $myArray's 的內(nèi)容
$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,"數(shù)組元素的值", $output)