Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition
Objectives Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 2 After studying Chapter 15, you should be able to: Nest repetition structures Utilize a text box’s Multiline, ReadOnly, and ScrollBars properties
One Loop within Another Loop Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 3 Repetition structures can be nested Programmer Determines whether a problem’s solution requires a nested repetition structure Figure 15-1 Shows problem specification and algorithm from Chapter 12
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 4 Figure 15-1 Problem specification and algorithm for signing one book for each customer
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 5 Figure 15-2 Problem specification and algorithm for signing zero or more books for each customer
Clock Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 6 Clock Uses nested repetition structures to keep track of time The second hand is controlled by the inner (nested) loop The minute hand is controlled by the outer loop Figure 15-3 shows logic used by clock’s minute and second hands Figure 15-4 shows interface for the Clock application
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 7 Figure 15-3 Logic used by a clock’s minute and second hands
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 8 Figure 15-4 Clock application’s user interface
Revisiting the Monthly Payment Calculator Application Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 9 Figure 15-6 Shows the output, processing, input items, and algorithm for the Monthly Payment Calculator application Application calculates and displays: Monthly payments on a loan Payments are calculated using: Principal and term entered by the user A loop that varies the annual interest rates from 4% through 7%
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 10 Figure 15-6 Planning information for the Monthly Payment Calculator application from Chapter 14
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 11 Figure 15-7 Planning information for the modified Monthly Payment Calculator application
Revisiting the Monthly Payment Calculator Application (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 12 ScrollBars property Indicates whether any scroll bars appear on the text box Multiline property Specifies whether the text box can accept and display multiple lines of text Setting the text box’s ReadOnly property to True Prevents user from editing contents of a text box
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 13 Figure Click event procedure for the btnCalc control
But I Want To Do It a Different Way Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 14 Use two Do…Loop statements or one For…Next statement and one Do…Loop statement
Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 15 Figure Modified Click event procedure for the btnCalc control
Summary Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 16 Repetition structures can be nested For a nested repetition structure to work correctly: It must be contained entirely within the outer repetition structure When a text box’s Multiline property is set to True: It can accept and display multiple lines of text
Summary (cont’d.) Clearly Visual Basic: Programming with Visual Basic 2010, 2 nd Edition 17 A text box’s ScrollBars property Determines whether scroll bars appear on the control Setting the text box’s ReadOnly property to True Prevents the user from editing contents of a text box