ACC: Introduction to Windows Programming for MS-DOS Programmer (88164)



The information in this article applies to:

  • Microsoft Access 1.0
  • Microsoft Access 1.1
  • Microsoft Access 2.0
  • Microsoft Access for Windows 95 7.0
  • Microsoft Access 97

This article was previously published under Q88164
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

This article discusses some differences between programming in the MS-DOS environment and programming in the event-driven Windows environment.

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.

As a traditional programmer, you may have become comfortable not only with a particular programming style, but also with certain accepted fundamentals, such as writing an instruction and expecting it to be carried out in a controlled order. Visual Basic for Applications in Microsoft Access for Windows 95 version 7.0 and 97 or Access Basic in Microsoft Access 1.x and 2.0 makes good use of Windows, making Windows programming easy to learn.

"One Entry, One Exit" vs. Event-Driven Programming

Consider 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.
   START PROGRAM

   LOOP WHILE TRUE
      GET KEYPRESS INTO X

      IF X IS "1"
         COUNT ALL RECORDS IN THE TABLE INTO Y
         DRAW BOX FROM ROW 10 COLUMN 5 TO ROW 12 COLUMN 7
         DISPLAY Y AT ROW 11 COLUMN 6

      IF X IS "2"
         EXIT LOOP

   END LOOP

   STOP PROGRAM
				
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.
   Form: MasterForm
   ----------------------------
   Push Button: CountButton
       Caption: Count
       OnClick: =DisplayCount()
   Push Button: ExitButton
       Caption: Exit
       OnClick: =CloseProgram()
   Text Box: DisplayWindow
				
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:
   PROCEDURE DisplayCount()

      COUNT ALL THE RECORDS IN THE TABLE INTO Y
      CHANGE THE DISPLAYWINDOW TEXT PROPERTY TO Y

   END 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.
   PROCEDURE CloseProgram

      CLOSE MASTERFORM

   END 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.

Advantages

The 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 Interface

The 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 Standard

Because 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 Environment

You 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.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbinfo kbProgramming KB88164