Advantages of Explicit Variable Declaration

Explicit variable declaration:

• Speeds up the execution of your procedure. Since Visual Basic knows the data type, it reserves only as much memory as is absolutely necessary to store the data.

• Makes your code easier to read and understand because all the variables are listed at the very beginning of the procedure.

• Helps prevent errors caused by misspelling a variable name. Visual Basic automatically corrects the variable name based on the spelling used in the variable declaration.

If you don't let Visual Basic know about the variable prior to using it, you are implicitly telling VBA that you want to create this variable. Implicit variables are automatically assigned the Variant data type (see Table 3-1). Although implicit variable declaration is convenient (it allows you to create variables on the fly and assign values to them without knowing in advance the data type of the values being assigned), it can cause several problems.

Introduction to Access 2003 VBA Programming

0 0

Post a comment