VBA LBound函数

作者在 2021-07-13 20:51:34 发布以下内容
LBound 函数
LBound函数返回指定数组中最小的下标。因此,阵列的LBound为零。
语法:
LBound(ArrayName[,dimension])
ArrayName, 必需的参数。该参数对应于所述数组的名称。
dimenstion, 一个可选的参数。这需要对应于所述阵列的维数的整数值。如果它是“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
vba | 阅读 727 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论