我有:
'Set logFileObj = fso.CreateTextFile("cit.log",True)
if logFileObj = "" then
WScript.StdOut.WriteLine "logFileObj not set"
else
WScript.StdOut.WriteLine "logFileObj set"
end if
这很有效。然后我尝试:
Set logFileObj = fso.CreateTextFile("cit.log",True)
if logFileObj = nothing then
WScript.StdOut.WriteLine "logFileObj not set"
else
WScript.StdOut.WriteLine "logFileObj set"
end if
我得到Microsoft VBScript runtime error: Object doesn't support this property or method
我已将if logFileObj = "" then
替换为if logFileObj = nothing then
答案 0 :(得分:1)
要与Nothing
进行比较,您必须使用Is
而不是=
:
Set logFileObj = fso.CreateTextFile("cit.log", True)
If logFileObj Is Nothing Then
WScript.StdOut.WriteLine "logFileObj not set"
Else
WScript.StdOut.WriteLine "logFileObj set"
End If
这是因为=
不能用于比较VBScript中的对象引用,Nothing
是对空对象的引用。
有关详细信息,请参阅Nothing
上的文档:https://msdn.microsoft.com/en-us/library/f8tbc79x(v=vs.84).aspx
答案 1 :(得分:-2)
您可以使用Isobject,如下面的代码所示: -
if isobject(logFileObj) then
WScript.StdOut.WriteLine "logFileObj not set"
else
WScript.StdOut.WriteLine "logFileObj set"
end if