The information in this article applies to:
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
MORE INFORMATION
For the purposes of this discussion, consider the use of the term
"traditional programmer" as someone who has not programmed in Windows, but
who has experience programming in an MS-DOS environment.
"One Entry, One Exit" vs. Event-Driven ProgrammingConsider the following pseudocode of a program designed to get user input, to count all the records in a table, and to display the result in a box if the user presses 1 or to exit if the user presses 2.
The purpose of this program is to continuously loop until a key press of a
1 or 2 is detected. At that point, a decision is made to perform some sort
of operation or to ignore the key press and continue looping. The
programmer has full control over what happens.
The Windows programming model is event-driven and graphic object oriented. In other words, programming in Windows involves creating objects and modifying aspects (or properties) of those objects based on different events. Consider the following sample program that presents two buttons to the user. If the user chooses the Count button, the program counts the records in the database and displays the result in a window. If the user presses the Exit button, the program quits. First, you create the necessary objects. Most of this phase of Visual Basic for Applications or Access Basic programming is created graphically with the Access Forms designer. The list of controls and properties below defines a form that will be used to illustrate this.
NOTE: In Microsoft Access 1.x, the OnClick property is called OnPush.
You can then create the modules that the objects will invoke. In this case, buttons are the only objects that will have the ability to invoke procedures. The procedures shown below are pseudo-code examples. The first procedure defined is the DisplayCount procedure:
Notice that the code did not direct the resulting count to be displayed in
a box painted on the screen. Instead, the Text property of DisplayWindow
was changed to the resulting count value. The next procedure defined is
the CloseProgram procedure.
Notice that this procedure does not provide an exit from some kind of loop
or other program structure. Instead, it closes the object that contains
the buttons and window.
At this point, you have a master form object containing two buttons, a window, and a couple of coded procedures. They are in no special order; they simply exist as part of the form. You may ask, "Where is the loop that checks for button activity? Where is the command to invoke the program?" The answer is that these do not exist as you might expect them to. You "run" the program by opening MasterForm. When you open the form, all the control objects (that is, the buttons and so on) exist on the form, waiting for something to happen. In this example, there is no flow of control (no looping to check activity). While the form is active, Windows constantly checks for events. When an event occurs, the user's input is put in a queue and "waits in line" until it is processed. For example, when you push the "Count" button, Windows detects that the button object you placed on the form has been affected. Windows sends a "Mouse Click" message to Microsoft Access. Microsoft Access then translates the message and determines that the DisplayCount() function should be called based on the "On Push" field of the command button. AdvantagesThe traditional programmer will find this new approach to programming a bit challenging. There are a few things to learn and "unlearn," but there are many advantages.Windows InterfaceThe Windows interface has been regarded throughout the industry as being very user-friendly. Familiar objects such as push buttons, radio buttons, list boxes, and a wide variety of colors and screen fonts are generally more appealing than standard ASCII text characters.The Windows StandardBecause Visual Basic for Applications and Access Basic force you, to some extent, into the Windows standard, others who are familiar with Windows applications can immediately recognize the "look and feel" of your application. This reduces the learning time because the user does not have to learn entirely new interface controls and prompts.Advantages Offered by the Windows EnvironmentYou do not have to worry too much about different devices such as monitors, printer drivers, and so on. The Windows operating environment takes care of most device compatibility and user preference issues. In addition, because Windows handles and processes events, you will find it much easier to create and manage many aspects of an application.Additional query words:
Keywords : kbprg |
Last Reviewed: October 14, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |