我正在将变体作为参数传递给函数
为简单起见,我提供了此示例函数来解释我的情况
Public Function test()
Dim arr() As String
testing (arr)
End Function
Public Function testing(ar As Variant)
If ar = Empty Then
MsgBox ("Hello")
End If
End Function
有时FilesDetails
会是null
,在这段时间函数返回“ For loop not initialized
”错误
如何检查变体是否为空?
我尝试过UBound(FilesDetails), FilesDetails.Count,IsNull(FilesDetails)
但没有运气
我通过使用以下方法解决了
Public Function test()
Dim Arr(1) As String
Arr(0) = "d"
Dim x As Boolean
x = IsArrayAllocated(Arr)
End Function
Function IsArrayAllocated(Arr As Variant) As Boolean
On Error Resume Next
IsArrayAllocated = IsArray(Arr) And _
Not IsError(LBound(Arr, 1)) And _
LBound(Arr, 1) <= UBound(Arr, 1)
End Function
如果isArrayAllocated函数不为null,则返回true
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句