Overview
Expressions are plain VB.NET statements, such as arithmetic expressions or calls to script.class
methods from the project, executed according to the Trigger or execution settings. IntelliSense only shows tags and application objects, but the standard VB.NET compiler is the one that compiles expressions. Whatever you write in the code editor should also be accepted in expressions.
Configurating Script Expressions
Besides the table in Script / Expressions, you can use expressions in several other places using the syntax described here to determine a value or configure a condition. The following is a list of recommendations when using expressions:
- Our platform implements automated replacements, such as "==" to "=". The syntax of an expression is close to a C# statement but without a need to add the semicolon “;” at the end. Therefore, VB.NET and C# programmers can use the expression fields seamlessly.
- You do not need to put an "@" before tag names in expressions. Instead, insert the "@" in the code editor to differentiate your Tags from .NET variables. However, expressions do not have local .NET variables, so you use the solution object directly.
- Use the standard operands described in the .NET documentation for arithmetic operands.
Evaluation methods
The platform has two methods for single-line evaluation, they are as follows:
The IIF method, which currently is used only with VB.Net, has three parameters:
IIF (A, B, C)
the first being a condition. This method will return B if condition A is true and C if the condition is false. For example:IIF (tag.A = 1, "True", "False")
The code above will return the string
True
if the value of thetag.A
is 1, orFalse
iftag.A
has a different value.
In this .NET method, all three parameters are evaluated regardless of the condition. For instance, given the following code:IIF (tag.A = 1, script.class.client.Func1(), script.class.client.Func2())
Both
Func1
andFunc2
will always be executed. Only the return value will be different based on the value oftag.A
The TIF method should be used when you want to execute only the function according to the value. For example, given the following code:
TIF (tag.A = 1, script.class.client.Func1(), script.class.client.Func2())
Only the
Func1()
orFunc2()
will be executed, according the value ofTag.A.
The TIF method is defined in the class library that is automatically exposed to 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 earlier in this chapter.
Adding Script Expressions
Go to Scripts → Expressions.
Select an expression, or select the insert row (first blank row) to create a new expression.
Enter or select information, as needed.
Script Expressions Configuration Properties | |
---|---|
Field | Description |
Object | Select an existing tag or object. |
Expression | Enter the expression. The expression can be a basic mathematical expression, a class, or a conditional expression. |
Domain | Select where the expression executes:
The creation of Expressions on Domain Client is restrict by default, in order to ensure compatibility with Web (HTML5) Clients, which don't execute the expressions configured here. You can modify that setup on Solution → Settings. |
Execution | Select when the expression executes:
|
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. |
Time | Specify the time when the expression runs. |
Label | Set a label to the specified class. |
BuildMessages | Return the message status after the expression runs |
BuildStatus | Read-only. Set after you click Verify.
|
BuildErrors | Read-only. Displays any errors encountered during the last build. |
Managing External References
If you need references to your own assemblies, you can use Scripts References.
As a fully compliant .NET application, you can find free source code to use, including .NET components, products, and libraries. You can also use your own libraries.
In this section...