This article will cover the syntax of the ‘switch’ control script statement

The switch statement is a logical statement. You can specify different execution scripts that run only when a given condition is met. Multiple conditions can be specified.

Statement syntax

Switch expression 
{case value list [ statements ]} 
[default statements] 
end switch


ExpressionThe expression result is what the value list compares against to decide how to execute.
Value listA comma separated list of values that will be compared to the result of the expression. Where the value matches the expression, the statement will be executed. If no matches exist, the default statement will be executed.
StatementsThe script executed by the statement.

Example

This example checks the date of a file and uses the ‘switch’ statement to log whether it is up to date. 

If FileTime('[lib://Public:DataFiles/ITEM_DETAILS.qvd]') < today() then
	Let a = 0;
Else 
	Let a = 1;
End if
Switch a
Case 0
	LOAD '$(a): the file is not up to date' as case autogenerate 1;
Case 1
	LOAD '$(a): the file is up to date' as case autogenerate 1;
Default
	LOAD '$(a): the file status is unknown, checks failed' as case autogenerate 1;
End Switch

Result

A table is generated with a field named ‘case’. The field contains a single row generated by the ‘switch’ statement to inform us that the file is not up to date.