Constants and Enumerations (Visual Basic)


Updated: July 20, 2015

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

Visual Basic supplies a number of predefined constants and enumerations for developers. Constants store values that remain constant throughout the execution of an application. Enumerations provide a convenient way to work with sets of related constants, and to associate constant values with names.

Conditional Compilation Constants

The following table lists the predefined constants available for conditional compilation.

CONFIGA string that corresponds to the current setting of the Active Solution Configuration box in the Configuration Manager.
DEBUGA Boolean value that can be set in the Project Properties dialog box. By default, the Debug configuration for a project defines DEBUG. When DEBUG is defined, Debug class methods generate output to the Output window. When it is not defined, Debug class methods are not compiled and no Debug output is generated.
TARGETA string representing the output type for the project or the setting of the command-line /target option. The possible values of TARGET are:

- "winexe" for a Windows application.
- "exe" for a console application.
- "library" for a class library.
- "module" for a module.
- The /target option may be set in the Visual Studio integrated development environment. For more information, see /target (Visual Basic).
TRACEA Boolean value that can be set in the Project Properties dialog box. By default, all configurations for a project define TRACE. When TRACE is defined, Trace class methods generate output to the Output window. When it is not defined, Trace class methods are not compiled and no Trace output is generated.
VBC_VERA number representing the Visual Basic version, in major.minor format. The version number for Visual Basic 2005 is 8.0.

Print and Display Constants

When you call print and display functions, you can use the following constants in your code in place of the actual values.

vbCrLfCarriage return/linefeed character combination.
vbCrCarriage return character.
vbLfLinefeed character.
vbNewLineNewline character.
vbNullCharNull character.
vbNullStringNot the same as a zero-length string (""); used for calling external procedures.
vbObjectErrorError number. User-defined error numbers should be greater than this value. For example:

 Err.Raise(Number) = vbObjectError + 1000
vbTabTab character.
vbBackBackspace character.
vbFormFeedNot used in Microsoft Windows.
vbVerticalTabNot useful in Microsoft Windows.

The following table lists and describes the enumerations provided by Visual Basic.

AppWinStyleIndicates the window style to use for the invoked program when calling the Shell function.
AudioPlayModeIndicates how to play sounds when calling audio methods.
BuiltInRoleIndicates the type of role to check when calling the IsInRole method.
CallTypeIndicates the type of procedure being invoked when calling the CallByName function.
CompareMethodIndicates how to compare strings when calling comparison functions.
DateFormatIndicates how to display dates when calling the FormatDateTime function.
DateIntervalIndicates how to determine and format date intervals when calling date-related functions.
DeleteDirectoryOptionSpecifies what should be done when a directory that is to be deleted contains files or directories.
DueDateIndicates when payments are due when calling financial methods.
FieldTypeIndicates whether text fields are delimited or fixed-width.
FileAttributeIndicates the file attributes to use when calling file-access functions.
FirstDayOfWeekIndicates the first day of the week to use when calling date-related functions.
FirstWeekOfYearIndicates the first week of the year to use when calling date-related functions.
MsgBoxResultIndicates which button was pressed on a message box, returned by the MsgBox function.
MsgBoxStyleIndicates which buttons to display when calling the MsgBox function.
OpenAccessIndicates how to open a file when calling file-access functions.
OpenModeIndicates how to open a file when calling file-access functions.
OpenShareIndicates how to open a file when calling file-access functions.
RecycleOptionSpecifies whether a file should be deleted permanently or placed in the Recycle Bin.
SearchOptionSpecifies whether to search all or only top-level directories.
TriStateIndicates a Boolean value or whether the default should be used when calling number-formatting functions.
UICancelOptionSpecifies what should be done if the user clicks Cancel during an operation.
UIOptionSpecifies whether or not to show a progress dialog when copying, deleting, or moving files or directories.
VariantTypeIndicates the type of a variant object, returned by the VarType function.
VbStrConvIndicates which type of conversion to perform when calling the StrConv function.

Visual Basic Language Reference
Visual Basic
Constants Overview
Enumerations Overview