Magazine article Computers in Libraries

dBase IV User-Defined Functions for Libraries

Magazine article Computers in Libraries

dBase IV User-Defined Functions for Libraries

Article excerpt

Robert P. Rynkiewicz is the assistant director of the Atlantic City Free Public Library, Atlantic City, New Jersey.

Many DBASE language programmers are familiar with function commands such as EOF(), LEN(), SUBSTR(), TRIM(), etc. The latest version of DBASE, dBASE [V v.1.1, provides the programmer with the ability to enhance the language by allowing programmers to define their own functions, hence the term user-defined functions" (UDF).

What often happens when a programmer creates an application in the previous version of the language, DBASE III Plus, is that he or she wants something to occur that is beyond die capability of the language, - that would require a tremendous amount of ingenuity. This is especially true when creating "Add" or "Edit" screens.

A few years ago I was writing a procedure to add new titles in an acquisitions system. I wanted to prevent the user from entering titles that had one or more of the following conditions: no information entered in the title field; leading articles such as "The"; and duplicate titles already in the database.

This could be accomplished in dBASE M Plus but the code would be extensive and quite complicated. DBASE IV and the new UDF feature allowed me to accomplish aH of this functionality and more with very little code.

dBASE IV v.1.1 allows a programmer a tremendous amount of freedom with UDFs. With the new release, Ashton-Tate has included a new command "SET DBTRAP ON/OFF." With DBTRAP ON, DBASE will help prevent a novice user from creating UDFs that can create unexpected results or worse. The SET DBTRAP ON command will not allow the user access to the more sensitive commands that could easily "hang up" the language. It is strongly suggested that you start out with the DBASE default setting of DBTRAP ON before creating elaborate functions.

UDFs are identical in syntax to dBASE functions. You enter the function name followed by parenthesis. Inside the parenthesis the programmer can pass a list of parameters.

UDFs look and act very much like procedures except the syntax is mote specific. You must always begin a UDF with the command FUNCTION and end with RETURN .

UDF names should not be identical to DBASE language functions. You cannot recursively APPEND, BROWSE, or EDIT the current work area. In other words, you cannot BROWSE the current database and have a UDF program interrupt that will try another BROWSE, EDIT, or APPEND of the same file. A detailed explanation of DBASE language UDFs can be found on pages 1-17 of the Language Reference book included with the documentation for DBASE IV version 1. 1.

One of the earliest UDFs to appear in the literature was a centering function. This function allows the programmer to center any text on the screen.

The UDF CENTER() shown in Figure 1 passes two parameters. The first one contains the text (character data within quotes) which will be centered on the screen, the second parameter is the numeric length of the line. The actual UDF can reside either in the main program module, or if used frequently, could reside in a program loaded into memory at the begining of the main module using the SET PROCEDURE TO" command.

I prefer to load functions like CENTER() into memory since they will be used frequently. There aTe several versions of the CENTER() function in the public domain. …

Search by... Author
Show... All Results Primary Sources Peer-reviewed

Oops!

An unknown error has occurred. Please click the button below to reload the page. If the problem persists, please try again in a little while.