Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Named Literals

A named literal, also called a named constant, is a special named value that represents a fixed value. Visual Basic comes with several named literals and you'll use many of them in your programs to assign values to controls at runtime.

Consider the drop-down list box that appears when you click a command button's MousePointer property (see Figure 3.8). The MousePointer property requires a value from 0 to 15 (or 99 for a custom value). When you set property values at design time, you simply select from the list, and the descriptions to the right of the numeric values explain what each value is for. When programming, you will be able to assign property values to properties when the user runs the program. Although you can assign 2 to the property value to change the mouse cursor to a crosshair during one part of the running application, your code will be better if you assign the named literal vbCrosshair. Although vbCrosshair is longer to type, you will know what value you assigned when you look at the project later.

03fig08.jpg

Figure 3.8 You can assign a named literal to the MousePointer property.

We're getting slightly ahead of ourselves discussing runtime property values that change inside the code, such as event procedures. Nevertheless, keep named literals in mind as you assign values in the Properties window at design time. The named literals often closely match their Properties window counterparts.

Share ThisShare This

Informit Network