Switch Function

Avalía unha lista de argumentos, composta por unha expresión seguida dun valor. A función Switch devolve un valor asociado á expresión pasada por dita función.

Sintaxe:

Switch (Expresión1, Valor1[, Expresión2, Valor2[..., Expresión_n, Valor_n]])

Parámetros:

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.

Expresión: A expresión que se desexa avaliar.

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:

Códigos de erro

5 Chamada de procedemento incorrecta

Exemplo:

Sub ExampleSwitch

Dim sGender As String

    sXenero = ObtIndiceXenero( "Duarte" )

    MsgBox sGender

End Sub

 

Function GetGenderIndex (sName As String) As String

    ObtIndiceXenero = Switch(sNome = "Berta", "feminino", sNome = "Duarte", "masculino")

End Function