【发布时间】:2013-05-02 13:53:28
【问题描述】:
很抱歉问了这么一个基本问题,但这让我发疯了......
VBA 中的什么函数返回数组中元素的数量...即当数组为空时返回 0?
我不能使用 UBound 执行此操作,因为它在对空数组调用时会引发错误,而且我无法相信通过使用 OnError 来首先确定其是否为空的方法......正如论坛上所建议的那样! array.Length 抱怨一个糟糕的限定符或其他东西。
我真的需要这样做:
dim termAry() as String
populate termAry
...
private sub populate(terms() as String)
redim preserve terms(terms.Length) ' Redim takes ubound for array size
terms(ubound(terms)) = "something really annoying"
end sub
P.S 任何指向一组简明 VBA 语言和函数参考的好的链接都是最有用的...... MSDN 似乎真的很晦涩!!!
【问题讨论】:
-
你想做什么?您需要数组的来源 - 它来自哪里
-
所有你需要处理的就是
if ubound(arr) > 1 then ...,用于初始化使用redim arr(MAX) -
VB中不存在空数组的概念吗?
-