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

Slides:



Advertisements
Similar presentations
Decisions If statements in C.
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 1.
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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
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.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
© 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.
1 C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved. 4.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
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.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Debugging Visual Basic.NET Programs ► ► Use debugging tools ► ► Set breakpoints and correct mistakes. ► ► Use a Watch and Local window to examine variables.
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.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #4 Control Statements – Part 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 5.1 – 5.4 © Copyright by Pearson Education, Inc. All Rights Reserved.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
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.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 7 Wage Calculator Application Introducing Algorithms, Pseudocode and Program Control.
 2007 Pearson Education, Inc. All rights reserved Control Statements: Part2.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
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.
How to debug an application
- Standard C Statements
Chapter 5- Control Structures: Part 2
Visual Basic 6 (VB6) Data Types, And Operators
Problem Solving and Control Statements: Part 2
Computer Programming I
CSC113: Computer Programming (Theory = 03, Lab = 01)
JavaScript: Control Statements I
Control Structures: Part 1
Chapter 3: Introduction to Problem Solving and Control Statements
3 Control Statements:.
Introduction to Problem Solving and Control Statements
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Debugging Visual Basic Programs
Dale Roberts, Lecturer IUPUI
Presentation transcript:

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

 All programs could be written in terms of only three control structures—the sequence structure, the selection structure and the repetition structure: ◦ If … Then, ◦ If … Then … Else ◦ Select…Case ◦ Do While … Loop ◦ While … End While and ◦ Do Until … Loop © by Pearson Education, Inc. All Rights Reserved.

◦ The Do While…Loop and While…End While repetition statements execute a set of statements while a condition—known as the loop- continuation condition—remains true. If the condition is initially false, the set of statements does not execute. ◦ The Do Until…Loop repetition statement executes a set of statements until a condition—known as the loop-termination condition—becomes true. If the condition is initially true, the set of statements does not execute. ◦ The Do…Loop While repetition statement executes a set of statements while its loop-continuation condition remains true. The set of statements is guaranteed to execute at least once. © by Pearson Education, Inc. All Rights Reserved.

 Repetition Statements (contd..) ◦ The Do…Loop Until repetition statement executes a set of statements until its loop-termination condition becomes true. The set of statements is guaranteed to execute at least once. ◦ The For…Next repetition statement executes a set of statements a specified number of times—this is known as counter-controlled (or definite) repetition. ◦ The For Each…Next repetition statement (introduced in Chapter 7) performs a set of statements for every element of a so-called array or collection of values. © by Pearson Education, Inc. All Rights Reserved.

 A selection statement chooses among alternative courses of action.  Suppose that the passing grade on an examination is 60 (out of 100).  If studentGrade >= 60 Then resultLabel.Text = "Passed" ' display "Passed" End If © by Pearson Education, Inc. All Rights Reserved.

 The If … Then … Else selection statement allows you to specify that a different action (or sequence of actions) is to be performed when the condition is true than when the condition is false.  The preceding pseudocode If…Else statement may be written in Visual Basic as  If studentGrade >= 60 Then resultLabel.Text = "Passed" ’ display "Passed" Else resultLabel.Text = "Failed" ’ display "Failed" End If © by Pearson Education, Inc. All Rights Reserved.

4.7 Nested If … Then … Else Statements

 When the following Do While … Loop statement finishes executing, product contains the result:  Do While product <= 100 product = product * 3 ' compute next power of 3 Loop © by Pearson Education, Inc. All Rights Reserved.

 The While…End While repetition statement behaves identically to the Do While … Loop repetition statement.  While product <= 100 product = product * 3 ' compute next power of 3 End While © by Pearson Education, Inc. All Rights Reserved.

 You can write the preceding Do While … Loop statement as a Do Until … Loop statement as follows:  Do Until product > 100 product = product * 3 'compute next power of 3 Loop  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 ). © by Pearson Education, Inc. All Rights Reserved.

Handling empty string

© by Pearson Education, Inc. All Rights Reserved.

 The statement in lines 43–45 outputs the class average, we used the expression  String.Format("{0:F}", average)  which indicates that average ’s value should be displayed as a number with a specific number of digits to the right of the decimal point—called a fixed-point number. © 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.

 Breakpoints are special markers that you can set at any executable line of code.  You cannot place them on comments or whitespace.  When a running program reaches a breakpoint, execution pauses, allowing you to examine the values of variables to help determine whether logic errors exist.  For example, you can examine the value of a variable that stores a calculation’s result to determine whether the calculation was performed correctly.  You can also examine the value of an expression.  Once the debugger pauses program execution, you can use various debugger commands to execute the program one statement at a time—this is called “single stepping” or simply “stepping.” © by Pearson Education, Inc. All Rights Reserved.

 To insert a breakpoint, left click in the margin indicator bar (the gray margin at the left of the code window) or right click on the line and select Breakpoint > Insert Breakpoint.  Additionally, you can click a line of code then press F9 to toggle a breakpoint on and off for that line of code.  A solid circle appears in the margin indicator bar where you clicked and the entire code statement is highlighted, indicating that a breakpoint has been set. © by Pearson Education, Inc. All Rights Reserved.

 While in break mode, you can also explore the values of a method’s local variables using the debugger’s Locals window (Fig. 4.21).  To view the Locals window, select Debug > Windows > Locals.  Recall that all variables in Visual Basic get initialized. © by Pearson Education, Inc. All Rights Reserved.

 You’ll now execute the program one statement at a time using the debugger’s Step Over command.  You can access this command by selecting Debug > Step Over, by pressing Shift + F8 or by pressing the Step Over command’s toolbar icon (). © by Pearson Education, Inc. All Rights Reserved.

 To execute the program without the breakpoints, you can: ◦ Disable each breakpoint by right clicking in the line of code with the breakpoint and selecting Breakpoint > Disable Breakpoint, then run the program; ◦ Remove each breakpoint by right clicking the breakpoint and selecting Delete Breakpoint, then run the program; or ◦ Execute the program without debugging by pressing Ctrl + F5. © by Pearson Education, Inc. All Rights Reserved.