Partager via


Creating Programs vs. Inputting Manually

Generally, anything that you can do in a program can be done as well. For example, if you wanted to look at information about a single customer in a table of customers, say the Ernst Handel company, you could do it manually by following a specific sequence of instructions.

To manually find a single order in a table

  1. From the File menu, choose Open.
  2. From the Files of type box, choose Table.
  3. Double-click Customer.dbf in the list of files.
  4. From the View menu, choose Browse.
  5. Scroll through the table, checking the Company field of the records for "Ernst Handel."

Programmatically, you could achieve the same results by typing the following Visual FoxPro commands in the Command window:

USE Customer
LOCATE FOR Company = "Ernst Handel"
BROWSE

After you locate the order for this company, you might want to increase the maximum order amount by 3 percent.

To manually increase the maximum order amount

  1. Tab to the max_ord_amt field.
  2. Multiply the value in max_ord_amt by 1.03, and type the new value in the field.

To achieve the same result programmatically, type the following Visual FoxPro command in the Command window:

REPLACE max_ord_amt WITH max_ord_amt * 1.03

It is relatively simple to change the maximum order amount for a single customer, either manually or by typing the instructions in the Command window. Suppose, however, that you wanted to increase the maximum order amount of every customer by three percent. To do this manually would be laborious and prone to mistakes. If you give the right instructions in a program file, Visual FoxPro can accomplish this task quickly and easily, without error.

Sample Program to Increase Maximum Order Amounts For All Customers

Code Comments
USE customer
Open the CUSTOMER table.
SCAN
Go through every record in the table and perform all the instructions between SCAN and ENDSCAN for every record.
REPLACE max_ord_amt WITH ;
  max_ord_amt * 1.03
Increase the maximum order amount by 3%. (The semicolon (;) indicates that the command is continued on the next line.)
ENDSCAN
End of the code that is executed for every record in the table.

Running a program has some advantages over entering individual commands in the Command window:

  • Programs can be modified and run again.
  • You can run programs from your menus, forms, and toolbars.
  • Programs can run other programs.

See Also

Command Window