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


Part One
Application Basics

Chapters 1, 2, and 3 demonstrate many important techniques that are required by any truly professional application. Many of these techniques are used throughout the rest of the book.

The first application, ExpenseReporter, allows the user to create, modify, and print trip-related expense reports using a single main form. In addition to features needed by any single-form application, ExpenseReporter implements a wide variety of sophisticated features—features such as recent file lists, printer setup, print previewing, and context-sensitive help give any application a polished look.

In fact, ExpenseReporter demonstrates so many techniques that they do not all fit in a single chapter. For that reason, ExpenseReporter is covered in both Chapter 1 and Chapter 2. Chapter 1 explains application fundamentals including scrolling areas, control arrangement, dynamic controls, field navigation, single document interface (SDI) issues, loading and saving files, menu design, and recent file lists. Chapter 2 discusses the more complicated topics of field- and form-level validation, printing, print preview, help, about dialogs, and splash screens.

Chapter 3 describes the AppointmentBook application, which allows the user to schedule and track appointments. When it is time for an appointment, the program presents a reminder. This application shows how to work with bit masks, use the model/view/controller (MVC) paradigm to manage complex views of data, preview key strokes, create rotated fonts, scroll large amounts of data, set alarms to wait until a specified time, and create nonrectangular forms.

Chapter 1
ExpenseReporter from a User’s Point of View

ExpenseReporter lets the user edit and print trip-related expense reports. This application demonstrates many fundamental techniques used by most high-quality applications. Chapters 1 and 2 describe these techniques in detail.

The first section of this chapter, “Using ExpenseReporter,” describes the ExpenseReporter application from the user’s point-of-view. This section also describes data validation and other features of ExpenseReporter that may be less obvious to users.

The “Key Techniques” section briefly lists important programming methods used by ExpenseReporter and described in Chapter 1; the remaining sections of this chapter describe these techniques in detail. Chapter 2 completes the discussion of ExpenseReporter by describing some of its more advanced features, including the print and preview capabilities, field validation, and help.

Using ExpenseReporter

Before you read about how ExpenseReporter was designed and coded, take a few minutes to run the program and test some of its features. The section, “Using the Compact Disk,” in the Introduction explains how you can load the program’s source files from the compact disk. ExpenseReporter is contained in the Expense.VBP project in the Ch1 directory.

Figure 1.1 shows the running ExpenseReporter application. The following sections describe most of ExpenseReporter’s features from the user’s point-of-view.

Field Validations

ExpenseReporter validates the values entered in many of its fields. For example, ExpenseReporter assumes the user’s name contains only letters, spaces, and periods as in John Q. Public. To help the user enter a correct value in this field, the program will not allow any other characters to be entered. If the user tries to enter an invalid character such as a number or an exclamation mark, the program beeps and ignores the character.

Similarly, ExpenseReporter assumes that department and project fields are numeric. The user can enter only digits in those fields.


FIGURE 1.1  ExpenseReporter.

Understanding how the program handles date fields is a little trickier. The program must allow partial dates such as 1/22/ while the user is in the middle of entering a date value. This is not a valid date, but the program cannot tell ahead of time whether the user will enter more characters to make this a complete date.

ExpenseReporter does prevent the user from entering month numbers greater than 12 and day numbers greater than 31—those numbers are never valid in date fields. As the user types, however, the program does not verify that the complete date entered exists. For example, the user can enter 4/31/1997 even though April never has 31 days.

Only when the program is certain the user has finished entering data on the form does it verify that the entered dates exist. When the user selects the File menu’s Print or Print Preview command, the program assumes the values entered are final. It then verifies that the dates exist and checks that the dates are complete rather than partial dates such as 1/22/. If a field contains an invalid value, the program presents a warning message and asks the user to correct the value.

The Category combo boxes in the expense rows contain a list of expense categories. These include Travel, Meal, Hotel, and Misc. The list also includes a blank option that is used in blank rows.

The values allowed by the Description combo boxes are related to the values selected in the corresponding Category box. For example, when an expense row’s Category is Meal, its Description choices are Breakfast, Lunch, and Dinner. When a row’s Category is Misc, its Description can be Gasoline, Parking, and Toll. When the user changes a Category value, the choices available for the corresponding Description field are changed appropriately. The user can also type directly into the Description field if an expense does not fit one of the predefined descriptions.

When the user enters a value in any Amount field, ExpenseReporter automatically computes the total of all the expenses. It then subtracts any values entered in the Prepaid and Advance fields and displays the amount due to the employee or to the company.

Managing Controls

ExpenseReporter cannot know ahead of time how many expense rows the user will need. To be certain it provides enough, the program always ensures that there is at least one empty row. As soon as the user enters data into the last empty row, the program creates another. There is always a place to enter more expense information without forcing the user to ask for more rows using a menu item or command button.

If the user creates so many expense rows that they cannot all fit on the screen, a vertical scroll bar appears. The scroll bar allows the user to move through the data to see all of the expense rows. If the user resizes the form so all of the rows fit, the scroll bar disappears until it is needed again.

ExpenseReporter also enhances the standard Windows navigation features to allow the user to move more conveniently through the form’s fields. When the input cursor is in a Date, Location, or Amount field, the user can press the up and down arrow keys to move to the previous or next expense row. If the user moves to a row that is not visible, the scrolling area adjusts so the user can see the row.

Print Preview and Printing

To see what an expense report would look like printed, the user can select the Print Preview command from the application’s File menu. At that point ExpenseReporter performs form-level validations. If the user entered any invalid dates such as 4/31/1996 or if a date field contains a partial date such as 1/12/, the application presents a warning message. The program also warns the user if any required fields have been left blank. In ExpenseReporter the Name, ID, Dept, Proj, and start and stop dates are all required.

Before presenting the print preview screen, ExpenseReporter also performs one form-level validation to ensure that the form makes sense overall. The program calculates the total meal and miscellaneous expenses for each day. If any day’s total exceeds the set per-diem allowance of $50, the program warns the user.

Finally, ExpenseReporter also reformats some of the fields. It extends dollar amounts that do not contain two digits after the decimal point. For example, the program converts 12 to 12.00. This alteration makes the amount columns line up nicely and produces a better-looking printout.

Finally, once the main expense form has passed all of the form-level validations, ExpenseReporter presents the print preview screen. Here the user can see approximately what the form will look like when printed. The user can view the form at large scale to see the parts of the printout in detail or at smaller scales to get an idea of how the printout will fit on the page.

Figure 1.2 shows the print preview screen displaying the expense report from Figure 1.1 at large scale. Because the printed form does not fit on the screen at this scale, scroll bars allow the user to view different parts of the form. Figure 1.3 shows the same form previewed at the smallest scale. Even though the text is unreadable, the display does show how the expense report will fit on the printed page.


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.