如何检查VBA中的数组是否为空? [英] How to check if an array is empty in VBA?

查看:2299
本文介绍了如何检查VBA中的数组是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,该函数检查数组是否为空。从今天开始,我遇到了运行时错误9。我不知道为什么。

I have a function, which checks whether the array is empty or not. Since today I'm getting an runtime error 9. I don't know why.

这里是代码:

When db table contains data, pass it to the variable => arrItems
arrItems as Variant
ArrEmpty as Boolean

With rs
  If Not .EOF Then
      arrItems = .GetRows
      .Close
  End If
End With

ArrEmpty = IsArrayEmpty(arrItems) 

Private Function IsArrayEmpty(parArray As Variant) As Boolean
    IsArrayEmpty = IIf(UBound(parArray) > 0, False, True) //Here is invoked the runtime error 9
End Function

如何检查数组是否为空?

How can I check if the array is empty?

推荐答案

好,我没有找到更好的解决方案像这样:

Ok I haven't found a better solution like this:

With rs
  If Not .EOF Then
      arrItems = .GetRows
  Else
      arrItems = Array()
  End If
  .Close
End With

ArrEmpty = IsArrayEmpty(arrItems) 

这篇关于如何检查VBA中的数组是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆