1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Practical Programming COMP153-08S Lecture: Repetition Continued.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Control Structures: Part 1. Introduction Control Structures If / Then Selection Structure If / Then / Else Selection Structure While Repetition Structure.
More on lists, exceptions, loops and validation. You can use the exception to indicate the error that occurred Private Sub btnCheck_Click(ByVal sender.
5.05 Apply Looping Structures
Illuminating Computer Science CCIT 4-6Sep
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Lecture 8 Visual Basic (2).
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
ENGR 112 Decision Structures.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Tutorial 6 The Repetition Structure
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
MULTIPLE ALTERNATIVES IF… THEN… ELSEIF SELECT CASE.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
Problem Solving with Decisions
PRACTICE SAC 1 Some solutions. 'inputs 'sale price 'postcode 'coupon codes 'processing 'calculate commissions (commission based on cost) 'calculate postage.
Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Controlling Program Flow with Looping Structures
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Practical Programming COMP153-08S Lecture: Repetition.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
Introduction to Computer CC111 Week 10 Visual Basic 3 1.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Chapter 5 - VB 2008 by Schneider1 Chapter 5 – Repetition 5.1 Do Loops 5.2 Processing Lists of Data with Do Loops 5.3 For...Next Loops.
Computer Science Up Down Controls, Decisions and Random Numbers.
Use TryParse to Validate User Input
Visual Basic Fundamental Concepts
UNIT 5 Lesson 15 Looping.
Chapter 5- Control Structures: Part 2
Visual Basic 6 (VB6) Data Types, And Operators
UNIT 4 Lesson 13 If statements.
Data Types 1.
Lists, Loops, Validation, and More
Control Structures: Part 2
Use TryParse to Validate User Input
Introduction to VB programming
Chapter 5 – Control Structures: Part 2
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
للمزيد زورونا على موقعنا الإلكتروني:
Control Structures: Part 1
Visual Basic..
Boolean Expressions and If statements
حلقات التكرار.
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Input and Output.
Fundamentals of visual basic
Case & Repetitive Statements
Input and Output Chapter 3.5
GUI Programming in Visual Studio .NET
Presentation transcript:

1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9

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 CC111 Lec9 : Visual Basic Selection If..Then..Else If (condition) Then (statement[s]) [ElseIf (condition) Then (statement[s])] [Else (statement[s])]

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 CC111 Lec9 : Visual Basic Selection Application Convert from Numerical Grade to Letter Grade (Form View) Letter_Grade_Calculator.exe

6 CC111 Lec9 : Visual Basic

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 CC111 Lec9 : Visual Basic Selection Application Convert from Numerical Grade to Letter Grade (Run)

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 CC111 Lec9 : Visual Basic Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)

11 CC111 Lec9 : Visual Basic Factorial Flowchart (N>0)

12 CC111 Lec9 : Visual Basic Factorial Application: Form View Factorial.exe

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 CC111 Lec9 : Visual Basic Factorial Application: Run

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 CC111 Lec9 : Visual Basic Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)

17 CC111 Lec9 : Visual Basic Factorial Application: Form View

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 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 CC111 Lec9 : Visual Basic Loops Application: Factorial Factorial (N)= N*(N-1)*(N-2)……….*(1)

21 CC111 Lec9 : Visual Basic Factorial Application: Form View

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 CC111 Lec9 : Visual Basic Factorial Application: Run