VBA 变体数组 - 空值测试不适用于整数值 0
VBA Variant Array - test for empty is not working with integer value of 0
我有以下 VBA 代码摘录,
Dim ERA_Curves AS Variant
ReDim ERA_Curves(2000,19)
ERA_Curves (350,4) = 0
然后当我测试
ERA_Curves(350,4) <> Empty
它returns 'False'
难道它不应该 return True 因为它在内存中有一些价值吗?我想测试内存是否真的是空的,(没有分配任何类型值)我在这里遗漏了什么吗?
您需要 IsEmpty function - 像这样使用:
If IsEmpty(ERA_Curves(350, 4)) Then
使用 <、> 等将事物与 Empty 进行比较不起作用,但如果您愿意,可以将 Empty 直接分配给 Variant:
ERA_Curves(350, 4) = 0
If IsEmpty(ERA_Curves(350, 4)) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
ERA_Curves(350, 4) = Empty
If IsEmpty(ERA_Curves(350, 4)) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
我有以下 VBA 代码摘录,
Dim ERA_Curves AS Variant
ReDim ERA_Curves(2000,19)
ERA_Curves (350,4) = 0
然后当我测试
ERA_Curves(350,4) <> Empty
它returns 'False'
难道它不应该 return True 因为它在内存中有一些价值吗?我想测试内存是否真的是空的,(没有分配任何类型值)我在这里遗漏了什么吗?
您需要 IsEmpty function - 像这样使用:
If IsEmpty(ERA_Curves(350, 4)) Then
使用 <、> 等将事物与 Empty 进行比较不起作用,但如果您愿意,可以将 Empty 直接分配给 Variant:
ERA_Curves(350, 4) = 0
If IsEmpty(ERA_Curves(350, 4)) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
ERA_Curves(350, 4) = Empty
If IsEmpty(ERA_Curves(350, 4)) Then
MsgBox "empty"
Else
MsgBox "not empty"
End If