$Incrg: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
m (Mlarocca moved page $INCRG to $Incrg: Lower case change)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<p>The $INCRG function performs simple arithmetic on global variables. Global variables are discussed in [[Global Features#Global Features|Global Features]].  </p>
<p>The $INCRG function performs simple arithmetic on global variables. Global variables are discussed in [[Global features]].  </p>
<b>Syntax</b>
<b>Syntax</b>
<p>The format of the $INCRG function is:</p>
<p>The format of the $INCRG function is:</p>

Latest revision as of 18:08, 21 July 2014

The $INCRG function performs simple arithmetic on global variables. Global variables are discussed in Global features.

Syntax

The format of the $INCRG function is:

$INCRG(global name [,increment] [,decimal_places*)

where:

  • global name must be specified as a string.
  • increment is an optional numeric value; the default value is 1.
  • decimal places is optional and specifies the number of decimal places to be preserved in the result of the operation. The fractional part of the result is truncated (not rounded) or padded with zeros as appropriate. If this argument is omitted, the $INCRG result has the same number of decimal places as the original global value.

How $INCRG works

$INCRG adds the value specified in the increment argument to the global variable specified in the global name argument and returns a completion code. The $INCRG operation preserves up to 15 digits of precision. Both the global value and the increment are treated as signed quantities. Thus, if the increment is less than 0, the function performs subtraction.

Model 204 converts the global value set by $INCRG to floating point and then converts it back to a string. Thus, any leading and trailing zeros, plus signs, and internal spaces are lost. The decimal point is also lost unless it is followed by a nonzero decimal digit before the 15th digit place. If the global variable does not exist, $INCRG creates one with a value equal to the increment. If a value is not specified as the decimal_places argument in the function call, the created global variable have no decimal places.

$INCRG returns a completion code indicating the success or failure of the operation, along with an explanatory message. Possible codes are:

Code Meaning
0 $INCRG completed normally
1 Global value is not numeric
2 No room for new value of global (size of global can change after increment)

IF statements

In an IF statement of the form "IF expression", the THEN clause is evaluated if expression has any value other than 0. Thus, IF $INCRG ('X') THEN JUMP TO ERROR.ROUTINE transfers control to the ERROR.ROUTINE statement on either of the two possible error conditions. If different actions are to be taken for each distinct condition, this technique is recommended:

JUMP TO (ERROR.TYPE1,ERROR.TYPE2) $INCRG ('X')

In this case, no jump is taken if $INCRG completes successfully and returns 0.

Example 1

PRINT $INCRG ('GLOBAL')

prints 0 if the operation is successful and increases the value of GLOBAL by 1.

Example 2

PRINT $INCRG ('X', -.5)

prints 0 if the operation is successful and decreases the value of global X by 5.