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!