Download presentation
Presentation is loading. Please wait.
Published byDelilah Parsons Modified over 9 years ago
1
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9
2
2 CC111 Lec9 : Visual Basic Controlling your Application Sequence Selection – If...Then...Else statement – Select Case statement Repititon – For...Next Loop statement – For Each...Next statement – Do Loops
3
3 CC111 Lec9 : Visual Basic Selection If..Then..Else If (condition) Then (statement[s]) [ElseIf (condition) Then (statement[s])] [Else (statement[s])]
4
4 CC111 Lec9 : Visual Basic Selection Application: Convert from Numerical Grade to Letter Grade Input: a numeric grade between 0 and 100 Output: depends on input InputOutput 0 49F 50 54D 55 59C- 60 64C 65 69C+ 70 74B- 75 79B 80 84B+ 85 89A- 90 94A 95 100A+
5
5 CC111 Lec9 : Visual Basic Selection Application Convert from Numerical Grade to Letter Grade (Form View) Letter_Grade_Calculator.exe
6
6 CC111 Lec9 : Visual Basic
7
7 Selection Application: Convert from Numerical Grade to Letter Grade (Code View) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If (ComboBox1.SelectedIndex = 0) Then Label2.Text = "F" End If If (ComboBox1.SelectedIndex = 1) Then Label2.Text = "D" End If If (ComboBox1.SelectedIndex = 2) Then Label2.Text = "C-" End If If (ComboBox1.SelectedIndex = 3) Then Label2.Text = "C" End If If (ComboBox1.SelectedIndex = 4) Then Label2.Text = "C+" End If If (ComboBox1.SelectedIndex = 5) Then Label2.Text = "B-" End If If (ComboBox1.SelectedIndex = 6) Then Label2.Text = "B" End If If (ComboBox1.SelectedIndex = 7) Then Label2.Text = "B+" End If If (ComboBox1.SelectedIndex = 8) Then Label2.Text = "A-" End If If (ComboBox1.SelectedIndex = 9) Then Label2.Text = "A" End If If (ComboBox1.SelectedIndex = 10) Then Label2.Text = "A+" End If End Sub
8
8 CC111 Lec9 : Visual Basic Selection Application Convert from Numerical Grade to Letter Grade (Run)
9
9 CC111 Lec9 : Visual Basic For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if less than end. If so, repeat loop again. If not, go to statement after Next.
10
10 CC111 Lec9 : Visual Basic Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)
11
11 CC111 Lec9 : Visual Basic Factorial Flowchart (N>0)
12
12 CC111 Lec9 : Visual Basic Factorial Application: Form View Factorial.exe
13
13 CC111 Lec9 : Visual Basic Factorial Application: Code View Using For..Next Loop Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n As Integer Dim m As Integer Dim f As Integer n = Val(TextBox1.Text) f = 1 For m = 1 To n Step 1 f = f * m Next m Label2.Text = "Factorial=" + Str(f) End Sub
14
14 CC111 Lec9 : Visual Basic Factorial Application: Run
15
15 CC111 Lec9 : Visual Basic Do While...Loop Structure Do While condition statements Loop Where The condition is tested, and if true the loop is repeated. When the condition is false, the statements are skipped after Loop is executed.
16
16 CC111 Lec9 : Visual Basic Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)
17
17 CC111 Lec9 : Visual Basic Factorial Application: Form View
18
18 CC111 Lec9 : Visual Basic Factorial Application: Code View Using Do..While..Loop Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n As Integer Dim m As Integer Dim f As Integer n = Val(TextBox1.Text) f = 1 m = 1 Do While m <= n f = f * m m = m + 1 Loop Label2.Text = "Factorial=" + Str(f) End Sub End Class
19
19 CC111 Lec9 : Visual Basic Do Until...Loop Structure Do Until condition statements Loop Where The condition is tested, and if false the loop is repeated. When the condition is true, the statements are skipped after Loop is executed.
20
20 CC111 Lec9 : Visual Basic Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)
21
21 CC111 Lec9 : Visual Basic Factorial Application: Form View
22
22 CC111 Lec9 : Visual Basic Factorial Application: Code View Using Do..Until..Loop Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim n As Integer Dim m As Integer Dim f As Integer n = Val(TextBox1.Text) f = 1 m = 1 Do Until m > n f = f * m m = m + 1 Loop Label2.Text = "Factorial=" + Str(f) End Sub
23
23 CC111 Lec9 : Visual Basic Factorial Application: Run
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.