Visual Basic 2010 How to Program © 1992-2011 by Pearson Education, Inc. All Rights Reserved.

Slides:



Advertisements
Similar presentations
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
Advertisements

 Control structures  Algorithm & flowchart  If statements  While statements.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection Statement 4.6 if else Selection Statement 4.7 while.
Control Structures: Part 1. Introduction Control Structures If / Then Selection Structure If / Then / Else Selection Structure While Repetition Structure.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.
Problem Solving and Control Statements. Using Exit to Terminate Repetition Statements There are many forms of the Exit statement, designed to terminate.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1B) UTPA – Fall 2011.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #4 Control Statements – Part 1.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved. 1.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Introduction to Problem Solving and Control Statements.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Introduction to Computers and Programming Lecture 7:
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
 2003 Prentice Hall, Inc. All rights reserved. 1 Will not cover 4.14, Thinking About Objects: Identifying Class Attributes Chapter 4 - Control Structures.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 4 Select … Case Multiple-Selection Statement & Logical Operators 1 © by Pearson Education, Inc. All Rights Reserved. -Edited By Maysoon.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Selection Using IF THEN ELSE CASE Introducing Loops.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (while) Outline 3.7The While Repetition.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.-Edited By Maysoon Al-Duwais1.
while Repetition Structure
Visual Basic 6 (VB6) Data Types, And Operators
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Problem Solving and Control Statements: Part 2
Visual Basic 2010 How to Program
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
JavaScript: Control Statements I
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Chapter 3: Introduction to Problem Solving and Control Statements
3 Control Statements:.
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 6 Control Statements: Part 2
Introduction to Problem Solving and Control Statements
Problem Solving and Control Statements
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Chapter 4 Select…Case Multiple-Selection Statement & Logical Operators
Presentation transcript:

Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.

 Simple If Conditions: if condition then statement End if  If else as follows: If TextBox1.Text >= 60 Then lblGrade.Text = "Pass" Else lblGrade.Text = "Fail" End If © by Pearson Education, Inc. All Rights Reserved.

 Visual Basic provides Logical operators that can combine multiple Boolean expressions into a compound expression OperatorEffect AndCombines two expressions into one. Both expressions must be true for the overall expression to be true. OrCombines two expressions into one. One or both expressions must be true for the overall expression to be true. It is only necessary for one to be true, and it does not matter which. XorCombines two expressions into one. One expression (not both) must be true for the overall expression to be true. If both expressions are true, or both expressions are false, the overall expression is false. NotReverses the logical value of an expression: makes a true expression false and a false expression true.

◦ Performing a Calculation in a Do While … Loop Repetition Statement  Consider a program segment designed to find the first power of 3 larger than 100.Suppose that the Integer variable product is initialized to 3.  When the following Do While … Loop statement finishes executing, product contains the result: Do While product <= 100 product = product * 3 Loop © by Pearson Education, Inc. All Rights Reserved.

◦ While … End While Repetition Statement  The While…End While repetition statement behaves identically to the Do While … Loop repetition statement, so their activity diagrams are also identical.  For consistency, you should choose one or the other.In this book, we use the Do While … Loop statement.  The following While … End While statement reimplements the preceding Do While … Loop :  While product <= 100 product = product * 3 End While © by Pearson Education, Inc. All Rights Reserved.

◦ Do Until … Loop Repetition Statement  Unlike the preceding repetition statements, the Do Until…Loop repetition statement executes its body statement(s) repeatedly as long as the condition (known as the loop-termination condition) evaluates to false.  You can write the preceding Do While … Loop statement as a Do Until … Loop statement as follows:  Do Until product > 100 product = product * 3 Loop © by Pearson Education, Inc. All Rights Reserved.

◦ Do Until … Loop Repetition Statement  Because we’re using a Do Until … Loop statement, the statement’s action is performed when the statement’s loop- termination condition is false (that is, product is less than or equal to 100 ).  When the loop-termination condition ( product > 100, the leftmost guard condition) is true, the statement exits.If the condition in a Do Until … Loop is initially true, the body statement(s) do not execute. © by Pearson Education, Inc. All Rights Reserved.

 To illustrate how algorithms are developed, we solve a problem that averages student grades.  Consider the following problem statement: ◦ A class of students took a quiz. The grades (integers in the range 0 to 100) for this quiz are available to you. Determine the class average on the quiz.  The class average is equal to the sum of the grades divided by the number of students. © by Pearson Education, Inc. All Rights Reserved.

◦ GUI for the Class-Average Application  Figure 4.10 shows this application’s GUI.  For this example, we introduce the ListBox control, which we use to display the grades the user enters and to manipulate those grades to perform the class-average calculation.  Each grade that the user enters into the program by pressing the Submit Grade Button is placed in the ListBox.  We calculate the class average when the user presses the Calculate Average Button.  We also provide a Clear Grades Button to remove all the grades from the ListBox and clear the results, so the user can enter a new set of grades. © by Pearson Education, Inc. All Rights Reserved.

◦ Setting the Form ’s Default Button  When you execute this program, notice that the Submit Grade Button has a blue highlight around it.  This Button is the Form ’s default Button—the one that will be pressed when the user presses the Enter key.  In this program, the user can type a value in the TextBox and press Enter to press the Submit Grade Button rather than clicking it with the mouse.  This convenience feature enables the user to rapidly enter grades.  You can specify a Form ’s default Button in the Properties window by setting the Form ’s AcceptButton property to the appropriate Button.  For this program, we set the AcceptButton property to the submitGradeButton. © by Pearson Education, Inc. All Rights Reserved.

◦ Pseudocode Algorithm with Counter-Controlled Repetition  After the user enters the grades and presses the Calculate Average Button, we use counter-controlled repetition to get the grades from the ListBox and process them one at a time.  This technique uses a variable called a counter (or control variable) to specify the number of times that a set of statements will execute.  In this example, repetition terminates when the counter exceeds the number of grades in the ListBox. © by Pearson Education, Inc. All Rights Reserved.

 The String class’s Format method performs the formatting.  The first argument to the method ( "{0:F}" ) is the format string, which acts as a placeholder for the value being formatted.  The numeric value that appears before the colon (in this case, 0 ) indicates which of Format ’s arguments will be formatted— 0 specifies the first argument after the format string passed to Format, namely average. © by Pearson Education, Inc. All Rights Reserved.

 The value after the colon (in this case, F ) is known as a format specifier, which indicates how a value is to be formatted.  The format specifier F indicates that a fixed-point number should be rounded to two decimal places by default.  The entire placeholder ( {0:F} ) is replaced with the formatted value of variable average.  You can change the number of decimal places to display by placing an integer value after the format specifier—for example, the string "{0:F3}" rounds the number to three decimal places. © by Pearson Education, Inc. All Rights Reserved.

 The ToString method can format a Date or DateTime value in a variety of ways  If the date is 8/10/2010 and the time is 3:22 PM  Tutorial 3-8 provides an opportunity to work with number formatting concepts Format String DescriptionToString() Value dShort Date"8/10/2010" DLong Date"Tuesday, August 10, 2010" tShort Time"3:22 PM" TLong Time"3:22:00 PM" FLong Date & Time "Tuesday August 10, :22:00 PM"

◦ GUI for the Licensing-Exam Analysis Application  Figure 4.13 shows this application’s GUI.  Each result is placed in the ListBox when the user presses the Submit Result Button.  We process all 10 results when the user presses the Analyze Results Button.  We also provide a Clear Results Button to reset the GUI so the user can enter a new set of results.  As in the previous example, we used the Form ’s AcceptButton property to set the Submit Result Button as the default Button.  We disabled the Analyze Results Button initially by setting its Enabled property to False. © by Pearson Education, Inc. All Rights Reserved.