Share via


How to: Set Compiler Options (Visual Basic)

The Visual Basic compiler provides several options for checking your code at compile time. Option Explicit determines whether variables must be explicitly declared. Option Strict determines whether explicit narrowing conversions and late binding are allowed. Option Infer enables type inference for member-level (local) variables. Option Compare specifies the method that is used for string comparisons: binary (case-sensitive) or text (case-insensitive).

Note

Setting these options sets the defaults for the project; they can be overridden for files in the project by using the Option Explicit, Option Strict, Option Infer, and Option Compare language statements.

In addition, options are provided for enabling or disabling compiler warnings for several specific conditions. For more information, see How to: Enable or Disable Compiler Warnings (Visual Basic).

Compiler options are set on the Compile page of the Project Designer.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To set Option Explicit

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.

  2. On the Compile tab, in the Option explicit list, select either On or Off.

To set Option Strict

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.

  2. On the Compile tab, in the Option strict list, select either On or Off.

    The (custom) option will appear in this list if you enable the compiler notifications Implicit conversion, Late binding, or Implicit type (see the Warning configurations option below). Changing Option Strict back to On will restore those notifications to their defaults. For more information, see How to: Enable or Disable Compiler Warnings (Visual Basic).

To set Option Compare

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.

  2. On the Compile tab, in the Option compare list, select either Binary or Text.

To set Option Infer

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.

  2. On the Compile tab, in the Option infer list, select either On or Off.

See Also

Tasks

How to: Enable or Disable Compiler Warnings (Visual Basic)

Reference

Option Explicit Statement (Visual Basic)

Option Strict Statement

Option Compare Statement

Option Infer Statement

Compile Page, Project Designer (Visual Basic)

Concepts

Local Type Inference (Visual Basic)

Other Resources

Managing Compilation Properties