CONDITIONAL STATEMENTS
IF Statement Allows your program to make decisions based on certain conditions.
1. If… Then Syntax:  If  condition  Then Statement/s End If
2. If… Then… Else Syntax:  If  condition  Then Statement/s Else Statement/s End If
IF… ELSEIF Statement If  1 st  condition   Then statement if the 1st condition is true ElseIf   2 nd  condition   Then statement if the 2nd condition is true   Else     statement if ALL conditions are false End If
Select Case Structure useful when you want to check a variable or an expression against multiple possible values
Syntax for  “ Select Case ” Select Case  expression or variable Case  range, constant, or variable ‘ Statements Case  range, constant, or variable ‘ Statements Case  range, constant, or variable ‘ Statements Case Else ‘ Statements End Select
Select Case lboColor.Text Case “red”, “purple”, “orange” lblRemark.Text = “This is a warm color.” Case “blue”, “green”, “blue violet” lblRemark.Text = “This is a cool color.” Case Else lblRemark.Text = “Please select a color.” End Case
Select Case Val(T xtAge .Text) Case 1 To 3 lblRemark .Text = "toddlerhood" Case 4 To 8 lblRemark .Text = "childhood" Case 9 To 12 lblRemark .Text = "preadolescence" Case 13 To 18 lblRemark .Text = "adolescence" Case 19 To 24 lblRemark .Text = "young adulthood" Case Is > 24 lblRemark .Text = "adulthood" Case Else lblRemark .Text = "infancy" End Select

Select Case

  • 1.
  • 2.
    IF Statement Allowsyour program to make decisions based on certain conditions.
  • 3.
    1. If… ThenSyntax: If condition Then Statement/s End If
  • 4.
    2. If… Then…Else Syntax: If condition Then Statement/s Else Statement/s End If
  • 5.
    IF… ELSEIF StatementIf 1 st condition Then statement if the 1st condition is true ElseIf 2 nd condition Then statement if the 2nd condition is true Else statement if ALL conditions are false End If
  • 6.
    Select Case Structureuseful when you want to check a variable or an expression against multiple possible values
  • 7.
    Syntax for “ Select Case ” Select Case expression or variable Case range, constant, or variable ‘ Statements Case range, constant, or variable ‘ Statements Case range, constant, or variable ‘ Statements Case Else ‘ Statements End Select
  • 8.
    Select Case lboColor.TextCase “red”, “purple”, “orange” lblRemark.Text = “This is a warm color.” Case “blue”, “green”, “blue violet” lblRemark.Text = “This is a cool color.” Case Else lblRemark.Text = “Please select a color.” End Case
  • 9.
    Select Case Val(TxtAge .Text) Case 1 To 3 lblRemark .Text = "toddlerhood" Case 4 To 8 lblRemark .Text = "childhood" Case 9 To 12 lblRemark .Text = "preadolescence" Case 13 To 18 lblRemark .Text = "adolescence" Case 19 To 24 lblRemark .Text = "young adulthood" Case Is > 24 lblRemark .Text = "adulthood" Case Else lblRemark .Text = "infancy" End Select