Creating and Using Calculated Values
Description
Use calculated values to automatically calculated a number, character string, or any other variable type when you enter or change data. The developer may manually enter the expression that calculates a value or use the Expression Builder. The operator cannot enter or change data in a calculated value.
Expressions
The Invoice form of the AlphaSports database has four calculated values: amt_disc, amt_tax, and grand_total. The calculated values have the following expressions.
total
Sum the INVOICE_ITEMS->Extension and GRP >INVOICE_HEADER fields.
total(INVOICE_ITEMS >Extension, GRP >INVOICE_HEADER)
amt_disc
Multiply the CALC->TOTAL field by the Discount and divide by 100.
CALC->TOTAL * Discount/100
amt_tax
Subtract the Calc->amt_disc field from the Calc->Total field, multiply by the Sales_Tax field, and divide by 100.
(Calc->Total - Calc->amt_disc) * Sales_Tax / 100
grand_total
Subtract the Calc->Amt_Disc field from the Calc->Total field, then add the Calc->Amt_Tax field.
Calc->Total - Calc->Amt_Disc + Calc->Amt_Tax
Procedure: Creating a Calculated Value
The following procedure assumes that the developer has opened the form in the Form Editor. Follow these instructions to create an email function similar to that called by Button6 on the Invoice form:
Select Form > Calculated Fields... to display the Calculated Values dialog box.
Enter calculated fields, one per line, in the format fieldname = expression.
Optionally, press F10 or the F10 - Expression Builder button to use the Expression Builder to help define the calculated field.
Optionally, press F2 or the F2 - Fields button to see a list of available fields.
Optionally, press F4 or the F4 - Functions button to use the Function Finder to select a function to use.
Optionally, press the following to use the Transform Code utility.
Optionally, press the following to automatically format your code.
The 'az up' icon and 'az down' buttons will sort your entries alphabetically.
Although these examples return numbers, calculated values can also return character and logical values.Click OK to return to the Form Editor.
Sketch the new Type-In control onto the form.
Select "Calc" in the Table list.
Select the new value in the Available Fields list.
Click OK to return to the Form Editor.
See Also