Reputation: 797
When declaring a variable to blank (before a loop for example), it is sometimes done as "" or Empty. Also, when checking the value, it is sometimes used with "(Not IsEmpty(variable))" and "variable <> Empty". Is it better to use one vs another and can it cause any issues using it the wrong way?
Ex1:
Ex2:
Thanks!
------------Update-------------
Note that my question is not asking for the difference between Null, Empty, and Nothing. I'm simply concentrating on the "Empty" part and whether it's the same things as writing "". For the most part, I have received similar results when interchanging the two, but I dont know if it's just the examples I used. For example, the following confused me some.
My code:
Dim x, y, z
'Option1 (Do not set x to anything)
'Option2
'x = Empty
'Option3
'x = ""
If x = "" Then
'Action1
End if
If x = Empty Then
'Action2
End if
If IsEmpty(x) Then
'Action3
End if
Why?
Upvotes: 2
Views: 10535
Reputation: 3485
Some considerations:
fileNameDate = Empty ' The same as just declaring Dim fileNameDate
IsEmpty(fileNameDate) ' = True
Is not the same as:
fileNameDate = ""
IsEmpty(fileNameDate) ' = False
I think the function IsEmpty()
is misnamed, because it checks if the variable has been initialized, not if it's actually empty.
Upvotes: 6