use*_*001 7 vbscript dictionary exists
我究竟做错了什么?从我的测试中,objDic.exists永远不会给出错误!
dim objDic
set objDic = createobject("scripting.dictionary")
objDic.add "test","I have not been deleted"
wscript.echo objDic.item("test") 'Displays -- I have not been deleted
objDic.remove "test"
wscript.echo """" & objDic.item("test") & """" 'Displays -- ""
if objDic.exists("test") then wscript.echo """" & objDic.item("test") & """" 'Displays -- ""
Run Code Online (Sandbox Code Playgroud)
HK1*_*HK1 12
就像我所知,一个字典对象密钥只是通过引用它来创建,就好像它确实存在一样.
wscript.echo objDic.Item("test") 'Creates the key whether it exists or not
wscript.echo objDic.Exists("test") 'Will now return true
Run Code Online (Sandbox Code Playgroud)
这里有一些代码可以用来证明/测试我的理论.我通常使用MsgBox而不是WScript.Echo,正如您将在我的代码中看到的那样.
dim objDic, brk
brk = vbcrlf & vbcrlf
set objDic = createobject("scripting.dictionary")
objDic.add "test","I have not been deleted"
wscript.echo "objDic.Exists(""test""): " & brk & objDic.item("test")
WScript.Echo "Now going to Remove the key named: test"
objDic.remove "test"
MsgBox "objDic.Exists(""test""): " & brk & objDic.Exists("test") 'Returns False
wscript.echo "objDic.item(""test""): " & brk & objDic.item("test") 'Shows Blank, Creates the key again with a blank value
wscript.echo "objDic.item(""NeverAdded""): " & brk & objDic.item("NeverAdded") 'Also shows blank, does not return an error
MsgBox "objDic.Exists(""test""): " & brk & objDic.Exists("test") 'Returns True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28853 次 |
| 最近记录: |