PROCEDURE Command

Example   See Also

Identifies the beginning of a procedure in a program file.

Syntax

PROCEDURE ProcedureName
  Commands
  [RETURN [eExpression ]]

ENDPROC

Arguments

ProcedureName

Specifies the name of the procedure to create.

Remarks

PROCEDURE is a statement within a program file that specifies the beginning of each procedure in the program file and defines the procedure name. Procedure names must begin with a letter or underscore and may contain any combination of letters, numbers, and underscores.

In Visual FoxPro for Windows, procedure names can be up to 254 characters long.

Comments can be placed on the same line after PROCEDURE and ENDPROC. These comments are ignored during compilation and program execution.

The PROCEDURE statement is followed by a series of commands that make up the procedure. You can include RETURN anywhere in the procedure to return control to the calling program or to another program, and to define a value returned by the procedure. If you do not include a RETURN command, an implicit RETURN is automatically executed when the function quits. If the RETURN command does not include a return value (or if an implicit RETURN is executed), Visual FoxPro assigns .T. (True) as the return value.

The procedure ends with the ENDPROC command. This command is optional; the procedure quits when it encounters another PROCEDURE command, a FUNCTION command, or the end of the program file.

Note   You cannot have normal executable program code included in a program file after procedures; only procedures, user-defined functions, and class definition can follow the first PROCEDURE or FUNCTION command in the file.

When you execute a procedure with DO ProcedureName, Visual FoxPro searches for the procedure in a specific order. Visual FoxPro searches:

  1. The program containing DO ProcedureName.

  2. The current database.

  3. The procedure files opened with SET PROCEDURE.

  4. Programs in the execution chain. It searches program files beginning with the most recently executed program and continuing back to the first executed program.

  5. A stand-alone program file. If a program file with the same name as the file name specified with DO is found, Visual FoxPro executes the program. If a matching program file name isn't found, Visual FoxPro generates an error message.

Include the IN clause in DO to execute a procedure in a specific file.

By default, parameters are passed to procedures by value. For information on passing parameters to procedures by reference, see SET UDFPARMS. A maximum of 27 parameters can be passed to a procedure. Parameters can be passed to a procedure by including a PARAMETERS or LPARAMETERS statement in the procedure, or by placing a list of parameters immediately after PROCEDURE ProcedureName. Enclose the list of parameters in a set of parentheses, and separate the parameters with commas.