Microsoft KB Archive/88164

= ACC: Introduction to Windows Programming for MS-DOS Programmer =

Article ID: 88164

Article Last Modified on 2/12/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



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 &quot;traditional programmer&quot; 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.

&quot;One Entry, One Exit&quot; 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 &quot;1&quot; 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 &quot;2&quot; 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, &quot;Where is the loop that checks for button activity? Where is the command to invoke the program?&quot;

The answer is that these do not exist as you might expect them to. You &quot;run&quot; 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 &quot;waits in line&quot; until it is processed. For example, when you push the &quot;Count&quot; button, Windows detects that the button object you placed on the form has been affected. Windows sends a &quot;Mouse Click&quot; message to Microsoft Access. Microsoft Access then translates the message and determines that the DisplayCount function should be called based on the &quot;On Push&quot; 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 &quot;unlearn,&quot; 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 &quot;look and feel&quot; 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.

Keywords: kbinfo kbprogramming KB88164

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.