Clearly Visual Basic Programming with Visual Basic 2008
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 15 Let Me Count the Ways
Objectives • Code a 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 Clearly Visual Basic: Programming with Visual Basic 2008 2
When Will It Stop? • Counter loop – Loop whose instructions you want processed a precise number of times – Can be either a pretest loop or a posttest loop • To code a posttest counter loop: – Use the Do. . . Loop statement • Pretest counter loop – Can be coded using either the Do…Loop statement or the For…Next statement Clearly Visual Basic: Programming with Visual Basic 2008 3
When Will It Stop? (continued) • Variable declared in a Dim statement at the beginning of a procedure – Has procedure scope – Can be used by the entire procedure • Block variables – Have a smaller scope than procedure-level variables Clearly Visual Basic: Programming with Visual Basic 2008 4
Clearly Visual Basic: Programming with Visual Basic 2008 5
Clearly Visual Basic: Programming with Visual Basic 2008 6
Spaceship-Version 1 Application • Figure 15 -3 – Shows the interface for the Spaceship-Version 1 application • Before coding the Spaceship-Version 1 application – View the Ch 15 -Spaceship video Clearly Visual Basic: Programming with Visual Basic 2008 7
Clearly Visual Basic: Programming with Visual Basic 2008 8
Spaceship-Version 2 Application • Display the numbers 3, 2, and 1 in the lbl. Count. To. Blast. Off control Clearly Visual Basic: Programming with Visual Basic 2008 9
Hey, Turn the Noise Down! • To have an application play an audio file while it is running: – Use the syntax My. Computer. Audio. Play(file. Name) • Visual Basic’s My feature – Exposes a set of commonly used objects to the programmer Clearly Visual Basic: Programming with Visual Basic 2008 10
The Monthly Payment Calculator Application • Figure 15 -6 – Shows the interface for the Monthly Payment Calculator application • Figure 15 -7 – Shows the application’s output, processing, and input items, as well as its algorithm Clearly Visual Basic: Programming with Visual Basic 2008 11
Clearly Visual Basic: Programming with Visual Basic 2008 12
Clearly Visual Basic: Programming with Visual Basic 2008 13
The Financial. Pmt Method • Calculates the periodic payment on a loan • Figure 15 -8 – Shows the method’s basic syntax – Lists the meaning of each of the three arguments included in the syntax • Can be used to calculate periodic payment on an investment Clearly Visual Basic: Programming with Visual Basic 2008 14
Clearly Visual Basic: Programming with Visual Basic 2008 15
Summary • The For…Next statement – Provides a convenient way to code a counter 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 2008 16
Summary (continued) • The syntax My. Computer. Audio. Play(file. Name) – 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 Clearly Visual Basic: Programming with Visual Basic 2008 17
- Slides: 17