If statement 如果x<&燃气轮机;如果不是isempty(x),则将其清空

If statement 如果x<&燃气轮机;如果不是isempty(x),则将其清空,if-statement,vbscript,is-empty,If Statement,Vbscript,Is Empty,这两个代码段在VBScript中等效吗 If x <> empty 'do something End if 背景: 我想从中重写一个条件 If ((Not IsEmpty( Var ) ) And ( Var <> "" ) ) Then 如果((非空(Var))和(Var“”)那么 更不冗长 If Var <> Empty And Var <> "" Then 如果变量为空且变量为“”,则 否;对于类型为objec

这两个代码段在VBScript中等效吗

If x <> empty
    'do something
End if


背景:

我想从中重写一个条件

If ((Not IsEmpty( Var ) ) And  ( Var <> "" ) )    Then 
如果((非空(Var))和(Var“”)那么
更不冗长

If Var <> Empty And Var <> ""  Then
如果变量为空且变量为“”,则

否;对于类型为object的变量,运算符方法将失败


(因为
=
方法会尝试读取对象的默认属性值)

当它发生时,这是在一个遵循if-isobject条件的elseif中,所以在我的例子中这不是问题。这完美地回答了我的问题,谢谢!
If Var <> Empty And Var <> ""  Then
dim woof
set woof = nothing

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

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