- VBA 教程
- VBA - 主頁
- VBA - 概述
- VBA - Excel 宏
- VBA - Excel 術語
- VBA - 宏註釋
- VBA - 訊息框
- VBA - 輸入框
- VBA - 變數
- VBA - 常量
- VBA - 運算子
- VBA - 決策
- VBA - 迴圈
- VBA - 字串
- VBA - 日期和時間
- VBA - 陣列
- VBA - 函式
- VBA - 子過程
- VBA - 事件
- VBA - 錯誤處理
- VBA - Excel 物件
- VBA - 文字檔案
- VBA - 程式設計圖表
- VBA - 自定義窗體
- VBA 有用資源
- VBA - 快速指南
- VBA - 有用資源
- VBA - 討論
VBA - UBound 函式
UBound 函式返回指定陣列中較大的下標。因此,此值對應陣列的大小。
語法
UBound(ArrayName[,dimension])
引數說明
ArrayName − 一個必需的引數。此引數對應陣列的名稱。
Dimension − 一個可選引數。它採用與陣列維數對應的整數值。如果為“1”,則它返回第一維的下界;如果為“2”,則它返回第二維的下界,依此類推。
示例
新增一個按鈕並新增以下函式。
Private Sub Constant_demo_Click()
Dim arr(5) as Variant
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
msgbox("The smallest Subscript value of the given array is : " & UBound(arr))
' For MultiDimension Arrays :
Dim arr2(3,2) as Variant
msgbox("The smallest Subscript of the first dimension of arr2 is : " & UBound(arr2,1))
msgbox("The smallest Subscript of the Second dimension of arr2 is : " & UBound(arr2,2))
End Sub
執行以上函式時,它產生以下輸出。
The smallest Subscript value of the given array is : 5 The smallest Subscript of the first dimension of arr2 is : 3 The smallest Subscript of the Second dimension of arr2 is : 2
vba_arrays.htm
廣告
