Calculated Fields


Alpha Anywhere supports two similar capabilities:

  • Calculated Fields - where Alpha Anywhere uses a field rule to calculate the value of a table field

  • Calculated Variables - which you may place on a layout or use in computations

If you define a calculated field for a table, you can use it in any layout or operation defined for that table.


Creating a Calculated Field Rule

See also Calculated Fields.

  1. In the Control Panel select the table and click Table > Edit Field Rules.

  2. On the Field Types tab in the In the Extended field types group, click the Calculated radio button.

  3. Optionally, change the Default descriptive name for this calculated field.

  4. Optionally, change the Field description.

  5. Enter the expression that computes the field value in the Calculated field expression field. The expression must return the same data type as the table field. Click to use the Expression Builder to help you define the expression.

A Calculated Field Rule Example

A calculated field rule defines how Alpha Anywhere will calculate the value of a field in your table. You can then place this field on a layout, just as you would place any other field. The following procedure shows how the Extension field was calculated for the invoice_items table of the AlphaSports database.

  1. Display the Tables/Sets tab of the Control Panel.

  2. Select the "invoice_items" table and click Design > Field Rules.

  3. Select the "invoice_items->Extension" field from the list box.

  4. Display the Field Types tab.

  5. Select the Calculated radio button.

  6. Click the 'x-y' icon in the Calculated field expression control to display the Expression Builder.

  7. Double click Field Name in the upper left corner of the dialog. Select "Price" and click Insert.

  8. Place a multiplication symbol after "Price", so the expression is "Price*".

  9. Double click Field Name in the upper left corner of the dialog. Select "Quantity" and click Insert, so the expression is "Price*Quantity".

  10. Click OK to return to the Field Rules Editor.

  11. Click Save OK > Close.


Forcing Recalculation Using Xbasic

The following script forces all calculated fields in a table to be recalculated.

dim tbl as P
tbl ="yourtablename")
while .not. tbl.fetch_eof()
end while