home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


The key Visual Basic techniques used to break AppointmentBook into manageable pieces are outlined in the following list. The rest of this chapter describes them in detail.


FIGURE 3.7  AppointmentBook’s about dialog.

•  Using Bit Masks. AppointmentBook uses bit masks to represent changes in the data. This section explains how a program can use bit masks to describe several Boolean or on/off features in a single integer or long integer.
•  Using the MVC Paradigm. The model/view/controller (MVC) paradigm uses a set of simple class objects to represent a complex assortment of interactions. This section explains MVC and how it is used by AppointmentBook.
•  Creating Fonts. To save screen space, AppointmentBook displays the names of the months in the month area using a rotated font. This section describes the CreateFont API function used to create rotated text.
•  Scrolling Large Amounts of Data. AppointmentBook’s month area displays data for the previous, current, and next years. This section explains techniques for managing very large amounts of data so AppointmentBook can scroll through almost 1100 days’ worth of data.
•  Setting Alarms. Visual Basic’s timer control is useful for managing periodic events that occur fairly frequently (more than once a minute or so). This section tells how an application can wait for isolated events that may occur far in the future.
•  Creating Nonrectangular Forms. AppointmentBook’s splash screen and about dialog use a distinctive, nonrectangular form. This section explains how an application can use irregularly shaped forms to add extra interest to an otherwise routine function.
•  Presenting Help. AppointmentBook provides help using HTML documents. This section describes the program’s help documents and its customized help browsing system.

Using Bit Masks

Computers store any data item as a series of bits, each of which can have the value zero or one. For example, in Visual Basic an integer is represented by a series of 16 bits; a long integer is represented by 32 bits.

A program can use the bits in one of these data types to record Boolean or on/off features. A feature is present, true, or on if the corresponding bit in the integer is a one. It is absent, false, or off if the bit is a zero. The series of bits 00...011 would indicate that only the last two features were present. A program can use an integer if it will need no more than 16 features and a long integer if it needs up to 32 features.

A bit mask is a value that represents a specific collection of values. Often a mask represents a single feature. For instance, the value 00...001 represents a value with only the last feature present.

The following sections explain how to use bit masks and how they are used in AppointmentBook. If you are already familiar with bit masks, you may want to skip to the section titled “Bit Masks in AppointmentBook.”

Defining Bit Masks

The following code defines bit mask values that describe specific vehicle features:

Public Const VEH_4WD = &H1            ‘ Four-wheel drive.
Public Const VEH_ABS = &H2            ‘ Anti-lock brakes.
Public Const VEH_Airbag1 = &H4        ‘ Driver-side airbag.
Public Const VEH_Airbag2 = &H8        ‘ Passenger airbag.
Public Const VEH_Automatic = &H10     ‘ Automatic transmission.
Public Const VEH_PowerSteering = &H20 ‘ Power steering.
Public Const VEH_PowerBrakes = &H40   ‘ Power brakes.
Public Const VEH_PowerWindows = &H80  ‘ Power windows.
Public Const VEH_RemoteKeyless = &H100‘ Remote keyless entry.
    :

This code illustrates several important points. First, each mask’s name begins with “VEH_.” This makes it easy to remember that the values represent vehicle features. Defining the masks using names such as “ABS”” and “4WD” without the “VEH_” prefix would make other parts of the code that use the masks harder to understand.

The definition of each mask includes a comment that indicates exactly what the mask means. The mask name itself should be as meaningful as possible, but it is still a good idea to place comments near the definitions. Later, if it is unclear what VEH_DOHC means, a quick search for the string “VEH_DOHC =” will locate the comment. In this example, it would also be best to change the name to something less cryptic, such as “VEH_DualOverheadCam.”

Finally, the values are defined using hexadecimal. This makes it easy to keep track of the next integer value that has only a single bit set. In base 10, the numbers with a single bit set are 1, 2, 4, 8, 16, 32, 64, .... In hexadecimal, the same numbers are 1, 2, 4, 8, 10, 20, 40, .... The sequence consists of the digits 1, 2, 4, and 8 followed by different numbers of zeros. This simple pattern makes it easy to generate as many hexadecimal values as necessary.

Alternatively, mask values can be specified in terms of the preceding values. A mask value with a single bit set multiplied by two gives the next value with a single bit set. The following code defines the first few vehicle codes using this method:

Public Const VEH_4WD = 1                 ‘ Four-wheel drive.
Public Const VEH_ABS = VEH_4WD * 2       ‘ Anti-lock brakes.
Public Const VEH_Airbag1 = VEH_ABS * 2   ‘ Driver-side airbag.
Public Const VEH_Airbag2 = VEH_Airbag2 * 2      ‘ Passenger airbag.
    :

This method has the advantage that it requires few changes to move items around in the list. The following code shows the same list with the new value VEH_Automatic inserted in the middle. Only the new line and the following line required changes.

Public Const VEH_4WD = 1                  ‘ Four-wheel drive.
Public Const VEH_ABS = VEH_4WD * 2        ‘ Anti-lock brakes.
Public Const VEH_Automatic = VEH_ABS * 2  ‘ Automatic transmission.
Public Const VEH_Airbag1 = VEH_Automatic * 2    ‘ Driver-side airbag.
Public Const VEH_Airbag2 = VEH_Airbag2 * 2      ‘ Passenger airbag.
    :


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.