UBound 函數返回指定數組的最大下標。因此,該值對應於數組的大小。
用法
UBound(ArrayName[,dimension])
ArrayName, 必需參數。此參數對應於數組的名稱。
dimension,一個可選參數。這需要一個與數組維度相對應的整數值。如果是'1',則返回第一維的下界;如果是'2',則返回第二維的下界,以此類推。
示例
<!DOCTYPE html>
<html>
<body>
<script language = "vbscript" type = "text/vbscript">
Dim arr(5)
arr(0) = "1" 'Number as String
arr(1) = "VBScript" 'String
arr(2) = 100 'Number
arr(3) = 2.45 'Decimal Number
arr(4) = #10/07/2013# 'Date
arr(5) = #12.45 PM# 'Time
document.write("The Largest Subscript value of the given array is:" & UBound(arr))
' For MultiDimension Arrays:
Dim arr2(3,2)
document.write(
"The Largest Subscript of the first dimension of arr2 is:" & UBound(arr2,1) & "<br />")
document.write(
"The Largest Subscript of the Second dimension of arr2 is:" & UBound(arr2,2) & "<br />")
</script>
</body>
</html>
當上麵的代碼保存為 .HTML 並在 Internet Explorer 中執行時,它會產生以下結果 -
The Largest Subscript value of the given array is:5 The Largest Subscript of the first dimension of arr2 is:3 The Largest Subscript of the Second dimension of arr2 is:2
相關用法
- VBScript UCase用法及代碼示例
- VBScript InStrRev用法及代碼示例
- VBScript TimeValue用法及代碼示例
- VBScript IsArray用法及代碼示例
- VBScript LBound用法及代碼示例
- VBScript Erase用法及代碼示例
- VBScript InStr用法及代碼示例
- VBScript Left用法及代碼示例
- VBScript DatePart用法及代碼示例
- VBScript FormatDateTime用法及代碼示例
- VBScript IsDate用法及代碼示例
- VBScript Hour用法及代碼示例
- VBScript Right用法及代碼示例
- VBScript Mid用法及代碼示例
- VBScript WeekDayName用法及代碼示例
- VBScript Replace用法及代碼示例
- VBScript Len用法及代碼示例
注:本文由純淨天空篩選整理自 VBScript UBound Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。