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 (Expression1, Value1[, Expression2, Value2[..., Expression_n, Value_n]]) As Variant

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
    sGender = GetGenderIndex( "John" )
    MsgBox sGender
End Sub
 
Function GetGenderIndex (sName As String) As String
    ObtIndiceXenero = Switch(sNome = "Berta", "feminino", sNome = "Duarte", "masculino")
End Function

Precisamos da súa axuda!