Repeating Program Instructions

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Chapter 6: The Repetition Structure
Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th 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 7: Sub and Function Procedures
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Repeating Actions While and For Loops
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
An Introduction to Programming with C++ Fifth Edition
Chapter 7: Sub and Function Procedures
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
5.05 Apply Looping Structures
Chapter 8 Using Repetition with Loops and Lists. Class 8: Loops and Lists Write Do loops to execute statements repeatedly Write For loops to execute statements.
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Seven Sub and Function Procedures.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
 What are the different types of loops? ◦ Do….While  Performs statements within loop while a condition is true ◦ Do….Until  Performs statements within.
Programming with Microsoft Visual Basic 2008 Fourth Edition
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 Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 5 Lists, Loops, Validation, and More.
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.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Introduction to Problem Solving and Control Statements.
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events Visual Basic. NET.
AdditionalControls 1. The MenuStrip 2 Double-click Let’s begin to design the menu bar for VB! Let’s begin to design the menu bar for VB! 3.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
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.
Controlling Program Flow with Looping Structures
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 14 Do It, Then Ask Permission.
Unit 6 Repetition Processing Instructor: Brent Presley.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
Looping Structures. A B dialog box that pops up and prompts the user for input Text area that pops up and prompts the user for to wait while it gets.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 9: Chapter 5: Slide 1 Unit 9 Do Until and For… Next Loops Chapter 5 Lists,
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Microsoft Visual Basic 2008: Reloaded Third Edition
REPETITION CONTROL STRUCTURE
Clearly Visual Basic: Programming with Visual Basic nd Edition
Lists, Loops, Validation, and More
Loops ISYS 350.
IS 350 Loops.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 5 The Do…Loop Statement
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS16 Application Development and Programming using Visual Basic.net
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Lecture Set 10 Windows Controls and Forms
Presentation transcript:

Repeating Program Instructions

Objectives Include the repetition structure in pseudocode and in a flowchart Write a For...Next statement Calculate a periodic payment using the Financial.Pmt method Include a list box and a combo box in an interface Write a Do...Loop statement Initialize and update counters and accumulators Display a dialog box using the InputBox function Create a multiline text box that cannot be edited Animate a control by moving it across a form Have the computer sound a beep 9/19/2018 VB 2005

The Repetition Structure Repetition structure (or loop): a structure that repeatedly processes one or more program instructions until a condition is met Pretest loop The condition is evaluated before the instructions within the loop are processed The instructions may be processed 0 or more times Posttest loop The condition is evaluated after the instructions within the loop are processed The instructions are always processed at least once 9/19/2018 VB 2005

The Repetition Structure (continued) Repetition statements in Visual Basic For...Next Do...Loop For Each...Next 9/19/2018 VB 2005

The For...Next Statement For...Next statement Processes a set of instructions a known number of times Is a pretest loop Syntax: For counter [As datatype]=startvalue to endvalue [stepvalue] [statements] Next counter 9/19/2018 VB 2005

The For...Next Statement (continued) Startvalue, endvalue, and stepvalue items Control the number of times the loop is processed Must evaluate to numeric values Can be positive or negative A negative stepvalue causes the loop counter to count down Flowchart symbol for the For...Next loop is a hexagon 9/19/2018 VB 2005

The For...Next Statement (continued) 9/19/2018 VB 2005

The For...Next Statement (continued) 9/19/2018 VB 2005

The Financial.Pmt Method Syntax: Financial.Pmt(Rate, NPer, PV[,Fv, Due]) Calculates a periodic payment on a loan or investment Returns the periodic payment as a Double type value Rate and number of periods arguments must be expressed in the same units (monthly, annual, etc.) Also calculates the amount that must be saved each period to accumulate a specific sum 9/19/2018 VB 2005

The Financial.Pmt Method (continued) 9/19/2018 VB 2005

The Monthly Payment Calculator Application 9/19/2018 VB 2005

Selecting the Existing Text in a Text Box Windows standard: highlight the existing text when a text box receives the focus SelectAll method: selects all text in a text box Syntax: textbok.selectAll() Enter event: occurs when the text box receives the focus 9/19/2018 VB 2005

Coding a Control’s TextChanged Event Procedure Occurs when a change is made in a control’s Text property Change may be made by user or the program 9/19/2018 VB 2005

Using a List Box in an Interface ListBox tool: creates a ListBox control ListBox control: displays a list of choices from which the user can select 0 or more choices SelectionMode property: controls the number of choices a user can select None: user can scroll but not select anything One: user can select one item MultiSimple and MultiExtended: user can select multiple items 9/19/2018 VB 2005

Using a List Box in an Interface (continued) 9/19/2018 VB 2005

Adding Items to a List Box Items collection: a collection of the items in a list box Collection: a group of one or more individual objects treated as one unit Index: A unique number that identifies an item in a collection Is zero-relative: the first item has index of 0 Add method: adds an item to the list box’s Items collection 9/19/2018 VB 2005

Adding Items to a List Box (continued) 9/19/2018 VB 2005

Adding Items to a List Box (continued) 9/19/2018 VB 2005

Adding Items to a List Box (continued) Sorted property: Determines if the list box items are sorted Sort order is dictionary order 9/19/2018 VB 2005

The SelectedItem and SelectedIndex Properties SelectedItem property: Contains the value of the selected item in the list If nothing is selected, it contains the empty string SelectedIndex property: Contains the index of the selected item in the list If nothing is selected, it contains the value -1 Default list box item: the item that is selected by default when the interface first appears 9/19/2018 VB 2005

The SelectedValueChanged and SelectedIndexChanged Events SelectedValueChanged and SelectedIndexChanged events: occur when a user selects an item in a list box 9/19/2018 VB 2005

The SelectedValueChanged and SelectedIndexChanged Events (continued) 9/19/2018 VB 2005

Using a Combo Box in an Interface ComboBox tool: creates a combo box control ComboBox control: Similar to a list box May contain a text field that allows the user to type an entry that is not on the list List portion may be hidden Three styles of combo boxes: Simple DropDown DropDownList 9/19/2018 VB 2005

Using a Combo Box in an Interface (continued) 9/19/2018 VB 2005

Using a Combo Box in an Interface (continued) SelectedItem property: contains the value of the selected item in the list Text property: contains the value that appears in the text portion of the control (item selected or typed in) 9/19/2018 VB 2005

The Do...Loop Statement Do...Loop statement: codes both a pretest or a posttest loop Use While or Until to code the condition for the loop Repetition symbol in a flowchart is the diamond Syntax: Do While condition Do Statement(s) Statement(S) Loop Loop Until condition 9/19/2018 VB 2005

The Do...Loop Statement (continued) 9/19/2018 VB 2005

The Do...Loop Statement (continued) 9/19/2018 VB 2005

The Do...Loop Statement (continued) 9/19/2018 VB 2005

The Do...Loop Statement (continued) 9/19/2018 VB 2005

Using Counters and Accumulators Counter: a numeric variable used for counting Accumulator: a numeric variable used for accumulating Initializing: assigning a beginning value to a variable Updating (or incrementing): adding a number to the value of a variable Counters are always incremented by a constant value, usually 1 9/19/2018 VB 2005

The InputBox Function InputBox function: displays a predefined dialog box Contains a text message, an OK button, a Cancel button, and an input area Function: a predefined procedure that performs a specific task and returns a value InputBox function returns: The user’s entry if the user clicks the OK button An empty string if the user clicks the Cancel button or the Close button on the title bar Syntax: InputBox(Prompt [,title], [Defaultresponse]) 9/19/2018 VB 2005

The InputBox Function (continued) 9/19/2018 VB 2005

Summary Repetition structure (or loop): repeatedly processes a set of instructions Pretest loop tests the condition before the instructions are processed Posttest loop tests the condition after the instructions are processed For...Next statement: a pretest loop that will process the instructions a fixed number of times Financial.Pmt method: calculates a periodic payment on a loan or investment 9/19/2018 VB 2005

Summary (continued) SelectAll method: highlights text in a text box TextChanged Event: occurs when a control’s text changes List box’s Items collection: adds an item to the list SelectedItem property of a list box: contains the value of the selected item in the list SelectedIndex property of a list box: contains the index position of the selected item in the list 9/19/2018 VB 2005

Summary (continued) Combo box: similar to a list box but may not expose the list items until clicked Three styles of combo boxes: Simple, DropDown, and DropDownList Do...Loop statement: codes a pretest or posttest loop Use a While or Until condition in a Do...Loop Flowchart symbol for repetition is a diamond 9/19/2018 VB 2005

Summary (continued) Counter and accumulators: variables that calculate subtotals, totals, and averages InputBox function: allows user input Console.Beep method: plays the sound of a beep through the computer’s console speakers 9/19/2018 VB 2005