How to use Variable Declaration to narrow down problems

TJPoorman

Registered User.
Local time
Today, 11:32
Joined
Jul 23, 2013
Messages
402
In order to help us to narrow down some of your problems please turn on variable declaration in your VBA project. Please see the attached pictures on how to turn this on.

Thank you
 

Attachments

  • 1.png
    1.png
    24.3 KB · Views: 1,913
  • 2.PNG
    2.PNG
    24.2 KB · Views: 1,833
What is the difference between this and 'Option Explicit' ?
 
What is the difference between this and 'Option Explicit' ?


The setting automatically adds Option Explicit to all new modules.
 
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.
 

Users who are viewing this thread

Back
Top Bottom