Vig*_*ian 4 excel vba excel-vba
我将变量作为参数传递给函数
为简单起见,我已经提出了这个示例函数来解释我的情况
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
Run Code Online (Sandbox Code Playgroud)
有时FilesDetails会出现这种情况null,在此期间函数返回" For loop not initialized"错误
如何检查变量是否为空?
我试过UBound(FilesDetails), FilesDetails.Count,IsNull(FilesDetails)但没有运气
Vig*_*ian 11
我用下面的方法解决了这个问题
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
Run Code Online (Sandbox Code Playgroud)
如果isArrayAllocated函数不为null,则返回true
试试这个 :-)
Dim var As Variant
If var = Empty Then
MsgBox "Variant data is Empty"
End If
Run Code Online (Sandbox Code Playgroud)
要么
If IsEmpty(var) Then
MsgBox "Variant data is Empty"
End If
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22045 次 |
| 最近记录: |