Está en la página 1de 2

Estas estructuras se utilizan cuando se requiere una respuesta alternativa a

una condición.

IF … ELSE … END IF SELECT CASE


Select Case Variable
Case Valor1
If Expresion Condicional Then
[ Sentencias ]
[ Sentencias 1 ]
Case Valor2
Else
[ Sentencias ]
[ Sentencias 2 ]
Case Else
End If
[ Sentencias ]
End Select

Utiliza operadores comparativos: Para comparar un texto


1. And Case “Abril”
2. Or Para igualar un número
3. Not Case 1
Para comparar un número
If Total > 1000 And p = "pagó" Then Case Is >10
If Total > 1000 Or p = "pagó" Then Para comparar un rango
If Not (Precio <= 1000) Then Case 1 to 10

Ejemplos
Sub IF_ELSE_ENDIF() Sub SELECT_CASE()
Dim x As Integer Dim x As Integer
x = InputBox("Ingrese su edad") x = InputBox("Ingrese su edad")
If x >= 18 Then Select Case x
MsgBox "MAYOR DE EDAD" Case Is >= 18
Else MsgBox "Mayor de edad"
MsgBox "MENOR DE EDAD"
End If Case Else
End Sub MsgBox "Menor de edad"

End Select
End Sub

Prof. Susan Cornejo Apaza


Sub IF_ELSEIF() Sub SELECT_CASE()
Dim x As Integer Dim x As Integer
x = InputBox("Ingrese su edad") x = InputBox("Ingrese su edad")
Select Case x
If x >= 1 And x <= 14 Then Case 1 To 14
MsgBox "Niño" MsgBox "Niño"
ElseIf x >= 15 And x <= 20 Then Case 15 To 20
MsgBox "Adolescente" MsgBox "Adolescente"
ElseIf x >= 21 And x <= 70 Then Case 21 To 70
MsgBox "Adulto" MsgBox "Adulto"
Else Case Else
MsgBox "Anciano" MsgBox "Anciano"
End If End Select
End Sub End Sub

Prof. Susan Cornejo Apaza

También podría gustarte