The Calculation object allows you to compose complex calculations or simply assign data to a field or variable. Since the Calculation object is adjustable in size, calculations are not hampered by any space considerations. In addition multiple Calculation objects can be positioned in succession in the Workspace. A Calculation object can also contain more than one statement in which case it executes them in a top-down order:

In the process of performing various operations on variables, the Calculation object uses statements which can be as simple as "target = expression;" where:

• the target is the field or variable that receives the results of evaluating the expression;
• the expression may involve fields, variables, constants and arithmetic or logical operators; and,
• the statement must be terminated by a semicolon.

Consider the impact on Triggered Procedures.

The following are simple examples of valid statements:

 1. Amount = Price * Quantity; Multiply the contents of the Price variable by the contents of the Quantity variable; store the resulting value in the Amount variable. 2. Quantity = Quantity - 1; Subtract 1 from the contents of the Quantity variable; store the resulting value back into the Quantity variable. 3. Date = '19940115'; Store date in the internal format of YYYYMMDD in the Date variable. 4. Name = 'John Doe'; Store the character string "John Doe" in the Name variable. 5. CityString = 'Calgary, ' + 'AB, ' + 'Canada' Concatenates (strings together) 'Calgary, '  'AB, ' 'Canada' and stores the resulting text string "Calgary, AB, Canada" in the CityString variable. 6. EffectivePrice = Price * (1.0 - PercentDiscount * 0.01); Calculate the effective price as the product of the original price carried by the Price variable and discount factor; the discount factor is calculated as the difference between 1 and the percentage of the discount stored in the PercentDiscount variable (note the priority of the operations: the expression in the parentheses is calculated first). 7. Flag = Amount > CreditLimit; Compare contents of the Amount variable with contents of the CreditLimit variable; if the former is > than the latter, assign logical value YES to the Flag variable; else, set it to NO.

STEP FORWARD recognizes the following data types in Calculation statements:

 Type Description TEXT Free-formatted ASCII text DATE Date in YYYYMMDD format TIME Time in HHMMSS format INTEGER A whole number without decimal point FLOAT A regular number with decimal point MONEY Money (similar to FLOAT) LOGICAL Logical value that can be set to YES or NO SEARCHKEY Search key FILENAME Name of file

The data type of the target variables in a Calculation statement is not explicitly assigned by the user, but is instead inferred from the context of the procedure. It is derived from the data type of the right-hand side of the equation, which in turn depends on the data types of variables and constants used in the expression.

In the simplest case, where the statement is of type target = constant, the target inherits data type of the constant. For example, Quantity = 1 sets the data type of Quantity to INTEGER, because this is the data type of constant 1. In another example, Industry = 'Automotive' makes the Industry variable of TEXT type, because the value assigned to it is enclosed in single quotes (and therefore, by definition, is a literal constant).

In the case of a more complex expression, where the right-hand side of the statement is composed of variables and constants of (possibly) different data types, evaluation of the resulting data type of the whole expression is done incrementally, in the following steps:

 1 The original expression is parsed into a series of elementary sub-expressions of A B type, where A and B are variables or constants, and is arithmetic, comparison or logical operator. This breaking-up of the expression is done according to the grouping of components of the expression (with parentheses), in the order of priorities. The example that follows illustrates this process:

 Original expression Parsed components A = B + (C - (D + 1)) * 2; V1 = D + 1 V2 = C - V1 V3 = V2 * 2 V4 = B + V3; A = V4;

 Here Vn is a temporary variable that holds results of intermediate calculations.

 2. Data type of each of the sub-expressions is evaluated according to the following rules: An INTEGER value can be added to or subtracted from DATE; the resulting data type is DATE (variable of DATE type must be on the left side of the arithmetic operator). For the purposes of calculation, the integer value is interpreted as number of days to be added to or subtracted from the date. A DATE variable can be subtracted from another DATE variable; the resulting data type is INTEGER. For the purposes of calculation, the integer value is interpreted as number of days separating the two dates. A DATE variable can be compared with another DATE variable; the resulting data type is LOGICAL. A DATE variable can be assigned to another DATE variable; the resulting data type is DATE. A TEXT variable or constant, or a SEARCHKEY variable can be assigned to another TEXT variable; the resulting data type is TEXT. A TEXT variable can be compared with another TEXT or SEARCHKEY variable (the comparison can only be for equality or inequality); the resulting data type is LOGICAL. A TIME variable can be assigned to another TIME variable; the resulting data type is TIME. A TIME variable can be compared with another TIME variable; the resulting data type is LOGICAL. An INTEGER, FLOAT or MONEY variable can be arithmetically added to, subtracted from, and multiplied or divided by another INTEGER, FLOAT or MONEY variable; the resulting data type is promoted to the highest rank according to the following formula:

 INTEGER INTEGER = INTEGER INTEGER FLOAT = FLOAT INTEGER MONEY = MONEY FLOAT INTEGER = FLOAT FLOAT FLOAT = FLOAT FLOAT MONEY = MONEY MONEY INTEGER = MONEY MONEY FLOAT = MONEY MONEY MONEY = MONEY

 An INTEGER, FLOAT or MONEY variable can be compared with another INTEGER, FLOAT or MONEY variable; the resulting data type is LOGICAL; A LOGICAL variable can be assigned to another LOGICAL variable; the resulting data type is LOGICAL. A LOGICAL variable can be compared with another LOGICAL variable (the comparison can only be for equality or inequality); the resulting data type is LOGICAL.

Triggered Procedures
Data Entry procedures are triggered when the fields to which they are attached are disturbed. This "disturbance" can occur through keyboard action or through the assignment of data using the Calculation object.

Data Entry procedures have this Inspector tool:

The default setting for Allow triggering of procedures is No. This option protects against the unintentional triggering of Procedures.

If the "disturbance" of a trigger-field brought about by the Calculation object is supposed to trigger the Procedure associated with the "disturbed" field, set the Inspector's switch to YES.