Collabora Office 24.04 Help
뒤에 값이 오는 식으로 구성된 인수 목록을 평가합니다. Switch 함수는 자신이 전달한 식과 연관된 값을 구합니다.
Switch (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]]) As Variant
Switch 함수는 왼쪽에서 오른쪽으로 식을 평가한 다음 함수 식에 할당된 값을 구합니다. 식과 값이 쌍으로 제공되지 않을 경우 런타임 오류가 발생합니다.
Expression: 평가할 식입니다.
Value: 식이 True일 경우 구할 값입니다.
다음의 예에서 Switch 함수는 전달된 이름에 적절한 성별을 할당합니다.
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