6.9.2 Simple Calculations

The first example calculates the value for the amount field from the values in the units field and the each field. The Form Description screen, data entry form and field descriptions for this example are shown in Figure 1.

Form Name ex1

Data File

Beginning form no Unique records no

Repeating form no Append form no

Freeze form no Additional form no

Required form no for one record

Next form name ex1

gifs/00000001.gif

Field name units Field length 8

Entry Allowed yes Input required no

In Data File no Invisible no

Edit Data Type real

Field name each Field length 12

Entry Allowed yes Input required no

In Data File no Invisible no

Edit/Match test each <= 0 "each too small"

test each >= 100 "each too big"

Edit Data Type money

Field name amount Field length 14

Entry Allowed no Input required no

In Data File no Invisible no

Calculation units*each

Edit Data Type money

Figure 1

Any time either the units or each field is changed, form recalculates the value of units*each and displays the result in the amount field.

Note the entry made in the Edit Data Type field when defining each of the different fields. The units field is a field of type real. Both the Each and Amount fields are money fields. When producing the calculated field result, the type of each of the different fields in the formula is taken into account.

When you use fields that are in a data file, you do not need to declare the data type in the Edit Data Type field. The field type is taken from the data dictionary for the file. In this example, however, the fields are not in a data file, so the data types must be declared by entering something in the Edit Field Type field.

The each field has an Edit/Match formula that verifies that the each field is between 0 and 100. Both of the test statements must pass for the formula to pass.