Back to Adaptive Vision Studio website

You are here: Start » Filter Reference » Conditional Processing » MergeDefault

MergeDefault


Copies an object from a conditional input to an non-conditional output, replacing Nil with a predefined default value.

Name Type Description
inConditionalObject <T>? Input conditional object
inDefaultObject <T> Object to be used if the conditional object is empty
outObject <T> Value of the conditional object, if it exists, or the default otherwise

The type of this filter is defined using the type variable T which represents any valid type. Read more.

Applications

Usually used to create a definite result for the special cases represented by the Nil value.

Description

This filter is a tool of the Conditional Execution mechanism. It receives a conditional value and:

  • if it is Nil, replaces it with a specified default value;
  • otherwise, copies the input value to the output.

Hints

  • Connect a conditional value to the inConditionalObject input.
  • On the inDefaultObject input define a value that will be substituted for Nil on the inConditionalObject input.
  • Also consider the coalescing operator (??) in Formula Blocks.
  • Also consider using a Variant Step macrofilter with two variants: "Nil" and "default". This may be more elegant and also faster.

Examples

Description of usage of this filter can be found in examples and tutorial: OCR text validation.

Here is a simple demonstration how this filter works, replacing Nil with 0:

inConditionalObject = 5
inDefaultObject = 0
outObject = 5
inConditionalObject = Nil
inDefaultObject = 0
outObject = 0

MergeDefault filter can be used to replace a numeric display in HMI with a label indicating a reading error, such as "(unknown)" or "N/A". Here, we are reading some value from an XML node. If it cannot be parsed (e.g. because there is incorrect syntax), then a special text will be displayed instead.

Remarks

This filter is a counterpart of the IFERROR function from Microsoft Excel.

This filter can be replaced with the following formula:

Complexity Level

This filter is available on Basic Complexity Level.

See Also

  • MakeConditional – Checks a condition and: if the condition is True, then it copies the input object to the output; otherwise returns Nil.
  • MergeBranches – Chooses the first non-Nil object, or reports an error if there is no such object.
  • MergeIntoArray – Creates an array from all the non-Nil input elements.