VB6 Tutorial 49: Named Constants

Posted On 2018-05-22 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner
Tags: VB6 Tutorials 
Views: 19


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

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.

QuickHint:

You can use the Object Browser to find the full list of named constants available in Visual Basic. Press F2 in the IDE to open the object browser.

This lesson will only cover more commonly used items. However, you'll notice that in the Object Browser, there are many, many more available to help you save time!

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, see VB6 Tutorial 09: Common Properties 1 of 3.

Alignment constants

The alignment constants are vbCenter, vbLeftJustify, vbRightJustify.

Button constants

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

CheckBox constants

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.

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 an error is being returned from a Visual Basic object.
  • vbTab: The Tab key, Chr(9).
  • vbVerticalTab: Vertical Tab character, Chr(11).

FormShow Constants

  • vbModal: Modal form
  • vbModeless: Modeless form

MouseButton constants

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

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.

Shift constants

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

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

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

has posted a total of 101 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.159.91.117

Before you can post, you need to prove you are human. If you log in, this test goes away.


Code Links