LBound()
函式返回指定陣列的最小下標。 因此,陣列的LBound
的結果是零。
LBound(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 : " & LBound(arr))
' For MultiDimension Arrays :
Dim arr2(3,2) as Variant
msgbox("The smallest Subscript of the first dimension of arr2 is : " & LBound(arr2,1))
msgbox("The smallest Subscript of the Second dimension of arr2 is : " & LBound(arr2,2))
End Sub
當執行上面的函式時,它會產生下面的輸出。
The smallest Subscript value of the given array is : 0
The smallest Subscript of the first dimension of arr2 is : 0
The smallest Subscript of the Second dimension of arr2 is : 0