A bit of a trivial question, but it got my interest.
I often edit my code on the fly, or in other words, when in debug mode. I do this so I can quickly check the edits I have made for performance.
When in debug mode, one can neither remove nor alter Dim
statements without countering the warning message:
This action will reset your project, proceed anyway?
I assume this is due to the compiler having stored variables in the memory in a manner specific to their data types, something which presumably can't be altered while the code is 'running'.
I have noticed, however, that adding a declaration in break mode can be done without any issues. Trying to remove or edit this line then once again throws the warning message.
Why is it possible to add but not to remove/edit declarations in break mode?
I strongly assume that the VBA runtime prevents you from modifying existing entries in the symbol table. Consider you have done something like
Dim i as Integer
i = 3
Debug.print i
You set a breakpoint to the Print
-statement and change the type of i to String
- what should the runtime do with the content of i
? Implicitly convert it to a String? And what should happen if a conversion is not possible?
Adding a new entry into the symbol table doesn't do any harm because it doesn't modify anything that was done previously, so the runtime allows you to do so.
Btw: If you remove Option Explicit
(I know you & me never do this...) and assign a value to an (undeclared) variable: This variable is now put into the symbol table and if you try to add a Dim
-statement now, you will get the This action will reset...
-message.