Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic:...
-
Upload
brian-manning -
Category
Documents
-
view
229 -
download
9
Transcript of Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic:...
Chapter 15 I’m on the Inside; You’re on the
Outside (Nested Loops)
Clearly Visual Basic: Programming with Visual Basic 2010
2nd Edition
Objectives
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition2
After studying Chapter 15, you should be able to:Nest repetition structuresUtilize a text box’s Multiline, ReadOnly, and ScrollBars properties
One Loop within Another Loop
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition3
Repetition structures can be nestedProgrammer
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, 2nd Edition4
Figure 15-1 Problem specification and algorithm for signing one book for each customer
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition5
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, 2nd Edition6
Clock Uses nested repetition structures to keep
track of timeThe second hand is controlled by the inner
(nested) loopThe minute hand is controlled by the outer
loopFigure 15-3 shows logic used by clock’s
minute and second handsFigure 15-4 shows interface for the Clock
application
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition7
Figure 15-3 Logic used by a clock’s minute and second hands
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition8
Figure 15-4 Clock application’s user interface
Revisiting the Monthly Payment Calculator Application
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition9
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 userA loop that varies the annual interest rates from 4%
through 7%
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition10
Figure 15-6 Planning information for the Monthly Payment Calculator application from Chapter 14
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition11
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, 2nd Edition12
ScrollBars property Indicates whether any scroll bars appear on
the text boxMultiline property
Specifies whether the text box can accept and display multiple lines of text
Setting the text box’s ReadOnly property to TruePrevents user from editing contents of a text
box
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition13
Figure 15-11 Click event procedure for the btnCalc control
But I Want To Do It a Different Way
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition14
Use two Do…Loop statements or one For…Next statement and one Do…Loop statement
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition15
Figure 15-12 Modified Click event procedure for the btnCalc control
Summary
Clearly Visual Basic: Programming with Visual Basic 2010, 2nd Edition16
Repetition structures can be nestedFor a nested repetition structure to work
correctly:It must be contained entirely within the outer
repetition structureWhen 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, 2nd Edition17
A text box’s ScrollBars property Determines whether scroll bars appear on
the controlSetting the text box’s ReadOnly property to
TruePrevents the user from editing contents of a
text box