Ant*_*ert 3 excel vba excel-vba
最近我遇到了一个相当奇怪的字典行为.
Sub DictTest()
Dim iDict As Object
Dim i As Integer
Dim strArr() As String
Set iDict = CreateObject("Scripting.Dictionary")
strArr = Split("Why does this happen ? Why does this happen over and over ?", " ")
For i = LBound(strArr) To UBound(strArr)
iDict(strArr(i)) = strArr(i)
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
输出是iDict,填充了7个项目:
但每当我添加手表:

它将一个空项添加到字典中:

为什么添加监视表达式会在字典中创建一个空项?
如果您使用键检查字典中的条目,"What???"则自然必须在字典中创建条目才能显示该条目.
如果您只想检查是否存在条目,请执行监视iDict.Exists("What???").
添加手表与以下代码的操作没有区别:
Sub DictTest()
Dim iDict As Object
Dim i As Integer
Dim strArr() As String
Set iDict = CreateObject("Scripting.Dictionary")
strArr = Split("Why does this happen ? Why does this happen over and over ?", " ")
For i = LBound(strArr) To UBound(strArr)
iDict(strArr(i)) = strArr(i)
Next
MsgBox "The value of the 'What???' entry in iDict is '" & iDict("What???") & "'"
End Sub
Run Code Online (Sandbox Code Playgroud)
更改Dictionary对象的内容与使用Watch Window更改x以下情况中的值没有什么不同:
在上面的代码中,我使用监视窗口编辑的价值x来自5于10之前的Debug.Print声明.
| 归档时间: |
|
| 查看次数: |
590 次 |
| 最近记录: |