检查是否在 vbscript 中设置对象 [英] check if set object in vbscript
本文介绍了检查是否在 vbscript 中设置对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
set newcon = Server.CreateObject("ADODB.Connection")
如果不是,我需要:
set newcon = nothing
我如何判断它是一个物体还是什么都没有?
how do I tell if it is an object or nothing?
我试过了
newcon is nothing
我得到需要的对象
如果我尝试 isobject
或 isnull
或 isempty
它不会给出真正的布尔值
If I try isobject
or isnull
or isempty
it does not give the true bool val for it
有什么我可以尝试的真正有效的方法吗?
Is there anything I Can try that really works?
推荐答案
我相信你在使用 Is Nothing 测试之前不小心更改了 newcon:
I believe you accidentially changed newcon before testing it with Is Nothing:
>> set newcon = CreateObject("ADODB.Connection")
>> WScript.Echo 0, IsObject(newcon)
>>
0 -1
>> set newcon = Nothing
>> WScript.Echo 1, IsObject(newcon)
>>
1 -1
>> WScript.Echo 2, newcon Is Nothing
>>
2 -1
>> newcon = "oops"
>> WScript.Echo 3, newcon Is Nothing
>>
Error Number: 424
Error Description: Object required
>> WScript.Echo 4, newconn Is Nothing ' oops
>>
Error Number: 424
Error Description: Object required
如果您收到错误 434,则 newcon(或您真正测试的变量)不包含对象或空.
If you get Error 434, then newcon (or the variable you really test) doesn't hold an object or Nothing.
这篇关于检查是否在 vbscript 中设置对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文