据我所知,字典对象键是通过仅引用它来创建的,就好像它确实存在一样。
wscript.echo objDic.Item("test") 'Creates the key whether it exists or not
wscript.echo objDic.Exists("test") 'Will now return true
这里有更多代码,您可以尝试证明/测试我的理论。我通常使用 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