Decision component enables users to specify a condition or a set of conditions, which if satisfied are either considered as true, otherwise false. It enables users to automate the process of decision making.
Decision component supports the following functions and operators.
A value is a terminal token representing a concrete element. This can be:
a floating point number
a date time
They are represented using numbers.
They are evaluated as
Floating point numbers
dot to define the decimal part.
They are evaluated as
You can use the
e to define power of ten (10^).
1.22e11e2 1e+2 1e-2 .1e-2 1e10
They are evaluated as
Dates and Times
Must be enclosed between
#2008/01/31# // for en-US culture
The are evaluated as
DateTime. NCalc uses the current Culture to evaluate them.
Booleans can be either
Any character between single quotes
' are evaluated as
You can escape special characters using \, `'
A parameter as a name, and can be optionally contained inside
2 + x, 2 + [x]
A function is made of a name followed by braces, containing optionally any value as arguments. Abs(1), doSomehting(1, 'dummy')
Expressions can be combined using operators. Each operator as a precedence priority. Here is the list of those expression's priority.
These operators can do some logical comparison between other expressions:
true or false
and operator has more priority than the
or, thus in the example above, false and true is evaluated first.
Relational operators are used to compare values. These operators always result in a boolean value.
- =, ==, !=, <>
- <, <=, >, >= 1 < 2
The additive operators are used for addition and string concatenation (+) and subtraction (-). The additive operators appear in additive expressions.
- +, - 1 + 2 – 3
The multiplicative are used for multiplication (*), division (/), and the remainder operation (%). The multiplicative operators appear in multiplicative expressions.
- *, /, %
- 1 * 2 % 3
Decimal numbers are natural to humans. Binary numbers are native to computers. Binary, octal, decimal, or hexadecimal symbols are only notations of the same number. Bitwise operators work with bits of a binary number.
- & (bitwise and), | (bitwise or), ^(bitwise xor), << (left shift), >>(right shift) 2 >> 3
Unary operator that takes a single operand in an expression or a statement.
- !, not, -, ~ (bitwise not) not true
Two primary operators let you specify structure and union members. The dot (a period) and arrow (formed by a minus and a greater than symbol) operators are always preceded by a primary expression and followed by an identifier.
- (, )
- values 2 * ( 3 + 2 )
The framework includes a set of already implemented
|Abs||Returns the absolute value of a specified number.||Abs(-1)||1M|
|Acos||Returns the angle whose cosine is the specified number.||Acos(1)||0d|
|Asin||Returns the angle whose sine is the specified number.||Asin(0)||0d|
|Atan||Returns the angle whose tangent is the specified number.||Atan(0)||0d|
|Ceiling||Returns the smallest integer greater than or equal to the specified number.||Ceiling(1.5)||2d|
|Cos||Returns the cosine of the specified angle.||Cos(0)||1d|
|Exp||Returns e raised to the specified power.||Exp(0)||1d|
|Floor||Returns the largest integer less than or equal to the specified number.||Floor(1.5)||1d|
|IEEERemainder||Returns the remainder resulting from the division of a specified number by another specified number.||IEEERemainder(3, 2)||-1d|
|Log||Returns the logarithm of a specified number.||Log(1, 10)||0d|
|Log10||Returns the base 10 logarithm of a specified number.||Log10(1)||0d|
|Max||Returns the larger of two specified numbers.||Max(1, 2)||2|
|Min||Returns the smaller of two numbers.||Min(1, 2)||1|
|Pow||Returns a specified number raised to the specified power.||Pow(3, 2)||9d|
|Round||Rounds a value to the nearest integer or specified number of decimal places. The mid number behavior can be changed by using EvaluateOption.RoundAwayFromZero during construction of the Expression object.||Round(3.222, 2)||3.22d|
|Sign||Returns a value indicating the sign of a number.||Sign(-10)||-1|
|Sin||Returns the sine of the specified angle.||Sin(0)||0d|
|Sqrt||Returns the square root of a specified number.||Sqrt(4)||2d|
|Tan||Returns the tangent of the specified angle.||Tan(0)||0d|
|Truncate||Calculates the integral part of a number.||Truncate(1.7)||1|
It also includes other general purpose ones.
|in||Returns whether an element is in a set of values.||in(1 + 1, 1, 2, 3)||true|
|If||Returns a value based on a condition.||if(3 % 2 = 1, 'value is true', 'value is false')||'value is true'|
Decision component exposes Control In and Control Out ports by default and dynamically created Data In ports.
|Control In||Must be connected to the Control Out port of one or more components.|
|Control Out||Must be connected to the Control In port of any other component. The Decision component exposes the following two types of Control Out ports:
|Data In||Can be connected to the Data Out port of another component from where the data is to be collected for the variable in the
This port is dynamically created with the name of the variable provided in the Decision component.
To edit the properties of the
Decision component, in the lower-right pane, change the required property. This is required to select the action to be performed using the Decision component.
Users can edit the following properties:
|Search||Search for the respective property.|
|Delay After Execution||Specifies the wait time (in seconds) after the action is executed.|
|Delay Before Execution||Specifies the wait time (in seconds) before the action is executed.|
|Name||Specifies the name for the Decision component.
Set the name to match the application field the user is interacting with.
Let us consider an example of deciding if a number is greater than or equal to 40.
To use the
Decisioncomponent and drop it on the Design surface.
Below the title bar, enter a logical condition. For example, the condition, x>=40. A Data In port is dynamically created with the name of the variable provided in the Decision Text Box.
For this example, lets add a number to define the value of 'X' and see whether the condition is satisfied. To execute the action, the user must add the Variable component.
To add the Variable component:
Variablecomponent and drop it on the Design surface.
Variablecomponent, and enter a number.
The user must also add two MessagBox
Showcomponents to display a success and a failure notification in case the decision fails to satisfy the condition.
To add the MessageBox
Showcomponent and drop it on the Design surface.
Showcomponent text box, and enter the success message.
Repeat the same steps by adding another
Showcomponent to add a failure message.
Control Outport of the Start component to the
Control Inport of the
Control Outport of the
Variablecomponent with the
Control Inport of the
Data Outport of the
Variablecomponent to the
Data Inport of the
True Control Outport of the
Decisioncomponent with the pass
False Control Outport of the
Decisioncomponent with the fail
In the toolbar, click
If the condition is successfully satisfied, the success message is displayed.
If the condition is not satisfied, the failure message is displayed.