MUX - Returns one of a set of values

Help Contents


The MUX function returns one value from a set of input values. An integer selector value chooses which value to return.


Informal Syntax:

MUX( K, In0, In1, ..., InX )

Formal Syntax:

MUX( K:=expression, In0:=expression, In1:=expression, ..., InX:=expression )


KANY_INTThe selector parameter.
In0ANYThe value to return if K equals 0 (zero).
In1ANYThe value to return if K equals 1 (one).
InXANYThe value to return if K equals X.

Return Value

If the value of K is less than 0 (zero), MUX returns the first parameter In0.

If the value of K is greater than the number of inputs, MUX returns the last parameter InX.

Otherwise, MUX returns the InX parameter.

Inputs In0 ... InX can be any type. The type of the return value is the "highest" type of the inputs In0 ... InX. For example if the input types are SINT and DINT, the return type of the function will be DINT.

See Automatic Type Promotion for further information.


ExampleReturn Value
MUX( 1, 'A', 'B', 'C' )STRING#'B'
MUX( K:=2, In0:=-5, In1:=0, In2:=10 )DINT#10

Standards Compliance

IEC 61131-3 Second Edition: Table 27.4.

IEC 61131-3 Third Edition: Table 32.6.

Note: The function allows the K parameter to be outside the range 0 to N-1. The IEC 61131-3 standard states this should be an error.

Further Information

Selection Functions

To learn about other selection functions.

Elementary Data Types

To learn about the different types supported by Fernhill SCADA.

Common Elements

To learn about other IEC 61131-3 Common Elements.


For the meaning of terms used in Fernhill SCADA.