Calc, Calculate Command
Obsolete
This command is replaced by the Move command.
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 variableresult. -
calc (sales_date + 30) to followup_date
Add 30 to the value of the variablesales_dateand place the sum in the variablefollowup_date. -
calc (parts.on_hand - 1) to parts.on_hand
Subtract 1 from the value of the database elementparts.on_handand place the difference inparts.on_hand. -
calc ((total + amount) / avrg) to avrg
Add the value oftotalto the value ofamount, divide the sum byavrg, and place the quotient inavrg.
Notes
-
You may use
calc,calculate, andmovenuminterchangeably. If the type ofdestinationisNumber, themovecommand will also function similarly. Thecalcandcalculatecommands 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
calcto fill output windows in report programs, becausecalcdoes not update window accumulators, which may be needed in the subtotal and/or total sections. Only theprintcommand should be used for this purpose.Printis 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.