gpt4 book ai didi

dictionary - VBScript Dictionary Exists 方法总是返回 True

转载 作者:行者123 更新时间:2023-12-03 09:56:43 26 4
gpt4 key购买 nike

我究竟做错了什么?根据我的测试,objDic.exists 永远不会给出 False!

    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 -- ""

最佳答案

就我所知,字典对象键是通过仅仅引用它就好像它确实存在而创建的。

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

关于dictionary - VBScript Dictionary Exists 方法总是返回 True,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10475669/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com