Presentation is loading. Please wait.

Presentation is loading. Please wait.

The IfTest and Case Statement1 The IF Test A conditional statement that permits portions of code to be executed only if and when some special condition.

Similar presentations


Presentation on theme: "The IfTest and Case Statement1 The IF Test A conditional statement that permits portions of code to be executed only if and when some special condition."— Presentation transcript:

1 The IfTest and Case Statement1 The IF Test A conditional statement that permits portions of code to be executed only if and when some special condition applies. (If there is some beer, get me a bottle, otherwise get me a cola.) (If it is raining, bring an umbrella)

2 The IfTest and Case Statement2 IF Test If (Condition T/F) Then ’ (do true stuff) Else ’ (do false stuff) End If

3 The IfTest and Case Statement3 IF Test (short form) If (Condition T/F) Then ’ (do true stuff) End If (use only if there is nothing to do in the Else branch)

4 The IfTest and Case Statement4 IF Test Example (1) Private Sub cmdDo_Click() If cmdDo.Caption = "Talk" Then lblBox.Caption = "ding ding" cmdDo.Caption = "clear" Else lblBox.Caption = "" cmdDo.Caption = "Talk" End If End Sub

5 The IfTest and Case Statement5 IF Test Example (2) >

6 The IfTest and Case Statement6 IF Test Example (3) Private Sub cmdBlink_Click() If lblBox.Visible = True then lblBox.Visible = False Else lblBox.Visible = True End If End Sub Since lblBox.Visible is boolean why not use If lblBox.Visible then

7 The IfTest and Case Statement7 The CASE Statement (1) This statement can be used instead of repeated “IF” tests. It is clearer and nearly self documenting. The following example is probably the best way to illustrate it. It allows a multi-way choice between routing something to the northwest, the midwest or to some unknown area. Many more branches are possible.

8 The IfTest and Case Statement8 The CASE Statement (2) Private Sub cmdWhere_Click() Select Case txtState.Text Case "WA", "OR" lblOffTo.Caption = "Northwest" Case "IL", "WI", "MN", "IA" lblOffTo.Caption = "Midwest" Case Else lblOffTo.Caption = ”unknown" End Select End Sub

9 The IfTest and Case Statement9 The CASE Statement (3)


Download ppt "The IfTest and Case Statement1 The IF Test A conditional statement that permits portions of code to be executed only if and when some special condition."

Similar presentations


Ads by Google