Sequentially evaluate the expressions in an expression/value list and return the associated value for the first expression whose result is not False (non-zero).
Switch ( expr1, value1 [ , expr2, value2 … [, expr-n, value-n ] ] )
expr-n -
Specifies a set of matched expression-value pairs. The expression is evaluated and if the result is True (non-zero), the associated value is returned. If False, the next expression is evaluated. Each expression is tested from left-to-right. All expressions and values are evaluated, even though only one of them may be returned. This can become important if the expressions or values have unexpected side effects.
value-n - (Input, expression, One required for every expression)
Specifies the value to return if the corresponding expression is True (non-zero).
If any of the expressions evaluate to True (non-zero), the corresponding value is returned. If all expressions are False, Null is returned
Null can also be returned if an expression evaluated to True, and its corresponding value is Null).
Error is returned if there is an odd number of parameters, or if the expression being tested is non-numeric
Switch (1 < 2, 55, 2 < 3, 66) |
Returns 55 |
Switch (1 > 2, 55, 2 < 3, 66) |
Returns 66 |
Switch (1 > 2, 55, 2 > 3, 66) |
Returns Null |
Switch (“aaa”, “aaa” ,“123”, “123”) |
Returns 123 |
Switch (Null, 55) |
Returns Error |
Switch (Error, 55) |
Returns Error |
Functions are specifically for use in the Macro Editor. Refer to Microsoft's official VB and JScript documentation for scripting equivalents.
Functions | Choose function | Description function | Iff function | In function | Lookup function | Switch function | Value function
© 2004-2021 looksoftware. All rights reserved.