The MORTGAGE.PRG program is an example of a program file containing multiple procedures and functions. The program computes home mortgage payments given the price of the property and the down payment. It also computes the total monthly payment, or PITI, which is principal, interest, taxes, and insurance. You can also enter the principal and interest payment and the program computes the price of the property.
The PRvalid() and LAValid() functions are called snippets. A snippet is a term (used with the screen designer) that refers to FoxPro code (usually a UDF) that is attached to a screen object or provides screen control. In the previous example, the snippets are called when the VALID clause is evaluated. (This occurs after you type a number into one of the @... GET fields.) Traditionally, a VALID clause is used to validate data entry; however, in MORTGAGE.PRG the VALID clause is used to simulate a spreadsheet. The snippets call the RECALC procedure each time an entry field is changed to recompute and redisplay the contents of the remaining entry fields and display fields. The PAYMENT() function computes the payment given the principal, interest rate, and term. The PV() function computes the principal given the payment, interest rate and term. You can also change the interest rate and the term of the payment. Figure 6.3 in the book shows an example output screen for the mortgage payment calculator.