目录

UBound

UBound函数返回指定数组的最大下标。 因此,该值对应于阵列的大小。

语法 (Syntax)

UBound(ArrayName[,dimension])

参数描述 (Parameter Description)

  • ArrayName - 必需参数。 此参数对应于数组的名称。

  • Dimension - 可选参数。 这需要一个与数组维度相对应的整数值。 如果为'1',则返回第一维的下限; 如果是'2',则返回第二维的下限,依此类推。

例子 (Example)

添加按钮并添加以下功能。

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
↑回到顶部↑
WIKI教程 @2018