2016-12-21 117 views

回答

5

NULL是沒有價值*

""的是一個零長度字符串

由於隱式轉換 - 尚未填充尚未威力返回真爲這兩種情況下一個對象。但是,如果你要放置的""值在那裏,它會爲isnull()和True返回False爲= ""

*感謝Comintern爲改善說明(見註釋)

+0

可能更準確的說,null是沒有價值以避免與Nothing混淆的結果IsNull(Nothing)計算結果爲false,因爲Nothing是一個對象引用 – Comintern

+0

@Comintern好點,我會更新我的答案 –

+0

而你忘了_Empty_。 – Gustav

-1

isnull表示值不同時編輯知:""意味着它是零長度字符串*


*信用卡:@Macro人。

+4

_Empty_是 「」 非常不同。 – Gustav

+0

正確。我的錯。 (儘管我看到這是一個常見的誤解,因爲我現在注意到@Erik von Asmuth也回答了這個問題。「」「是一個空字符串。」儘管我喜歡他的想法,使用'If nz([variable], 「」)=「」Then') [我在這裏很新 - 我應該編輯我寫的東西?] –

+1

是的,Nz的方法似乎無與倫比,如果你可以編輯你的答案,一定要繼續。聖誕節快樂 – Gustav

2

如說其他答案,null是無用的,「」是一個空字符串。

爲了測試在訪問VBA null和空變量,使用以下命令:

If nz([variable], "") = "" Then do stuff 

新西蘭函數將空變量「」或0

3

如果你這樣做檢查,以品牌sense x必須是變體,並且Null不是「Nothing」。沒有意思是空的,並且存在特殊的檢查。

運行該看看:

Dim x As Variant 

Debug.Print IsEmpty(x) ' True 
Debug.Print IsNull(x) ' False 
Debug.Print x = ""  ' True 
Debug.Print Nz(x) = "" ' True 

x = Null 
Debug.Print IsEmpty(x) ' False 
Debug.Print IsNull(x) ' True 
Debug.Print x = ""  ' Null 
Debug.Print Nz(x) = "" ' True 

x = "" 
Debug.Print IsEmpty(x) ' False 
Debug.Print IsNull(x) ' False 
Debug.Print x = ""  ' True 
Debug.Print Nz(x) = "" ' True 
+1

你可以添加結果作爲一個評論權''debug.print'行,以提高可讀性... –

+0

好吧,花了一些打字... – Gustav

+0

完美,從我+1已經授予:) –

0

,當我想檢查空/空字符串 我用

If x & "" <> "" then 
相關問題