Skip to main content
Previous sectionNext section

CALCULATE

Returns the results of an I-type calculation.

Synopsis

CALCULATE(ITypeDictItem)

Arguments

ITypeDictItem A valid virtual attribute. Must be a compiled I-type in the dictionary opened as @DICT.

Description

The CALCULATE function evaluates an itype expression defined in a dictionary item against data in an MVBasic program and returns the result.

CALCULATE reads the dictionary item ITypeDictItem from the file opened to the @DICT variable. It then evaluates the itype expression defined in attribute 2 of the dictionary item, using the data in @ID and @RECORD. Calculate also sets the @CONV, @FORMAT, and @HEADER system variables to attributes 3, 5, and 4 of the dictionary item respectively. These can be used with the OCONV and FMT functions to format the results of CALCULATE.

Before using CALCULATE you must open a file to the @DICT system variable, and assign values to @ID and @RECORD. If the itype expression uses other @variables (for example @FILE.NAME) then these need to be set as well.

CALCULATE and ITYPE Compared

The CALCULATE function is similar to the ITYPE function:

  • The ITYPE function argument is a variable into which a dictionary item has already been read, or an itype expression assigned. The ITYPE function allows on-the-fly creation of itype expressions

  • The CALCULATE function argument must be the name of an existing dictionary item which will be read by the function.

Example

The following example opens the Myfile file to the item variable, and the Myfile dictionary to the @DICT special variable. It then reads through the item variable by @ID, and uses CALCULATE to calculate a total of the records in item. CALCULATE also sets values for the @CONV and @FORMAT system variables used by the OCONV and FMT functions.

OPEN 'Myfile' TO item ELSE STOP 201,'MyFile'
OPEN 'DICT','Myfile' TO @DICT ELSE STOP 201,'DICT MyFile'
SELECT item TO 0
LOOP WHILE READNEXT @ID FROM 0
   DO
   READ @RECORD FROM item,@ID
   total += CALCULATE(amt_due)
   REPEAT
convtotal = OCONV(total,@CONV)
fmttotal = FMT(convtotal,@FORMAT)
PRINT fmttotal
END
Copy code to clipboard

See Also