is if x <> empty the same as if not isempty(x)

92 views Asked by At

Are these two snippets equivalent in VBScript?

If x <> empty
    'do something
End if

If not isempty(x)
    'dosomething
End if



Context:

I want to rewrite a condition from

If ((Not IsEmpty( Var ) ) And  ( Var <> "" ) )    Then 

to the less verbose

If Var <> Empty And Var <> ""  Then
1

There are 1 answers

1
Alex K. On BEST ANSWER

No; the operator approach would fail for a variant typed as object

dim woof
set woof = nothing

msgbox isempty(woof) '// ok -> false

msgbox woof = empty  '// object reference not set error

(Because the = approach would attempt to read the value of the default property of the object)