Configuring Expressions
Besides the Edit > Script > Expressions table, in several places in FactoryStudio, you can use expressions, using the same syntax described here, to determine a value or to configure a condition.
Expressions are just plain
VB.NET expressions, such as arithmetic expressions or calls to script.class methods from the project. Intellisense only shows tags and application objects, but the expressions are compiled using the standard VB.Net compiler, so what you would write in the code editor, should be accepted in expressions as well.
FactoryStudio implements some automated replacements, such as == to =, so the syntax of an expression is also very close the a C# statement, but with no need to add the “;” on the end.
In this way, both VB.NET and C# programmers are able to use seamless the expression fields.
In expressions, you do not need to put @ before that tag names. You need the @ in the code editor to differentiate project tags from .NET variables. However, expressions do not have local .NET variables, so you use the project object directly.
For arithmetic operands, you can use the standard operands as described in the .NET documentation.
To allow single-line evaluations, the .NET language has the IIF command, which currently is used only with IF. The IF command has three parameters. For example:
IF (A, B, C)
The first parameter is a condition. That method will return B if condition A is true, and it returns C if the condition is false.
Example: If (tag.A = 1, "True", "False") will return a string according the value of tag.A.
In this .NET method, all three parameters are evaluated independent of the condition. For instance, if you have IF (tag.A = 1, script.class.client.Func1(), script.class.client.Func2()), both Func1 and Func2 will always be executed. Only the return value will be different based on the value of tag.A.
The IF or IIF method needs to evaluate the parameters before calling the method. There are many scenarios where you want to execute only the function according the value.
For that scenario FactoryStudio has a method called TIF, which has that behavior.
So, you use the expression:
TIF (tag.A = 1, script.class.client.Func1(), script.class.client.Func2())
Only the Func1() or Func2() will be executed, according the value of Tag.A
The TIF method is defined in the class library that is automatically exposed for expressions that are in the toolkit function library.
For more complex calculations, you can call a class that you create on the Classes tab. See
Configuring Classes.
To configure expressions:
1. Go to Edit > Scripts > Expressions.
2. Enter or select information, as needed.
Column | Description |
Object | Select an existing tag or object. |
Expression | Enter the expression. The expression can be basic mathematical expression, use a class, or a conditional expression. |
Domain | Select where the expression executes: •Client—Expression executes on each client system. These are expressions that apply locally (on the user’s computer), for example, report generation. •Server—Expression executes on the server system. These are expressions that apply across the application, that is, globally. |
Execution | Select when the expression executes: •OnChange—The expression executes when the value of any tag in the expression changes. •TriggerOrPeriod—The expression executes when the trigger event occurs or when the interval set in the Period elapses. •ChangeOrStartup—The expression executes when the value of any tag in the expression changes or at startup. |
Trigger | Enter or select the tag or object that triggers the expression execution. The expression executes when the value of the object changes. |
DisableCondition | Enter or select the tag or object that disables the expression execution. |
BuildStatus | Read-only. Set after you click Verify. •Green check mark—Expression runs without errors. •Red X—Expression has errors. |
BuildErrors | Read-only. Displays any errors encountered during the last build. |
3. Click Verify to check the validity of the expression.