2016-02-23 42 views
0

我有以下VBA代碼提取整數值工作,VBA變量數組 - 測試空不爲0

Dim ERA_Curves AS Variant 
ReDim ERA_Curves(2000,19) 

ERA_Curves (350,4) = 0 

然後當我測試

ERA_Curves(350,4) <> Empty 

返回「 False'

它不是假設它返回True,因爲它在內存中有一些價值嗎?我想測試內存是否真的是空的,(我沒有分配任何類型的值)我在這裏丟失了什麼?

回答

1

您需要IsEmpty function - 像這樣使用:

If IsEmpty(ERA_Curves(350, 4)) Then 

比較事情<清空,>等不工作,但如果你願意,你可以直接分配到空的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 
+0

工程就像一個魅力!謝謝。 – lukieleetronic