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

/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 allows implicit declaration of variables.

To set /optionexplicit in the Visual Studio integrated development environment

  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.

To set /optionexplicit programmatically

The following code compiles when /optionexplicit- is used.

Module Module1
    Sub Main()
        i = 99
    End Sub
End Module

Community Additions