Skip to content

Calc, Calculate Command

Obsolete

This command is replaced by the Move command.

See Also

Purpose

To evaluate an expression and move the result to an in-memory variable, field, or window.

Syntax

calc{ulate}
source_expression
to
destination

The procedure must be previously defined in the program by the procedure command.

The number of values must match the number of arguments declared for the procedure, and the type of each must match that of its respective argument.

What It Does

Calc evaluates an arithmetic expression (source_expression) and places the result in a variable (destination).

  • calc (23.9 * 44.1) to result
    Multiply 23.9 by 44.1 and place the product in the variable result.

  • calc (sales_date + 30) to followup_date
    Add 30 to the value of the variable sales_date and place the sum in the variable followup_date.

  • calc (parts.on_hand - 1) to parts.on_hand
    Subtract 1 from the value of the database element parts.on_hand and place the difference in parts.on_hand.

  • calc ((total + amount) / avrg) to avrg
    Add the value of total to the value of amount, divide the sum by avrg, and place the quotient in avrg.

Notes

  • You may use calc, calculate, and movenum interchangeably. If the type of destination is Number, the move command will also function similarly. The calc and calculate commands are provided primarily to enhance the readability of programs.

  • DataFlex cannot calculate literal dates in expressions correctly.

calc (05/12/96 + 30) to due_date

This command would put 5 divided by 12 divided by 96 plus 30 into due_date, not the desired result. Instead, use a Date-type variable to calculate on a date, as follows:

move 05/12/96 to invoice_date
calc (invoice_date + 30) to due_date
  • Do not use calc to fill output windows in report programs, because calc does not update window accumulators, which may be needed in the subtotal and/or total sections. Only the print command should be used for this purpose. Print is capable of evaluating expressions.

  • To calculate the value of an expression that is in a String variable, put the name of the string inside parentheses. Strings so used may contain only numbers and operators, not field, window, or variable names.

move (3 + 4) to astring
calc (astring) to anumber
  • Expressions in DataFlex are made up of combinations of operators (+, -, *, /, ^), literal numbers, and/or references to database elements, in-memory variables, or windows. DataFlex evaluates expressions from the innermost parentheses outward, from left to right, without regard to any precedence of operators.