The Switch() Function
The Switch() function is a slight variation of the Choose() function. The Switch() function uses pairs of test conditions and return values. The first parameter is an expression to test and the second parameter is a result value that is returned if the expression is true. This is repeated with every two parameters being in one group.
The syntax for the Switch() function is as follows:
This function can return any data type except for an array. The data types of each result must be the same.
What makes this unique from the If Then and Select statements is that every parameter is evaluated before a result is returned from the function. Even if the first parameter is true, all the remaining parameters are still evaluated. This can have good or bad consequences depending upon your needs. The result can be bad because there could be a performance issue if you are passing it time-intensive functions. It could also result in an error being raised if every condition wasn’t meant to be evaluated (e.g. divide by zero errors).
Executing every line can be good if you want to force various functions to be called prior to returning a value. For example, it can perform a list of financial functions prior to returning a value.