Constants in VB Script

Aneejian · Mar 19, 2017 · 7 mins read.

Constants in VB Script

VB Script has a number of useful constants that you can use in your code. These constants provide a convenient way to use specific values without actually having to remember the value itself. Since constants are already defined in VBScript, you don’t need to explicitly declare them in your code.

Below are the various categories of constants provided in VBScript.


Category Description
Color Constants It defines eight basic colors that can be used in scripting.
Comparison Constants Defines constants used to compare strings.
Date and Time Constants Defines date and time constants used by various date and time functions.
Date Format Constants Defines constants used to format dates and times.
Miscellaneous Constants Defines constants that don’t conveniently fit into any other category.
MsgBox Constants Defines constants used in the MsgBox function to describe button visibility, labeling, behavior, and return values.
String Constants Defines a variety of non-printable characters used in string manipulation.
Tristate Constants Defines constants used with functions that format numbers.
VarType Constants Defines the various Variant subtypes.

Color Constants

Constant Value Description
vbBlack &h00 Black
vbRed &hFF Red
vbGreen &hFF00 Green
vbYellow &hFFFF Yellow
vbBlue &hFF0000 Blue
vbMagenta &hFF00FF Magenta
vbCyan &hFFFF00 Cyan
vbWhite &hFFFFFF White

Comparison Constants

Constant Value Description
vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Perform a textual comparison.

Date and Time Constants

Constant Value Description
vbSunday 1 Sunday
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
vbUseSystemDayOfWeek 0 Use the day of the week specified in your system settings for the first day of the week.
vbFirstJan1 1 Use the week in which January 1 occurs (default).
vbFirstFourDays 2 Use the first week that has at least four days in the new year.
vbFirstFullWeek 3 Use the first full week of the year.

Date Format Constants

Constant Value Description
vbGeneralDate 0 Display date and/or time. For real numbers, display a date and time. If there is no fractional part, display only a date. If there is no integer part, display time only. Date and time display is determined by your system settings.
vbLongDate 1 Display a date using the long date format specified in your computer’s regional settings.
vbShortDate 2 Display a date using the short date format specified in your computer’s regional settings.
vbLongTime 3 Display a time using the long time format specified in your computer’s regional settings.
vbShortTime 4 Display a time using the short time format specified in your computer’s regional settings.

Miscellaneous Constants

Constant Value Description
vbObjectError -2147221504 User-defined error numbers should be greater than this value, for example, Err.Raise Number = vbObjectError + 1000

MsgBox Constants

The following constants are used with the MsgBox function to identify what buttons and icons appear on a message box and which button is the default. In addition, the modality of the MsgBox can be specified. Since these constants are built into VBScript, you don’t have to define them before using them. Use them anywhere in your code to represent the values shown for each.

Constant Value Description
vbOKOnly 0 Display OK button only.
vbOKCancel 1 Display OK and Cancel buttons.
vbAbortRetryIgnore 2 Display Abort, Retry and Ignore buttons.
vbYesNoCancel 3 Display Yes, No, and Cancel buttons.
vbYesNo 4 Display Yes and No buttons.
vbRetryCancel 5 Display Retry and Cancel buttons.
vbCritical 16 Display Critical Message icon.
vbQuestion 32 Display Warning Query icon.
vbExclamation 48 Display Warning Message icon.
vbInformation 64 Display Information Message icon.
vbDefaultButton1 0 The first button is the default.
vbDefaultButton2 256 Second button is the default.
vbDefaultButton3 512 The third button is the default.
vbDefaultButton4 768 Fourth button is the default.
vbApplicationModal 0 Application modal. The user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal. On Win16 systems, all applications are suspended until the user responds to the message box. On Win32 systems, this constant provides an application modal message box that always remains on top of any other programs you may have running.

MsgBox - Identify Buttons

The following constants are used with the MsgBox function to identify which button a user has selected. These constants are only available when your project has an explicit reference to the appropriate type library containing these constant definitions. For VBScript, you must explicitly declare these constants in your code.

Constant Value Description
vbOK 1 OK button was clicked.
vbCancel 2 Cancel button was clicked.
vbAbort 3 Abort button was clicked.
vbRetry 4 Retry button was clicked.
vbIgnore 5 Ignore button was clicked.
vbYes 6 Yes button was clicked.
vbNo 7 No button was clicked.

String Constants

Constant Value Description
vbCr Chr(13) Carriage return.
VbCrLf Chr(13) & Chr(10) Carriage return-linefeed combination.
vbFormFeed Chr(12) Form feed; not useful in Microsoft Windows.
vbLf Chr(10) Line feed.
vbNewLine Chr(13) & Chr(10) or Chr(10) Platform-specific newline character; whatever is appropriate for the platform.
vbNullChar Chr(0) Character having the value 0.
vbNullString String having value 0 Not the same as a zero-length string (“”); used for calling external procedures.
vbTab Chr(9) Horizontal tab.
vbVerticalTab Chr(11) Vertical tab; not useful in Microsoft Windows.

Tristate Constants

Constant Value Description
vbUseDefault -2 Use default from computer’s regional settings.
vbTrue -1 True
vbFalse 0 False

VarType Constants

Constant Value Description
vbEmpty 0 Uninitialized (default)
vbNull 1 Contains no valid data
vbInteger 2 Integer subtype
vbLong 3 Long subtype
vbSingle 4 Single subtype
vbDouble 5 Double subtype
vbCurrency 6 Currency subtype
vbDate 7 Date subtype
vbString 8 String subtype
vbObject 9 Object
vbError 10 Error subtype
vbBoolean 11 Boolean subtype
vbVariant 12 Variant (used only for arrays of variants)
vbDataObject 13 Data access object
vbDecimal 14 Decimal subtype
vbByte 17 Byte subtype
vbArray 8192 Array