Switch Function

λ€μ κ°μ΄ μ€λ μμΌλ‘ κ΅¬μ±λ μΈμ λͺ©λ‘μ νκ°ν©λλ€. Switch ν¨μλ μμ μ΄ μ λ¬ν μκ³Ό μ°κ΄λ κ°μ κ΅¬ν©λλ€.

Syntax:

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

Parameters:

Switch ν¨μλ μΌμͺ½μμ μ€λ₯Έμͺ½μΌλ‘ μμ νκ°ν λ€μ ν¨μ μμ ν λΉλ κ°μ κ΅¬ν©λλ€. μκ³Ό κ°μ΄ μμΌλ‘ μ κ³΅λμ§ μμ κ²½μ° λ°νμ μ€λ₯κ° λ°μν©λλ€.

Expression: νκ°ν  μμλλ€.

Value: μμ΄ TrueμΌ κ²½μ° κ΅¬ν  κ°μλλ€.

λ€μμ μμμ Switch ν¨μλ μ λ¬λ μ΄λ¦μ μ μ ν μ±λ³μ ν λΉν©λλ€.

Error codes:

5 μλͺ»λ νλ‘μμ  νΈμΆμλλ€.

Example:

``````
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
``````