Using an uninitialized variable is a common programming error. By design VBA initializes declared variables to appropriate defaults for their types. There is no facility to change this behavior.
How to avoid implicit assignment of values to variables?
Michael Mrva
20
Reputation points
Hi,
I'm using VB in Office 2019 under Windows 10. Is there a statement - like Option Explicit, Option Script etc - to enforce that the Visual-Basic-compiler doesn't assign values to variables by itself, e.g. 0 to an integer variable or False to a Boolean variable that appears on the right side of an assignment, but hadn't got a value by the algorithm before. I'd like to see an error message in this case. How can this be achieved?
Thanks for your help.
Michael