Initializing help system before first use

VDL Expression Language Syntax

There are several basic rules to follow when using expression language.

Expressions are case sensitive, so Return and return refer to different objects.

The dot operator is used to access properties of objects. For example:
scenario.entities.TotalReturn.value
gives access to the entities property of the scenario object. This in turn is also an object, and the second dot provides access to the Return property of the entities object.

Array Access

Elements within an expression language array are accessed using square brackets, inside which the array index of the required element is specified (remember that array indices start at 0). Because array entities can have multiple indices, they cannot be treated as plain arrays; So when you de-reference an array entity within an expression (get an element using its index), you will need to call the array name as a function, passing the indices as parameters.
scenario.entities.MyArray(0).value
Warning: Usually, array elements will be referenced by looping over all the indices. It is unsafe to reference array elements directly without guarding the expression to firstly check that the element exists, by employing ternary expressions, such as:
<span vdl-text="=scenario.entities.MyArray(0) ? scenario.entities.MyArray(0).value : ''"></span>
For more on accessing array and other entities, see Entity Values and Labels.

Function Calls

Functions of the VDL expression language can be written inline or within script blocks.

Inline functions are written within an expression itself:
<vdl-validate pass="=function(entity,value) { return value > 100; }">
</vdl-validate>
Note For more on the <vdl-validate> element, see Using Validators.
Inline functions are appropriate if a function is simple and doesn't need to be shared. Another option is to write it in a script block:
<script>
function MyFunc (entity, value) {
    return value < 10;
}
</script>
<vdl-validate pass="=MyFunc"></vdl-validate>
This method provides more space in which to write what might be a more complex function, it can be read and understood more clearly and permits sharing with other elements if needed.

String Concatenation and Demarcation

You can use expressions to concatenate strings and returned entity values. Because an expression is enclosed in double quotes, use single quotes for strings within expressions:

View Designer

String concatenation in the View Designer

Code editor
<span vdl-text="='Calculated'+' '+'Optimal'+' '+'Return   '"></span>
The previous code snippet returns the value as 'Calculated Optimal Return'.

Key-value pairs

Several attributes take key-value pairs as their input. For example:
<div vdl-css="hilite: true, showing: false"></div>
The symbol before a colon is called a key, anything after it (up until the end of the attribute string or the next comma) is the value. These are treated as evaluated expressions. If a chosen key contains anything other than alphanumeric characters (a-z, A-Z and 0-9) then the key itself must be placed inside quotes. To avoid clashing with the attribute quotes, use single quotes:
<div vdl-css="'hilite-item': true, 'showing-item':false"></div>
Similarly, when the value is a string, for the same reason, enclose it in single quotes.

Arithmetic and Comparison (Boolean) Operators

A range of standard and boolean operators is available.
Operator Name Example
+ add 2+2 = 4
- unary negative -10
- subtract 12 - 7 = 4
* multiply 8 * 7 = 56
/ divide 20/4 = 5
% remainder 20 % 7 = 6
< less than 3 < 6
<= less than or equal to 5 <= 10
> greater than 17 > 1
>= greater than or equal to 20 >= 20
== roughly equal to 3 == '3'
!= roughly not equal to 4 != '4'
=== strictly equal 6 === 6
!== strictly not equal to 6 !== '6'
Note If in doubt, use the strict comparisons. Use of the roughly equal/not equal operators can lead to unexpected matches.

Logical Operators

The VDL expression language implements three logical operators.
Operator Name Example
! not !false === true
&& logical and True && !true === false
|| logical or false || true === true