DO Command
Collapse the table of content
Expand the table of content

DO Command

Visual Studio .NET 2003

Executes a Visual FoxPro program or procedure.

DO ProgramName1 | ProcedureName [IN ProgramName2] [WITH ParameterList]


Specifies the name of the program to execute.

If you don't include an extension with the program you execute, Visual FoxPro looks for and executes these versions of the program in the following order:

  • .exe (executable version)
  • .app (an application)
  • .fxp (compiled version)
  • .prg (program)

To use DO to execute a specific menu program, form program, or query, you must include its extension (.mpr, .spr, or .qpr).

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 SET PROCEDURE.

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 DO 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 for a discussion of passing parameters by value or reference. The maximum number of parameters you can pass to a program or procedure is 27. For more information on parameter passing, see LPARAMETERS and PARAMETERS.


DO executes a Visual FoxPro program or procedure in a program or procedure file. A program file can itself contain additional DO commands, making it possible for you to nest DO commands up to 128 levels.

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:

  • The calling program.
  • The Command window.
  • The 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.

See Also


© 2016 Microsoft