Re: How to use Variable Declaration to narrow down problems
Declaring a variable is the first step to achieve an efficient and error-free code. To use an incorrect type of variable involves consuming more memory and processing time than the necessary.
Variables can be declared in two ways: Implicitly and Explicitly. Unless Option Explicit, is indicated all the variables of the module are implicit, that is, they do not have a defined scope (private, public, static) and they are of the Variant type, (they are not associated to an specific type: numeric, text, date, etc.)
Using implicit variables may lead to run time errors: suppose that in a part of the process variable XYZ = "123" is declared and then in other part of the same process a reference is erroneously made to the same variable like XZY = "456". This will create a new variable rather than changing its value without any warning and as a result, an execution error occurs.
In addition, the "Variant" type require more space in the memory. For example, to store an integer in a Variant type 128 bits are needed while storing the same value in an integer will only need 16 bits. However, there are occasions in which this type of variables should be used: the most common example is to assign a null value to a variable, only “Variant” types accept null values.
Practically the only advantage of using implicit variables is that it allows the elimination of a few code lines.
In short, the variables must be explicitly declared. Perhaps the only valid scenario for the implicit variables is during the development stage while designing a process.