Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?

Similar presentations


Presentation on theme: "Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?"— Presentation transcript:

1 Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?

2 Clearly Visual Basic: Programming with Visual Basic 2008 Objectives Write a pretest loop using the Do…Loop statement Utilize counter and accumulator variables Refresh the screen Delay program execution Show a pretest loop in both pseudocode and a flowchart Display a dialog box using the InputBox function 2

3 Clearly Visual Basic: Programming with Visual Basic 2008 Over and Over Again Repetition structure (loop) –Used to process one or more program instructions repeatedly, until some condition is met –Can be either a pretest loop or a posttest loop Pretest loop –Loop condition is evaluated before the instructions within the loop are processed Posttest loop –Evaluation occurs after the instructions within the loop are processed 3

4 4Clearly Visual Basic: Programming with Visual Basic 2008

5 Over and Over Again (continued) Figure 13-2 –Shows the modified problem specification along with the modified algorithm Figure 13-3 –Shows another problem specification and algorithm involving Rob Figures 13-4 and 13-5 –Shows a modified version of the previous problem specification 5Clearly Visual Basic: Programming with Visual Basic 2008

6 6

7 7

8 8

9 9

10 10 The Do … Loop Statement Do…Loop statement –Used to code both a pretest loop and a posttest loop Figure 13-6 –Shows syntax of the Do…Loop statement Keyword While –Indicates that the loop instructions should be processed while the condition is true Keyword Until –Indicates that the loop instructions should be processed until the condition becomes true

11 11Clearly Visual Basic: Programming with Visual Basic 2008

12 12Clearly Visual Basic: Programming with Visual Basic 2008

13 The Do … Loop Statement (continued) intNumber variable –Called a counter variable Counter variables –Always numeric variables –Typically assigned a beginning value of either 0 or 1, depending on the value required by the application Updating (incrementing) –Adding a number to the value stored in the counter variable 13Clearly Visual Basic: Programming with Visual Basic 2008

14 14

15 My Dream Car-Version 1 Application Figure 13-8 –Shows the interface for the My Dream Car-Version 1 application Refresh method –Will ensure that any code appearing before it that affects the interface’s appearance is processed –Syntax: Me.Refresh() Sleep method –Used to delay program execution –Syntax System.Threading.Thread.Sleep(milliseconds) 15Clearly Visual Basic: Programming with Visual Basic 2008

16 16Clearly Visual Basic: Programming with Visual Basic 2008

17 Flowcharting the Click Me Button’s Event Procedure Figure 13-11 –Shows flowchart for the Click Me button’s Click event procedure You mark the flowline leading to the true path with a “T” (for True) You mark the flowline leading to the false path with an “F” (for False) 17Clearly Visual Basic: Programming with Visual Basic 2008

18 18Clearly Visual Basic: Programming with Visual Basic 2008

19 My Dream Car-Version 2 Application The lblMessage control’s Visible property –Set to True in the Properties window –The picCar control’s Visible property is set to False Figure 13-12 –Shows the algorithm for the Click Me button’s Click event procedure 19Clearly Visual Basic: Programming with Visual Basic 2008

20 20Clearly Visual Basic: Programming with Visual Basic 2008

21 The Sales Express Application Accumulator variable –Numeric variable used for accumulating something –Assigned a value outside the loop –Updated within the loop –Incremented by an amount that varies 21Clearly Visual Basic: Programming with Visual Basic 2008

22 22Clearly Visual Basic: Programming with Visual Basic 2008

23 23Clearly Visual Basic: Programming with Visual Basic 2008

24 The InputBox Function Displays one of the standard dialog boxes available in Visual Basic Empty string –Represented by the String.Empty constant Figure 13-16 –Shows basic syntax of the InputBox function 24Clearly Visual Basic: Programming with Visual Basic 2008

25 25Clearly Visual Basic: Programming with Visual Basic 2008

26 The InputBox Function (continued) Figure 13-18 –Shows a sample testing chart for the Sales Express application Runtime error –Occurs while an application is running Before using a variable as the divisor in an expression: –Verify that the variable does not contain the number 0 26Clearly Visual Basic: Programming with Visual Basic 2008

27 27Clearly Visual Basic: Programming with Visual Basic 2008

28 Summary Use a repetition structure, or loop –To repeatedly process one or more program instructions Loop –Can be either a pretest loop or a posttest loop Do…Loop statement –Can be used to code a pretest loop Counter and accumulator variables –Should be assigned a value outside the loop, but updated within the loop 28Clearly Visual Basic: Programming with Visual Basic 2008

29 Summary (continued) Loop condition –Represented by a diamond in a flowchart Priming read –Gets only the first input item from the user InputBox function –Can be used to display a dialog box that contains a message, an OK button, a Cancel button, and an input area If a variable is used as the divisor in an expression: –Always verify that the variable does not contain the number 0 29Clearly Visual Basic: Programming with Visual Basic 2008


Download ppt "Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?"

Similar presentations


Ads by Google