More About Programming
More About Programming
introduces a variety of features that make it easier for you to create powerful, flexible
applications.
For example, you can load multiple projects into a single session of the programming
environment, work with Windows registry settings, or selectively compile certain
parts of your program.
Beyond the fundamentals of writing code, Visual Basic provides a variety of language
elements that enhance your code. The last three topics in this chapter discuss three of
these language elements: user-defined types, enumerated constants, and collections.
Note If you are using the Control Creation Edition of Visual Basic, some of the material
covered in this document may not be applicable. With the full editions of Visual Basic you have
the ability to create applications, ActiveX documents, and other types of components. Although
some of the terminology may relate to application specific objects such as forms, in most
cases the underlying concepts also apply to ActiveX control creation.
1
Contents
· Working with Resource Files
· Working with Templates
· Creating Your Own Data Types
· Using Enumerations to Work with Sets of Constants
· Using Collections as an Alternative to Arrays
2
—1
—2
1
When you open a template, Visual Basic displays the object with placeholders that
you can customize. For example, to create an About dialog box, open the About
Dialog template and replace the Application Title, Version, and App Description
placeholders with information specific to your application.
2
To create your own template, save the object that you want to use as a template, then
copy it to the appropriate subdirectory of the Visual Basic Template directory. For
—3
—4
—5
—6
Type SystemInfo
CPU As Variant
Memory As Long
DiskDrives(26) As DriveInfo
Cost As Currency
PurchaseDate As Variant
End Type
—7
—8
—9
4
Because the constant Sunday also evaluates to 0, Visual Basic also displays the
message box if you replace "Saturday" with "Sunday" in the second line of the
example:
MyDay = Sunday ' Sunday also evaluates to 0.
31
Note Although you normally assign only enumeration constant values to a variable declared
as an enumeration type, you can assign any long integer value to the variable. Visual Basic will
not generate an error if you assign a value to the variable that isn't associated with one of the
enumeration's constants.
32
For More Information See "Providing Named Constants for Your Component" in
"General Principals of Component Design."
33
—10
—11