DO Command
Executes a Visual FoxPro program or procedure.
Tip
You can execute a program that executes another program that executes another program and so on by including additional nested DO commands in a program file. For more information about program nesting levels, see Visual FoxPro System Capacities.
DO ProgramName1 | ProcedureName [IN ProgramName2] [WITH ParameterList]
Parameters
ProgramName1
Specifies the name of the program to execute.If you do not include an extension with the program you execute, Visual FoxPro looks for and executes versions of the program in the following order:
Executable (.exe)
Application (.app)
Compiled (.fxp)
Program (.prg)
To execute a specific menu program, form program, or query using the DO command, you must include the file extension (.mpr, .spr, or .qpr).
ProcedureName
Specifies the name of the procedure to execute. Visual FoxPro first looks for the procedure in the currently executing program. If the procedure is not located there, Visual FoxPro then looks for the procedure in the procedure files opened with SETPROCEDURE.You can include the IN ProgramName2 clause to tell Visual FoxPro to look for the procedure in a file you specify.
Multiple procedures within an executable (.exe) version or an application (.app) can have the same name. When you use the DO command to start a procedure in an executable version or in an application, Visual FoxPro searches only the main program of the executable version or application for the specified procedure.
IN ProgramName2
Executes a procedure in the program file specified with ProgramName2.When the file is located, the procedure is executed. If the program file cannot be located, the message "File does not exist" appears. If the program file is located but the specified procedure isn't in the program file, the message "Procedure is not found" appears.
WITH ParameterList
Specifies parameters to pass to the program or procedure. The parameters listed in ParameterList can be expressions, memory variables, literals, fields, or user-defined functions. By default, parameters are passed to programs and procedures by reference. You can pass a parameter by value by placing it in parentheses.See SET UDFPARMS Command for a discussion of passing parameters by value or reference. The maximum number of parameters you can pass to a program or procedure is 26. For more information on parameter passing, see LPARAMETERS Command and PARAMETERS Command.
Remarks
When you use DO to run a program, the commands contained in the program file are executed until one of the following occurs:
RETURN is encountered.
CANCEL is executed.
Another DO is issued.
The end of the file is reached.
QUIT is executed.
When program execution is complete, control is returned to one of the following:
Program that called DO
Command window
Operating system
If you choose Do from the Program menu and execute a program in a directory on a drive other than the current directory or drive, Visual FoxPro automatically changes the default directory and drive to the directory and drive containing the program.
You can also modify how an application searches for data and resources such as functions, procedures, executable files, and so on using SYS(2450) - Application Search Path Order.