Permalink
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (62 sloc) 2.7 KB
title ms.date ms.prod ms.reviewer ms.suite ms.technology ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author translation.priority.ht
/optionexplicit
2015-07-20
.net
devlang-visual-basic
article
/optionexplicit
VB
/optionexplicit compiler option [Visual Basic]
optionexplicit compiler option [Visual Basic]
-optionexplicit compiler option [Visual Basic]
5d296ab3-bafe-4c4d-9887-78f162ed86c7
16
dotnet-bot
dotnetcontent
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

/optionexplicit

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

Syntax

/optionexplicit[+ | -]  

Arguments

+ | -
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.

Remarks

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.

Example

The following code compiles when /optionexplicit- is used.

[!code-vbVbVbalrCompiler#5]

See Also

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