Creating and Using Calculated Values


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.

Alpha Anywhere documentation and software has traditionally referred the values that you calculate and place on a layout as "calculated fields". However, these values are not fields, because they are not stored in a table record. They are temporary variables that are created and calculated on demand.


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, 
  • amt_disc

    Multiply the CALC->TOTAL field by the Discount and divide by 100.

    CALC->TOTAL * 
  • 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:

  1. Select Form > Calculated Fields... to display the Calculated Values dialog box.

  2. Enter calculated fields, one per line, in the format fieldname = expression.

  3. Optionally, press F10 or the F10 - Expression Builder button to use the Expression Builder to help define the calculated field.

  4. Optionally, press F2 or the F2 - Fields button to see a list of available fields.

  5. Optionally, press F4 or the F4 - Functions button to use the Function Finder to select a function to use.

  6. Optionally, press the following to use the Transform Code utility.

  7. Optionally, press the following to automatically format your code.

  8. 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.
  9. Click OK to return to the Form Editor.

  10. Sketch the new Type-In control onto the form.

  11. Select "Calc" in the Table list.

  12. Select the new value in the Available Fields list.

  13. Click OK to return to the Form Editor.


See Also