/optionexplicit

 

Updated: July 20, 2015

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

Causes the compiler to report errors if variables are not declared before they are used.

/optionexplicit[+ | -]  

+ | -
Optional. Specify /optionexplicit+ to require explicit declaration of variables. The /optionexplicit+ option is the default and is the same as /optionexplicit. The /optionexplicit- option enables implicit declaration of variables.

If the source code file contains an Option Explicit Statement, the statement overrides the /optionexplicit command-line compiler setting.

To set /optionexplicit in the Visual Studio IDE

  1. Have a project selected in Solution Explorer. On the Project menu, click Properties. For more information, see Introduction to the Project Designer.

  2. Click the Compile tab.

  3. Modify the value in the Option Explicit box.

The following code compiles when /optionexplicit- is used.

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

Visual Basic Command-Line Compiler
/optioncompare
/optionstrict
/optioninfer
Sample Compilation Command Lines
Option Explicit Statement
Visual Basic Defaults, Projects, Options Dialog Box

Show: