Classic Computer Magazine Archive COMPUTE! ISSUE 149 / FEBRUARY 1993 / PAGE 66

Using FoxPro. (program development software and data base management system) (Column)
by Tom Campbell

Make no mistake--FoxPro makes programming in an xBASE language a lot easier, if you know xBASE (xBASE includes the languages based on dBASE III+ and IV).

Despite its $500 street price, FoxPro lacks detailed training because it's aimed at the professional developer. But there are a lot of training resources available. Take FoxPro seriously, and it will pay you back handsomely with a level of productivity that C programmers can only dream of.

What programmers in C, BASIC, or Pascal will appreciate most is that the structure of a database can be changed with impunity and that adding data entry routines is trivial. In traditional languages, adding or subtracting fields to a random-access file structure requires vast recording and must be avoided.

You can create a complete database browser with a mousing, menuing interface in well under 100 lines--including a custom data entry screen with error checking. Let's look at code from a program I wrote in under 15 minutes.

This code makes a box at the bottom of the screen that's 36 columns wide; has a shadowed, double border; and can be dragged anywhere onscreen with a mouse: DEFINE WINDOW Buttons FROM; 20, 12 TO 22, 56 FLOAT; SHADOW DOUBLE. Later commands such as ACTIVATE will use the box's name (Buttons in this case). The semicolon continues lines.

Later, this code displays the box and makes it active: ACTIVATE WINDOW Buttons. Now you can drag the box, and all of its contents will remain neatly inside.

This code creates a row of buttons within the box. [at] 0, 2 GET ButtomCmd PICTURE; '[ar]*HN \The row of buttons is located at row 0, column 2 in the Buttons box. PICTURE is a terse but logical and easy-to-use minilanguage. The [at]* means buttons will be created. H means it's a horizontal row; use V for a vertical row. N means pushing a button won't halt data entry.

Identifiers such as Next will appear in the buttons; semicolons separate buttons. Preceding any letter in the button text with the two-character \< sequence makes that an accelerator--meaning you can press that key to activate the button. The ?\ sequence means that the button is activated when you press the Esc key. In our example, Quit can be activated with a or Esc. ButtonCmd is the name of the variable in which the value of the button you click on will be placed; its default value is 0, \ValidButton() is a user-written routine that's evaluated when a button is clicked on. Because the row was defined in a floating window, you can drag the window, and all the buttons will stay in it.

A custom data entry screen with a row of push buttons requires fewer than 24 lines. DEFINE WINDOW Customer FROM; 3, 8 To 13, 60; FLOAT SHADOW DOUBLE USE Test ACTIVATE WINDOW Customer; NOSHOW [at] 1, 3 SAY 'Name' [at] 1, 14 GET TEST.Name [at] 3, 3 SAY 'Address' [at] 3, 14 GET TEST.Address [at] 5, 3 SAY 'Price' [at] 5, 14 GET TEST.Price [at] 7, 3 SAY 'Phone' [at] 7, 14 GET TEST.Phone ACTIVATE WINDOW Buttons [at] 0, 2 GET act PICTURE; '[at]*HN \USE Test opens up the database called test.dbf. The [at] . . . SAY lines display labels in the window at the specified positions. Data is entered at the [at] . . . GET lines, and data entry is triggered by READ. Move between fields using the keyboard or the mouse.

ValidButton() is called to handle the push-button actions. Each button is treated as if it were an index into a numeric array, so Next returns 1, Previous returns 2, and Quit returns 3. All ValidButton() needs is about 20 lines worth of CASE statements that call built-in xBASE routines such as TOP to move to the beginning of the file or BOF() to sense if the end of the file has been reached. ValidButton() is called continuously until Quit is clicked on. The Quit case executes a command such as CANCEL, which returns control to the calling program or to DOS if it's an exe.

That's it: the beginning of a program that with two more pages of code can become a self-contained database management system with a modern user interface and error-checking logic for data entry.

With FoxPro, you'll need a $500 product called the Distribution Kit to create exe files. So is it really worth $1,000 to use FoxPro? Without a doubt. Being able to create a slick, working prototype in just a few minutes could mean that you'll make that $1,000 back--on your first job.