Loading...
Saturday, May 4, 2013

Option Explicit

One of another best practice for MS Access programming is to use Option Explicit. 
Place Option Explicit on the top of each module

For a short summary, we use option explicit to force explicit declaration of all variable.

This little tips will help save your coding and debug time a lot. Place this Option Explicit statement in your visual basic access code, on the top position of your modules, classes. When you define this statement, you will need to declare every variables you use in your code.

What if you don't use this option explicit variable declaration? well, visual basic will then assign variant data type to all of your undeclared variables. You will might have a lot of trouble on the application run time.

With this option statement, when you try to compile your code, MS Access will look for any variable that is used without declaration, and raise an error "variable not defined".

How does this technique help you?
Well, we use Option Explicit :
  1. To force explicit declaration of all variable. 
  2. To avoid incorrectly typing the name of an existing variable. In other word, to prevent incidentally misspelling of variable names.
  3. To avoid confusion in code where the scope of the variable is not clear.
  4. To speeds up the execution of your code. As visual basic knows what data type the variable is, it then reserves only as much memory as it is necessary to store the data.
Here is the example of how we do this.
Option explicit  ' Force explicit variable declaration.
Dim MyVar        ' Declare variable.
MyInt = 10       ' Undeclared variable generates error.
MyVar = 10       ' Declared variable does not generate error.

2 comments:

  1. Top Casino Games like Fruit Party and Immortal Romance - Game Review
    Fruit Party is one of a couple of games that 카지노사이트 are similar to the casinosites excellent arcade versions of the classic casino game Fruit Party arcade version. The top  Rating: 2.5 · ‎Review by Bill White

    ReplyDelete
  2. SEGA Genesis / Mega Drive | Free Multiplayer Online Game
    No download required – 토토사이트 play 예스카지노 online, free and connect your Sega Genesis / Mega Drive This is a classic SEGA Mega Drive online game.

    ReplyDelete

 
TOP