Estructura de Selección en Visual Basic
Download
Report
Transcript Estructura de Selección en Visual Basic
Estructura de Selección en Visual
Basic
COMP 215
Definición
• La estructura de selección la utilizamos
cuando necesitamos programar el
computador para que, dependiendo del
cumplimiento o no de ciertas condiciones
dentro del programa, se ejecuten o no
instrucciones.
If Blocks
• If condition Then
action1
Else
action2
End If
Flowchart general
N
Execute action2
Is the condition
true?
T
Execute action1
ElseIf clauses
If condition1 Then
action1
ElseIf condition2 Then
action2
ElseIf condition3 Then
action3
Else
action4
End If
Ejemplo programación ElseIf
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gpa As Double
Dim honors As String
gpa = CDbl(TextBox1.Text)
If gpa >= 3.9 Then
honors = "summa cum laude..."
ElseIf gpa >= 3.6 Then
honors = "magna cum laude..."
ElseIf gpa >= 3.3 Then
honors = "cum laude..."
ElseIf gpa >= 2.0 Then
honors = "........."
Else
honors = "You don't graduated..."
End If
TextBox2.Text = gpa & " " & honors
End Sub
End Class
Select Case Block
Select Case selector
Case valueList 1
action1
Case valueList 2
action2
Case Else
action of last resort
End Select
Ejemplo programación Select Case
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gpa As Double
Dim honors As String
gpa = CDbl(TextBox1.Text)
Select Case gpa
Case Is >= 3.9
honors = "summa cum laude..."
Case Is >=3.6
honors = "magna cum laude..."
Case Is >= 3.3
honors = "cum laude..."
Case Is >=2.0
honors = "........."
Case Else
honors = "You don't graduated..."
End Select
TextBox2.Text = gpa & " " & honors
End Sub
End Class