Visual Basic Compiler Options  

/optionexplicit

Causes the compiler to report errors if variables are not declared prior to use.

/optionexplicit[+ | -]

Arguments

+ | -
Specify /optionexplicit+ to require explicit declaration of variables. /optionexplicit- is the default; /optionexplicit+ is the same as /optionexplicit. Both let you declare variables implicitly.

To set /optionexplicit in the Visual Studio integrated development environment

  1. Open the project's Property Pages dialog box. For details, see <Projectname> Property Pages Dialog Box.
  2. Click the Common Properties folder.
  3. Click the Build property page.
  4. Modify the Option Explicit property.

To set /optionexplicit programmatically

Example

The following code compiles when /optionexplicit- is used:

Module Module1
   Sub Main()
      i = 99
      System.Console.WriteLine(i)
   End Sub
End Module

See Also

Visual Basic Compiler Options | /optionstrict | Sample Compilation Command Lines