Named Constants


The Visual Basic 6 language provides so many built-in constants that save your time and effort for programming.

The Constants start with the “vb” string, for example, vbRed. And you know about the color constants if you’ve read the previous lessons. The named constants are also known as symbolic constants. They have predefined values defined in the VB language.



See in the Object Browser

The symbolic constants or the named constants belong to the “Constants” module and the enumerated properties. See in the Object Browser. Press F2 to open the Object Browser.

You won’t find all the named constants in this lesson. Only the frequently used ones have been mentioned. Look up in object browser to learn about all of them.



1. The Color constants

These constants belong to the “ColorConstants” enumeration. [Search “ColorConstants” in the Object Browser]
vbBlack
vbBlue
vbCyan
vbGreen
vbMagenta
vbRed
vbWhite
vbYellow

These color constants have their long values, for instance, the vbYellow has the long value 65535. It’s hard to remember the numeric values, while the constants are a lot easier, and the code becomes more readable too.

For code examples about color properties:

Read Lesson 12: Common properties.



2. Alignment constants

vbCenter,
vbLeftJustify
The alignment constants are vbCenter, vbLeftJustify, vbRightJustify.



3. Button constants

vbButtonGraphical,
vbButtonStandard
Button constants include vbButtonGraphical, vbButtonStandard that represent graphical and standard appearance of command button respectively.

Read about:



4. CheckBox constants

vbChecked,
vbUnchecked,
vbGrayed
The constants that relate to the CheckBox control are vbChecked, vbUnchecked and vbGrayed constants that are respectively the checked check value, unchecked check value and grayed check value to express the states of the CheckBox control.

Read about:



5. Constants from the “Constants” module

vbBack: Backspace character, equivalent to Chr(8).
vbCr: Carriage return character without line feed, equivalent to Chr(13).
vbCrLf: Carriage return & line feed combination, Chr(13)+Chr(10).
vbFormFeed: Constant for Form Feed, Chr(12).
vbLf: Constant for line-feed without carriage-return, Chr(10).
vbNewLine: Constant for new line, this is platform specific.
vbNullChar: Single null character, Chr(0).
vbNullString: Constant for null string.
vbObjectError: Constant which indicates that en error is being returned from a Visual Basic object.
vbTab: The Tab key, Chr(9).
vbVerticalTab: Vertical Tab character, Chr(11).



6. FormShow Constants

vbModal: Modal form
vbModeless: Modeless form



7. KeyCode Constants

vbKey0: 0 key
vbkey1: 1 key
vbkey2: 2 key
Constants for 0 to 9 numeric key digits are available, from vbKey0 to vbKey9.
vbkeyA:
vbKeyB:
vbKeyC
vbKeyA to vbKeyZ are available.

vbKeyBack:
vbKeyControl:
vbKeySpace:
Browse through the object browser to know more about the KeyCode constants.



8. MouseButton constants

vbLeftButton: Left mouse button
vbMiddleButton: Middle mouse button
vbRightButtom: Right mouse button



9. QueryUnload constants

The QueryUnload constants are useful when you take a QueryUnload event in your program. The QueryUnload constants are as follows:

vbAppTaskManager: When task manager is closing the application.
vbAppWindows: When current windows session is ending.
vbFormCode: when Unload method is invoked from code.
vbFormControlMenu: When the user is closing the application from the Control menu box, pressing the close button.
vbFormMDIForm: When the MDI parent form is closing while the MDI child form also closes automatically.
vbFormOwner: The owner of the form is closing the application.

For code example related to QueryUnload constants:



10. Shift constants

vbAltMask: Alt key bit mask
vbCtrlMask: Ctrl key bit mask
vbShiftMask: Shift key bit mask

For code examples related to shift constants:



11. System color constants

There are so many system color constants in VB6. Look up in the Object Browser. [Search “SystemColorConstants”]
Only few of them are shown below.
Vb3DFace
Vb3DHighlight
Vb3DLight
Vb3DShadow