LBound()函数返回指定数组的最大下标。 因此,这个值对应于数组的大小。
语法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 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
¥ 我要打赏
纠错/补充
收藏
加QQ群啦,易百教程官方技术学习群
注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/109067.html