Export (0) Print
Expand All

/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+, which is the same as /optionexplicit, is the default. /optionexplicit- allows implicit declaration of variables.

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

  • See OptionExplicit Property.

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 | Option Explicit Statement

Show:
© 2014 Microsoft