PROCEDURE Command Example

The following example illustrates how a procedure can be called to accomplish a discrete task such as making an entry in a log file. The procedure opens the log file (which is assumed to exist in the example), constructs an entry based in information passed in parameters, writes the entry out, and closes the file. The procedure is called with a DO command similar to the one at the top of the program.

DO MakeLogEntry WITH "Logged in", "jsmith"

PROCEDURE MakeLogEntry
 PARAMETERS message, username
 pnHandle = FOPEN("LOG2.TXT",2)     && Assume the file exists
 pnSize = FSEEK(pnHandle,0,2)           && Move to end of file
 logEntry = dtoc(date())+","+time()+","+username+","+message
 =FPUTS(pnHandle, logEntry)
 =FCLOSE(pnHandle)  && Close file
ENDPROC

The following example shows how a procedure can be called to return a value.

SET CENTURY ON
? longdate(({^1998-02-16}))  && Displays Monday, February 16, 1998

PROCEDURE longdate
 PARAMETER mdate
 RETURN CDOW(mdate) + ", " + MDY(mdate)
ENDPROC