Topic: DMD0118

Help File Version: 2.10.0.636

SUM IFxx - Sum If (EQ, NE, LT, LE, GT, GE)


This instruction can only be used in the Expression parameter of the Calculate Expression (MATH) instruction.

 

Each of the Sum If math functions sums the values in the locations in the specified range that match the specified value by making the comparison in the function name. There are six variants of the Sum If math function, and all six have the following parameters:

 

Note: Use the F9 key or click the 'three dot box' at the right edge of the parameter field to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.

 

Result specifies a location to store the result of the calculation. This can be any writable numeric location or an array reference, e.g. D [V0 ], (the array reference itself can be a math expression, e.g. D [ V0 +16 ]).

 

The Expression parameter consists of all the text between the bounding parentheses. The parameter list must consist of 2 parameters separated by a comma. Each parameter is an expression which can be a constant value, a bit or numeric memory location, an arithmetic expression, and / or mathematical function or other expressions up to a maximum of 1024 characters. Expressions can be nested, so use of parentheses is recommended to ensure proper evaluation order.

The first parameter designates the comparison value. This can be any expression parameter, including any constant value, any readable numeric location, any readable bit location, any Math function, or any combination of these with Math operators.
 

The second parameter specifies the first location in the range of locations to compare against. This can be any readable any numeric or bit data block location, including casts and structure members (fields of heap structures are not supported).

 

The third parameter specifies the number of contiguous locations that will be compared against. This can be any expression parameter, including any constant value, any readable numeric location, any readable bit location, any Math function, or any combination of these with Math operators.

If the third parameter is 0, the result will be 0, and Argument Out of Range (ST132) will be ON.

 

If the third parameter exceeds the size of the specified data block, the result will only include the values up through the last location in the block, and Argument Out of Range (ST132) will be ON. For example, assume the block of WX locations has a range of WX0 to WX255. The result of SUMIFEQ(45, WX250, 10) would only include the values in WX250 through WX255, and Argument Out of Range (ST132) will be ON.


The following are the 6 variants of the Sum If math function:

SUMIFEQ - Sum If Equal to Expression

In the example below, D0 will sum the values from the locations in the range of D100 through D109 that contain a value that is equal to 45.

 


SUMIFNE - Sum If Not Equal to Expression

In the example below, D0 will sum the values from the locations in the range of D100 through D109 that contain a value that is not equal to 45.

 


SUMIFLT - Sum If Less Than Expression

In the example below, D0 will sum the values from the locations in the range of D100 through D109 that contain a value that is less than 45.

 


SUMIFLE - Sum If Less Than or Equal to Expression

In the example below, D0 will sum the values from the locations in the range of D100 through D109 that contain a value that is less than or equal to 45.

 


SUMIFGT - Sum If Greater Than Expression

In the example below, D0 will sum the values from the locations in the range of D100 through D109 that contain a value that is greater than 45.

 


SUMIFGE - Sum If Greater Than or Equal to Expression

In the example below, D0 will sum the values from the locations in the range of D100 through D109 that contain a value that is greater than or equal to 45.

 

 


See Also:

MATH - Calculate Expression

 

IF - If / Else Expression


SUMIFxx - Sum If (EQ, NE, LT, LE, GT, GE)

 

COUNTIFxx - Count If (EQ, NE, LT, LE, GT, GE)

 


Rung Example: