Clearly Visual Basic: Programming with Visual Basic nd Edition

Slides:



Advertisements
Similar presentations
Chapter 6: The Repetition Structure
Advertisements

Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 11: Classes and Objects
Programming with Microsoft Visual Basic th Edition
CS0004: Introduction to Programming Repetition – Do Loops.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Repeating Actions While and For Loops
Arrays.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Chapter Four The Selection Structure
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Chapter 4: The Selection Structure
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6: The Repetition Structure
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Programming with Microsoft Visual Basic th Edition
Introduction to Problem Solving and Control Statements.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Programming with Microsoft Visual Basic th Edition
Programming with Microsoft Visual Basic 2012 Chapter 9: Arrays.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 16 I’m on the Inside; You’re on the Outside.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 14 Do It, Then Ask Permission.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 23 The String Section (String Manipulation) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter 7 What’s Wrong with It? (Syntax and Logic Errors) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
Chapter 4: Do-It-Yourself Designing (Designing Interfaces)
Microsoft Visual Basic 2008: Reloaded Third Edition
Microsoft Visual Basic 2005: Reloaded Second Edition
Visual Basic 6 (VB6) Data Types, And Operators
Value-Returning Functions
Chapter 3: Using Variables and Constants
The Selection Structure
Repeating Program Instructions
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Presentation transcript:

Clearly Visual Basic: Programming with Visual Basic 2010 2nd Edition Chapter 14 Let Me Count the Ways (Counter-Controlled Loops)

Objectives After studying Chapter 14, you should be able to: Code a counter-controlled pretest loop using the For…Next statement Play an audio file while an application is running Calculate a periodic payment using the Financial.Pmt method Concatenate strings Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

When Will It Stop? Counter-controlled loop Loop whose instructions you want processed a precise number of times Can be either a pretest loop or a posttest loop Coding a posttest counter-controlled loop Use the Do...Loop statement Coding a Pretest counter-controlled loop Use either the Do…Loop statement or the For…Next statement Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

When Will It Stop? (cont’d.) For…Next syntax Shown in Figure 14-1 on next slide CounterVariableName Name of numeric variable Can be declared in a Dim statement To have procedure scope Variable declared in the For clause: Has block scope and can be used only within the loop Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

When Will It Stop? (cont’d.) startValue, endValue, stepValue Numeric items in the For clause Control the number of times loop is processed Can be positive or negative, integer, or non-integer Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Figure 14-1 Syntax, example, and processing tasks for the For…Next statement (continues) Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Figure 14-1 Syntax, example, and processing tasks for the For…Next statement (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Figure 14-2 Processing steps for the example in Figure 14-1 Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Spaceship-Version 1 Application Figure 14-3 Shows the interface for the Spaceship-Version 1 application Before coding the Spaceship-Version 1 application: View the Ch14-Spaceship video Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Spaceship-Version 1 Application (cont’d.) Figure 14-3 Interface for the Spaceship-Version 1 application Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Spaceship-Version 2 Application Display the numbers 3, 2, and 1 in the lblCountToBlastOff control Figure 14-5 For…Next statement entered in the Go button’s Click event procedure in the Spaceship-Version 2 application Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Hey, Turn That Noise Down! To have an application play an audio file while it is running: Use the syntax My.Computer.Audio.Play(fileName) Visual Basic’s My feature Exposes a set of commonly used objects to the programmer Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

The Monthly Payment Calculator Application Figure 14-6 Shows the interface for the Monthly Payment Calculator application Figure 14-7 Shows the application’s output, processing, and input items, along with its algorithm Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

The Monthly Payment Calculator Application (cont’d.) Figure 14-6 Interface for the Monthly Payment Calculator application Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Figure 14-7 Output, processing, input, and algorithm for the Monthly Payment Calculator application Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

The Financial.Pmt Method Calculates the periodic payment on a loan Figure 14-8 Shows the method’s basic syntax Lists the meaning of each of the three arguments included in the syntax Gives examples Can also be used to calculate periodic payment on an investment Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Figure 14-8 Basic syntax and examples of the Financial.Pmt method Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

But They Said There Were No Strings Attached Concatenation operator Represented by ampersand (&) Used to concatenate (connect or link) strings Must use a space before and after the ampersand Figure 14-9 Shows syntax and examples of using the concatenation operator Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Figure 14-9 Syntax and examples of concatenating strings Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Summary The For…Next statement Variable declared in a For clause Provides a convenient way to code a counter-controlled loop Variable declared in a For clause Has block scope Can be used only by the For…Next loop The For…Next statement’s counter variable must be numeric Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition

Summary (cont’d.) The syntax My.Computer.Audio.Play(fileName) Can be used to play an audio file while an application is running Financial.Pmt method Used to calculate a periodic payment on a loan or investment Concatenation operator (&) Used to connect strings Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition