获取数组长度? [英] Get length of array?
本文介绍了获取数组长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取数组的长度,但是我仍然收到错误Object Requeried。
I'm trying to get the length of an array yet I keep getting the error "Object Requeried".
我做错了?
Dim columns As Variant
columns = Array( _
"A", "ID", _
"D", "Name")
Debug.Print columns.Length ' Error: Object required
推荐答案
数组长度
UBound(columns) LBound(列)+1
UBound
每个数组的长度在VBA中的数组可以从不同的索引开始,例如`Dim arr(2 to 10)
UBound
alone is not the best method for getting the length of every array as arrays in VBA can start at different indices e.g `Dim arr(2 to 10)
UBound
将返回正确的结果,只有当数组为1(开始索引为1,例如 Dim arr(1到10)
,在任何其他情况下都会返回错误的结果例如 Dim arr(10)
UBound
will return correct results only if the array is 1-based (starts indexing at 1 e.g. Dim arr(1 to 10)
. It will return wrong results in any other circumstance e.g. Dim arr(10)
More on the VBA Array in this VBA Array tutorial.
这篇关于获取数组长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文