The dictionary is filled with an empty element after checking the position of the dictionary in the viewport

Recently, I came across a rather strange dictionary behavior.

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

The iDict output consists of 7 elements: Taken from the window of local residents But whenever I add a clock: It adds an empty element to the dictionary: Why does adding a clock expression create an empty dictionary in the dictionary?
Add View Window

Taken from the watch window

+1
source share
1 answer

If you study the entry in the dictionary with the key "What???", then, naturally, an entry will be created in the dictionary to show you this entry.

If you just want to check if the recording exists, follow the clock iDict.Exists("What???").

Adding hours View window

Adding a clock does not affect the following code differently:

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

Dictionary , x :

enter image description here

, x 5 10 Debug.Print.

+3

Source: https://habr.com/ru/post/1693993/


All Articles