VBScript - The Constants

December 2016



What is a constant?


A constant is a name (usually an easy to remember one), replacing a value (number, string, etc..) that doesn't change. The objective of a constant is to make a your code more readable and secondly to facilitate its maintenance, as itis easier to modify a static value declared at the beginning of your code, than to replace several values located at different locations in your code.

How to define a constant?


It is possible to define constants with the Const statement:
Const size_when_empty       
size_when_empty = 2310       
Const NAME_OF_PROGRAM       
NAME_OF_PROGRAM = "Kioskea"

In the case that the constant can't be distinguished from a variable, there are coding conventions recommending the use of a prefix "vb" for your constant. Thus, the constants above should be conventionally named as follows:
Const size_when_empty       
vbsize_when_empty = 2310       
Const NAME_OF_PROGRAM       
vbNAME_OF_PROGRAM = "Kioskea"

VBScript natively offers a number of constants defined below.

Color constants



ConstantValue
hexadecimal
Description
vbBlack&h00Black
vbRed&hFFRed
vbGreen&hFF00Green
vbYellow&hFFFFYellow
vbBlue&hFF0000Blue
vbMagenta&hFF00FFMagenta
vbCyan&hFFFF00Cyan
vbWhite&hFFFFFFvbWhite

Constant for strings



ConstantValue
hexadecimal
Description
vbCrChr(13)Carriage return.
VbCrLfChr(13) and Chr(10)Carriage return and line feed.
vbFormFeedChr(12)Next page.
vbLfChr(10)New line (Unix system).
vbNewLineChr(13) and Chr(10) or Chr(10)New line (depends on the OS).
vbNullCharChr(0)Null Character (code ASCII 0).
vbNullStringString having value as 0.Not to be confused with an empty string (""). Used when calling external procedures.
vbTabChr(9)Horizontal tab.
vbVerticalTabChr(11)Vertical tab.

Constants for dialog boxes


The MsgBox procedure which allows you to create and manage interactive dialogs box, has a number of arguments to define its appearance and behavior. The constants below are used to define most of these arguments.

The buttons displayed


The constants below define the number and type of buttons displayed in the dialog box:


ConstantValueDescription
vbOKOnly0OK.
vbOKCancel1OK and Cancel.
vbAbortRetryIgnore2Abort, Retry and Ignore.
vbYesNoCancel3Yes, No and Cancel.
vbYesNo4Yes and No.
vbRetryCancel5Retry and Cancel.

Icons


The constants below define the type of icons displayed in the dialog box:


ConstantValueIcone
vbCritical16Critical Message.
vbQuestion32Request message.
vbExclamation48Warning message.
vbInformation64Information message.

Default button


The constants below set the default (selected) button in the dialog box:


ConstantValueIcone
vbDefaultButton10Set first button as default.
vbDefaultButton2256Set second button as default.
vbDefaultButton3512Set third button as default.
vbDefaultButton4768Set fourth button as default.

Modality


The constants below define the modality of the dialog box:



ConstantValueDescription
vbApplicationModal0This is a modal box for the application. This means that a user action on the dialog is necessary to continue executing the script.
vbSystemModal4096This is a modal box for the system. This means that a user action on the dialog is necessary to continue the execution of all applications. On 16-bit system applications are pending until validation by the user, while on 32-bit systems box appears on the top of all applications.

The button types


The constants below define the types of buttons (clicked buttons):


ConstantValueDescription
vbOK1OK.
vbCancel2Cancel.
vbAbort3Abort.
vbRetry4Retry.
vbIgnore5Ignore.
vbYes6Yes.

vbNo
7No.

Constant for data type


The constants below define the types of variables used in VBScript:


Name of constantValueData type
vbEmpty0Uninitialized variable (default)
vbNull1Variable containing invalid data
vbInteger2Integer sub-type
vbLong3Long sub-type
vbSingle4Single Subtype
vbDouble5Double Subtype
vbCurrency6Currency Sub-type
vbDate7Date sub-type
vbString8String sub-type
vbObject9can be any object
vbError10Error sub-type
vbBoolean11Boolean sub-type
vbVariant12Variant
vbDataObject13Data object
vbDecimal14Decimal sub-type
vbByte17Byte sub-type
vbArray8192Array

Keyboard codes


Each key is represented by a sequence of characters surrounded by braces:

KeyCode
BACKSPACE{BACKSPACE}, {BS} ou {BKSP}
BREAK{BREAK}
CAPSLOCK{CAPSLOCK}
DELETE{DELETE} or {DEL}
DOWN ARROW{DOWN}
END{END}
ENTER{ENTER}or ~
ESC{ESC}
HELP{HELP}
HOME{HOME}
INS{INSERT} or {INS}
LEFT ARROW{LEFT}
NUMLOCK{NUMLOCK}
PGDN{PGDN}
PGUP{PGUP}
PRTSC{PRTSC}
RIGHT ARROW{RIGHT}
SCROLLLOCK{SCROLLLOCK}
TAB{TAB}
UP ARROW{UP}
F1{F1}
F2{F2}
F3{F3}
F4{F4}
F5{F5}
F6{F6}
F7{F7}
F8{F8}
F9{F9}
F10{F10}
F11{F11}
F12{F12}
F13{F13}
F15{F15}
F16{F16}
{{{}
{{{}
}{}}
[{[}
]{]}
+{+}
^{^}
%{%}
~{~}

It is possible to specify key combinations using the SHIFT, CTRL, and ALT keys:

KeyCode
MAJ+
CTRL^
ALT%

Original document published CommentcaMarche.net.

Related :

This document entitled « VBScript - The Constants » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.