Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

8.11 Switch

The Switch() Function

The Switch() function is also like a shortcut for the If statement and the Select Case statement. The parameters are grouped in pairs. The first parameter is an expression to test and the second parameter is a result value that is returned if the expression is true.

The syntax for the Switch() function is as follows:

Var = Switch(condition1, result1, condition2, result2, ….)

What makes this unique from the If and Select Case statements is that every parameter is evaluated before a result is returned from the function. This can have good or bad results depending upon your needs. The result can be bad because there could be a performance issue if you are passing time-intensive functions as parameters or it could result in an error being raised. It can be good if you want to force various functions to be called prior to returning a value.. This function can return any data type except for an array. The data types of each result must be the same.