> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Careful What You Watch For
- URL: https://nolongerset.com/careful-what-you-watch-for/
- Published: 2020-12-08T23:51:29.000Z
- Updated: 2026-05-08T13:07:28.000Z
- Description: Can the simple act of creating a Watch change the behavior of your code while debugging? Why yes, yes it can.
- Author: Mike Wolfe
- Tags: Hidden Features, Intermediate, #Import 2026-05-20 02:59

I came across this answer on StackOverflow the other day and wanted to bring some attention to it (emphasis mine):

> I had this problem manifest itself while debugging when **I had a watch that attempted to return the "missing" key's item**. Actually, further frustrated debugging had the same problem when I literally had a watch for the \[scriptingdictonaryObject\].exists() condtional); I suggest that **the "missing" key is added because of the watch**. When I removed the watch and instead created a temporary worksheet to copy the array to while running, the unwanted keys were no longer added.

[Dictionary object adding items before .add() is calledI am using a dictionary object from the MS Scripting Runtime library to store a series of arrays and perform operations on the array cells as necessary. There is a for loop to go through the proces...![](https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a)Stack Overflowriddley\_w![](https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=73d79a89bded)](https://stackoverflow.com/a/28374984/154439)

### What's going on here?

One of the "features" of a Dictionary object is that it will *implicitly* create new items without needing to call the .Add method *explicitly*. What's the difference between implicit and explicit?

*Note: Early-bound usage of the Dictionary object requires a reference to the "Microsoft Scripting Runtime" ([](https://nolongerset.com/vba-dictionaries-aka-hash-tables/)[detail](https://nolongerset.com/vba-dictionaries-aka-hash-tables/)s here).*

```vba
Dim MyDict As New Dictionary

'Explicit add
MyDict.Add "KeyA", "Item A"

'Implicit add
MyDict.Item("KeyB") = "Item B"

Debug.Print MyDict("KeyA"); vbNewLine; MyDict("KeyB")
```

Here's the relevant portion of the [documentation](https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/item-property-dictionary-object) regarding *implicit* key creation:

> **Remarks**  
> If *key* is not found when changing an *item*, a new *key* is created with the specified *newitem*. If *key* is not found when attempting to return an existing item, a new *key* is created and its corresponding item is left empty.

### Reproducing the problem

Let's reproduce the problem to see exactly where things go sideways.

#### Expected behavior

Create the following sample routine:

```vba
Sub WatchOut()
    Dim MyDict As Dictionary
    Set MyDict = New Dictionary
    
    Debug.Print "KeyA exists? "; MyDict.Exists("KeyA")
End Sub
```

Run the above routine from the immediate window and it should return False:

```vba
WatchOut
KeyA exists? False
```

#### Add a watch

Now, let's add a watch of the "KeyA" item:

![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2020/12/image-5.png)

Let's try running the **WatchOut** routine again:

```vba
WatchOut
KeyA exists? False
```

So far, so good. Maybe this isn't a problem after all.

#### Step through the code

Let's add a **Stop** statement to force the code to break:

```vba
Sub WatchOut()
    Dim MyDict As Dictionary
    Set MyDict = New Dictionary
    
    Stop
    Debug.Print "KeyA exists? "; MyDict.Exists("KeyA")
End Sub
```

Now, let's try running the **WatchOut** routine:

```vba
WatchOut
KeyA exists? True
```

Aha! The combination of the watch and breaking into the debugger is enough to force the "bug" to appear. I put *bug* in scare quotes because it's actually expected behavior for the debugger. But it's almost certainly unexpected behavior for the developer. 

*(Note that there is nothing special about the *Stop* command that causes this behavior. You can remove the *Stop* line and set a breakpoint on the code and the same behavior will occur.)*

You can see where this sort of thing could cause you to pull your hair out while debugging. Anytime the behavior of your program is different while running normally versus while debugging, you've got the makings of one aggravating debugging session.

### Summary

Steps to reproduce the problem:

1. Create a Watch for a specific Dictionary item
2. Break into the debugger while executing the code

---

This will probably only ever help one or two developers. But it will potentially save those developers *hours* of frustration. And, if I'm being honest, I'm as likely as anyone to be one of those developers ;-).

*Image by [WikiImages](https://pixabay.com/users/wikiimages-1897/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=67535) from [Pixabay](https://pixabay.com/?utm%5Fsource=link-attribution&utm%5Fmedium=referral&utm%5Fcampaign=image&utm%5Fcontent=67535)*