Constants in VB Script

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

Categories

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

Color Constants

ConstantValueDescription
vbBlack&h00Black
vbRed&hFFRed
vbGreen&hFF00Green
vbYellow&hFFFFYellow
vbBlue&hFF0000Blue
vbMagenta&hFF00FFMagenta
vbCyan&hFFFF00Cyan
vbWhite&hFFFFFFWhite

Comparison Constants

ConstantValueDescription
vbBinaryCompare0Perform a binary comparison.
vbTextCompare1Perform a textual comparison.

Date and Time Constants

ConstantValueDescription
vbSunday1Sunday
vbMonday2Monday
vbTuesday3Tuesday
vbWednesday4Wednesday
vbThursday5Thursday
vbFriday6Friday
vbSaturday7Saturday
vbUseSystemDayOfWeek0Use the day of the week specified in your system settings for the first day of the week.
vbFirstJan11Use the week in which January 1 occurs (default).
vbFirstFourDays2Use the first week that has at least four days in the new year.
vbFirstFullWeek3Use the first full week of the year.

Date Format Constants

ConstantValueDescription
vbGeneralDate0Display 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.
vbLongDate1Display a date using the long date format specified in your computer’s regional settings.
vbShortDate2Display a date using the short date format specified in your computer’s regional settings.
vbLongTime3Display a time using the long time format specified in your computer’s regional settings.
vbShortTime4Display a time using the short time format specified in your computer’s regional settings.

Miscellaneous Constants

ConstantValueDescription
vbObjectError-2147221504User-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.

ConstantValueDescription
vbOKOnly0Display OK button only.
vbOKCancel1Display OK and Cancel buttons.
vbAbortRetryIgnore2Display Abort, Retry and Ignore buttons.
vbYesNoCancel3Display Yes, No, and Cancel buttons.
vbYesNo4Display Yes and No buttons.
vbRetryCancel5Display Retry and Cancel buttons.
vbCritical16Display Critical Message icon.
vbQuestion32Display Warning Query icon.
vbExclamation48Display Warning Message icon.
vbInformation64Display Information Message icon.
vbDefaultButton10The first button is the default.
vbDefaultButton2256Second button is the default.
vbDefaultButton3512The third button is the default.
vbDefaultButton4768Fourth button is the default.
vbApplicationModal0Application modal. The user must respond to the message box before continuing work in the current application.
vbSystemModal4096System 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.

ConstantValueDescription
vbOK1OK button was clicked.
vbCancel2Cancel button was clicked.
vbAbort3Abort button was clicked.
vbRetry4Retry button was clicked.
vbIgnore5Ignore button was clicked.
vbYes6Yes button was clicked.
vbNo7No button was clicked.

String Constants

ConstantValueDescription
vbCrChr(13)Carriage return.
VbCrLfChr(13) & Chr(10)Carriage return-linefeed combination.
vbFormFeedChr(12)Form feed; not useful in Microsoft Windows.
vbLfChr(10)Line feed.
vbNewLineChr(13) & Chr(10) or Chr(10)Platform-specific newline character; whatever is appropriate for the platform.
vbNullCharChr(0)Character having the value 0.
vbNullStringString having value 0Not the same as a zero-length string (""); used for calling external procedures.
vbTabChr(9)Horizontal tab.
vbVerticalTabChr(11)Vertical tab; not useful in Microsoft Windows.

Tristate Constants

ConstantValueDescription
vbUseDefault-2Use default from computer’s regional settings.
vbTrue-1True
vbFalse0False

VarType Constants

ConstantValueDescription
vbEmpty0Uninitialized (default)
vbNull1Contains no valid data
vbInteger2Integer subtype
vbLong3Long subtype
vbSingle4Single subtype
vbDouble5Double subtype
vbCurrency6Currency subtype
vbDate7Date subtype
vbString8String subtype
vbObject9Object
vbError10Error subtype
vbBoolean11Boolean subtype
vbVariant12Variant (used only for arrays of variants)
vbDataObject13Data access object
vbDecimal14Decimal subtype
vbByte17Byte subtype
vbArray8192Array