Sometimes you may want to restrict the values that can be stored in a variable.
For example, you may want to limit an “Age” variable so it only holds values in the range of 0 to 100.
Similarly, you may want to ensure that a File Path variable only holds values with a certain file extension.
To add a constraint to a variable, look for the “Constraints” tab when creating or editing a variable.
Taking the example above, suppose we want to restrict this variable so it can only hold Excel files (i.e. files with the extensions “xls” or “xlsx”).
We can achieve this by adding a constraint like so:
Once a constraint is applied to a variable it will be checked whenever an attempt is made to change the value of the variable.
Similarly, the “Set Variable” module will also enforce the constraints when changing a variable value.
In the case of the file extension example above, when the user attempts to select a file, the open file dialog is automatically filtered according to the constraint: