Thank you for your support!    
UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Edit Discussion
> Option Explicit    

Option Explicit
Image:NotifCleanup.gif This page requires general cleanup in formatting or text to better fit the UA Wiki Guidelines

Option Explicit is a compiler directive. Using Option Explicit enables the compiler to catch misspellings so users do not have as many surprises at run-time.

It is always a good idea to DIMension your variables before you use them -- and best to be a specific data type if it applies and you do not need to store a null (as only a variant can do)

Dim nPartID As Long

to force variable declaration (which is HIGHLY recommended), put this at the top of your module:

Option Explicit

from the VBE window, you can do --> Tools, Options... and check "Require Variable Declaration" so that any new modules created will have the Option Explicit statement automatically at the top. Modules that have already been created will not be changed.

Another handy thing in declaring variables is that, if Access recognizes the variable name you have typed as a variable that has been DIMensioned, it will change the case for you after you move off the line -- so it is good to put one or more uppercase characters in variable names and type everything in lower case

npartid --> will be corrected to --> nPartID
as soon as you move off the line. Nice because you have an indicator that you typed the name correctly! And if you didn't, the compiler will catch it since all variables must be declared when using Option Explicit.

If you declare a variable but do not specify its type, Access will assume it is a variant -- this takes extra space. Declared variable access is slightly faster than undeclared variable access.

When you use a Variant type, which can hold any type of data -- numbers, strings, arrays, etc – you have flexibility to be lazy, and that also degrades performance. In order to work with a Variant, Access has to figure out what type of data it has, keep track of that in another place, as well as perform conversions, whereas if you specify a data type, Visual Basic can compile the code more efficiently.

Another reason to specifically declare the data type is so that the AutoComplete feature of Visual Basic can list only things that apply specifically to that data type.

other compiler directives:

Option Compare Database
This uses the default database comparison (in most locals this is the same as using Option Compare Text)
Option Compare Text
this means that "ABC" = "abc" so case is ignored when string comparisons are made
Option Compare Binary
Comparisons are made based on the binary representation of a character, therefore "ABC" does NOT equal "abc"


Option Base 1

This statement sets the default lower limit index of an array to 1 instead of the default of 0 (zero).

There are more compiler directives, but these are the most common.

MODULE INFORMATION

this thread has some good reference information:

Code Behind Form (CBF)
http://www.utteraccess.com/forum/enter-live-mail-addre-t1437894.html&mode=flat#entry1438041

Edit Discussion
This page was last modified 17:03, 11 February 2012.  This page has been accessed 2,469 times.  Disclaimers