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


Arranging the expense controls in rows and columns creates a new navigation opportunity as well. Using the Tab key the user can move to the right through an expense row. Using Shift-Tab the user can move to the left in a row. ExpenseReporter uses code in the text box event handlers to allow the user to move up and down through the columns by using arrow keys.

In the text box’s KeyUp event handler, ExpenseReporter checks to see if the key pressed is an up or down arrow. If the key is an up arrow and if this field is not in the first expense row, the program uses the SetFocus method to move the cursor to the row above. Similarly, if the key is a down arrow key and the field is not in the last expense row, the program uses SetFocus to move the cursor to the row below. When focus moves to the new field, that field’s GotFocus event handler ensures that the scrolling area is positioned so the field is visible.

The following code shows the KeyUp event handler for the AmountText field. The KeyUp event handlers for the other fields are similar.

Private Sub AmountText_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDown And Index < MaxRow Then
        AmountText(Index + 1).SetFocus
    ElseIf KeyCode = vbKeyUp And Index > 0 Then
        AmountText(Index - 1).SetFocus
    End If
End Sub

The up and down arrow keys have special meaning for list and combo box controls. These keys move the value displayed by the control through the available choices. For example, suppose the choices available in a combo box are Travel and Meal. If the user selects Travel with the mouse and then presses the down arrow key, the control’s value changes to Meal. If the user then press the up arrow key, the value changes back to Travel.

Because the arrow keys have special meanings for these controls, applications should not use a KeyUp event handler to change those meanings. That will prevent the user from moving up and down through these columns using the arrow keys, but it allows the combo boxes to keep their standard arrow key functionality.

Selecting a Document Interface

An application with a single document interface (SDI) allows the user to interact with only one document at a time. Microsoft Paint, which comes with Windows 95 and Windows NT, uses a single document interface. A Microsoft Paint user can open a file and edit the drawing it contains. To open a different file, the user must first close the one that is currently open. If the user tries to open a new file without closing the first file, the program closes it automatically. If changes have been made to the file, Paint asks if the user wants to save the changes before it closes the file, so it will not automatically lose any work the user has done. Figure 1.7 shows Microsoft Paint editing a simple drawing.

In contrast, an application with a multiple document interface (MDI) allows the user to interact with more than one file at one time. Microsoft Word uses a multiple document interface to allow a user to edit more than one file at once. The Window menu allows the user to switch quickly from one open file to another. The Split command in the Window menu creates two views of the same document. Figure 1.8 shows Word displaying two views of the same document.

Even though a multiple document interface gives the user more flexibility than a single document interface, MDI is not the best choice for all applications. Some tasks are fairly limited, and allowing the user to present multiple views of the same task may not be very helpful. In that case, the extra benefit given by an MDI is not worth the added complexity for the developer or for the user.

For example, Windows Explorer allows the user to perform a simple task: locating and executing files. If this application used a multiple document interface, the user could see multiple views of the files on more than one disk or computer at one time. In some cases, this might make it a bit easier to drag and drop files from one directory to another. It would, however, make the user interface quite a bit more complicated. By using the scroll bars it is only a little more difficult to perform this same operation using the SDI Explorer.

To perform operations that are difficult using Explorer’s SDI interface, the user can start another copy of Explorer and drag files from one to the other. This approach gives the user the flexibility of an MDI interface when it is really needed and avoids the extra complexity most of the time when SDI is powerful enough.


FIGURE 1.7  Microsoft Paint’s single document interface.

Because Explorer is a small, fast application, starting a second copy will not slow the user’s computer significantly. Starting a second copy of a large application like Microsoft Word, on the other hand, could have a serious effect on the system’s performance. For that reason it makes sense for Microsoft Word to use an MDI. Because a single copy of Word can display many documents, the user does not need to start another copy and possibly slow the entire system.

Notice that a “document” is not always what one traditionally thinks of as a document. As far as SDI and MDI are concerned, a “document” is the largest coherent unit that the user manipulates. For Paint and Word this unit is a file representing a picture or a printed document. For Windows Explorer a “document” is a view of the files on a computer.

The following lists summarize some of the things to consider when choosing between SDI and MDI for an application.

SDI is appropriate when the following conditions hold:

•  The application is small and fast.
•  The task the application performs is small and well defined, so MDI will not provide a large benefit.


FIGURE 1.8  Microsoft Word displaying two views of a document.


MDI is appropriate when the following conditions hold:
•  The application is large and slow to load.
•  The user will often want to view or modify more than one document at one time.
•  The application uses lots of different screens that would be hard to keep track of if they were not contained in an MDI.

Managing SDI Documents

Whether an application uses an SDI or an MDI, it must have a document management strategy. This strategy must ensure that documents modified by the user are properly saved. If the user wants to close a document or exit from the application, the program needs to make sure that each loaded document is safe. If a document has been modified since it was last saved, the application needs to give the user a chance to save the changes before continuing.

Setting DataModified

ExpenseReporter uses a Boolean variable DataModified to keep track of whether the currently loaded document has been modified since the last time it was saved. Because this is an SDI application, a single variable is sufficient. An MDI application would need one variable for each open file. DataModified is declared in the declarations section of ExpenseReporter’s Expense.FRM module. The program changes the value of DataModified when certain events occur. When the user opens an existing file on disk, for example, the document contained in that file has not yet been modified so the program sets DataModified to false. Table 1.1 lists the events that make the program change the value of DataModified.


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.