Condividi tramite


Creating Programs

You can write code that executes commands and save it in a program file in Visual FoxPro. Although you can run code in the Command window, running a program has some advantages such as the following:

  • You can modify and run programs multiple times.
  • You can run programs from menus, forms, and toolbars.
  • You can use programs to run other programs.

To create a program

  1. From the File menu, choose New.
  2. In the New dialog box, select Program, and click New File.
  3. In the editing window, type the code for the program.

You can also create a program in the following ways by using MODIFY COMMAND in the Command window or selecting Programs under the Code node in the Project Manager and choosing New. For more information, see MODIFY COMMAND Command and Project Manager Window.

Note   Make sure you save the program after creating it.

To save a program

  • From the File menu, choose Save.

Programs are saved with the .prg extension.

If you try to close an unsaved program, a dialog box opens, prompting you to either save or discard the changes you made to it.

If you save a program that was created in the Project Manager, the program is added to the project.

If you save a program that does not have a name, the Save As dialog box opens so you can specify a name for the program. After you save your program, you can run or modify it.

Modifying Programs

To makes changes to a program, open the program.

To open a program

  1. From the File menu, choose Open.
  2. In the Open dialog box, choose Program in the Files of type list to show only program files.
  3. Select the program you want to modify and choose OK.

If the program is part of a project, you can select the program in the Project Manager and choose Modify. You can also type the MODIFY COMMAND command with the name of the program in the Command window as follows:

MODIFY COMMAND MyProgram

-or-

MODIFY COMMAND ?

From the list of files, select the program you want to modify and choose Open.

After you open the program, you can make changes. When you finish making your changes, be sure to save the program.

Running Programs

After you create and save a program, you can run it.

To run a program

  1. From the Program menu, choose Do.
  2. From the list of programs, select the program and choose Do.

If the program is part of a project, you can select the program in the Project Manager and choose Run. You can also type the DO command with the name of the program in the Command window as follows:

DO MyProgram

See Also

Programming in Visual FoxPro | Running Code Manually | Searching and Replacing Code References | Viewing Code Definitions | Project Manager Window | Operating the Command Window