Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computing Dr. Nadeem A Khan. Lecture 21.

Similar presentations


Presentation on theme: "Introduction to Computing Dr. Nadeem A Khan. Lecture 21."— Presentation transcript:

1 Introduction to Computing Dr. Nadeem A Khan

2 Lecture 21

3 IF BLOCK EXTENDED IF condition 1 Then action1 ElseIf condition 2 Then action 2 action 2 ElseIf condition 3 Then action 3 Else action 4 End If

4 Select Case Blocks

5 ► Example: Sub Command1_Click ( ) Picture1.Cls Let num = Val(Text1.Text) Select Case num Case 1 Picture1.Print “Buckle my shoe.” Case 2 Picture1.Print “Pick the sticks.” Case 3,4,5,6 Picture1.Print “Lay them straight.” Case Else Picture1.Print “Start all over again.” End Select End Sub

6 Select Case Block ► General form Select Case selector Case valueList1 action1 Case valueList2 action2.. Case Else action of last resort End Select

7 Select Case Block (Contd.) ► See fig. 5.4:Flow Chart for Select Case block block

8 Another example

9 Sub Command1_Click ( ) Sub Command1_Click ( ) Dim x As Integer, y As Integer, num As Integer Let x=2 Let y=3 Let num = Val(Text1.Text) Select Case num Case y-x, x Picture1.Print “Buckle my shoe.” Case Is<=4 Picture1.Print “Pick up sticks.” Case x+y To x*y Picture1.Print “Lay them straight.” Case Else Picture1.Print “Start all over again.” End Select End Sub

10 Still another example

11 Sub Command1_Click ( ) Dim season As string Rem Determine the number of days in a season Picture1.Cls Let season = Text1.Text Picture1.Print season; “has”; NumDays(season);“days.” End Sub Select Case Block (Contd.)

12 Function NumDays (seasons As String) As Integer Select Case UCase$(season) Case “WINTER” NumDays = 87 Case “SPRING” NumDays = 92 Case “SUMMER”, “AUTUMN”, “FALL” NumDays = 93 End Select End Functions Select Case Block (Contd.)

13 ► Study chapter 5 with all its comments and examples. Solve some problems as well! Note:


Download ppt "Introduction to Computing Dr. Nadeem A Khan. Lecture 21."

Similar presentations


Ads by Google