Q: Why should I use Option Explicit?

Option Explicit forces you to declare all variables before using them. The main reason to use the OPTION EXPLICIT statement at the top of all modules is to minimize the amount of bugs introduced into your code by misspelling a variable name. Most variants of BASIC (including VB) have the capability to create variables 'on the fly' (without any declarations). This capability can be a double edged sword.

The OPTION EXPLICIT statement causes VB to 'disable' its ability to create variables on the fly. Thus, all variables must be declared using a DIM or REDIM statement. All variables not declared will cause an error when the OPTION EXPLICIT statement is used. This will eliminate bugs caused by a misspelled variable. The option works module-wide, so you can have some modules with and some without this option in your project. Declaring variables on the fly makes all but the most trivial code difficult to debug and maintain.

VB creates Variant type variables by default.

This FAQ could actually be part of a much larger discussion on programming standards, with issues like naming conventions, documenting your code and dealing with errors. As the Focus On Visual Basic series evolves I hope to cover these in more detail. For now, I can’t think of a better source of information than Rod Stephen's Bug Proofing Visual Basic book. You can check it out on the Getting Started Book Store.