Switch Function

Evaluates a list of arguments, consisting of an expression followed by a value. The Switch function returns a value that is associated with the expression that is passed by this function.

แƒกแƒ˜แƒœแƒขแƒแƒฅแƒกแƒ˜

Switch (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]])

Parameters:

The Switch function evaluates the expressions from left to right, and then returns the value that is assigned to the function expression. If expression and value are not given as a pair, a runtime error occurs.

Expression1, Expression2: แƒœแƒ”แƒ‘แƒ˜แƒกแƒ›แƒ˜แƒ”แƒ แƒ˜ แƒชแƒ˜แƒคแƒ แƒฃแƒšแƒ˜ แƒกแƒ˜แƒ“แƒ˜แƒ“แƒ”แƒ”แƒ‘แƒ˜ แƒแƒœ แƒกแƒขแƒ แƒ˜แƒฅแƒแƒœแƒ”แƒ‘แƒ˜, แƒ แƒแƒ›แƒšแƒ”แƒ‘แƒ˜แƒช แƒ’แƒ˜แƒœแƒ“แƒแƒ— แƒจแƒ”แƒแƒ“แƒแƒ แƒแƒ—.

Value: The value that you want to return if the expression is True.

In the following example, the Switch function assigns the appropriate gender to the name that is passed to the function:

Error codes:

D'oh! You found a bug (text/sbasic/shared/00000003.xhp#err5 not found).

แƒ›แƒแƒ’แƒแƒšแƒ˜แƒ—แƒ˜:

Sub ExampleSwitch

Dim sGender As String

    sGender = GetGenderIndex( "John" )

    MsgBox sGender

End Sub

 

Function GetGenderIndex (sName As String) As String

    GetGenderIndex = Switch(sName = "Jane", "female", sName = "John", "male")

End Function