How to avoid implicit assignment of values to variables?

Michael Mrva 20 Reputation points
2023-09-30T07:43:05.2766667+00:00

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

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,449 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 47,951 Reputation points
    2023-09-30T11:52:04.9066667+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.