Download presentation
Presentation is loading. Please wait.
Published byMyra Wade Modified over 9 years ago
1
2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition 11.3 Introducing the For…Next Repetition Statement 11.4 Examples Using the For…Next Statement 11.5 Constructing the Interest Calculator Application 11.6 Wrap-Up Tutorial 11 – Interest Calculator Application Introducing the For…Next Repetition Statement
2
2003 Prentice Hall, Inc. All rights reserved. 2 Objectives In this tutorial, you will learn to: –Execute statements repeatedly with the For…Next repetition statement. –Obtain user input with the NumericUpDown control. –Display information, using a multiline TextBox.
3
2003 Prentice Hall, Inc. All rights reserved. 3 11.1 Test-Driving the Interest Calculator Application
4
2003 Prentice Hall, Inc. All rights reserved. 4 11.1 Test-Driving the Interest Calculator Application Figure 11.1 Completed Interest Calculator application. Click to decrease number of years NumericUpDown control Click to increase number of years Executing the application
5
2003 Prentice Hall, Inc. All rights reserved. 5 11.1 Test-Driving the Interest Calculator Application Enter data into application –Principal and interest rate entered –Using NumericUpDown control to increase years Program output –Output displayed in multiline TextBox –Vertical scrollbar enabled
6
2003 Prentice Hall, Inc. All rights reserved. 6 11.1 Test-Driving the Interest Calculator Application Figure 11.2 Output of completed Interest Calculator application. Multiline TextBox displays application results
7
2003 Prentice Hall, Inc. All rights reserved. 7 11.2 Essentials of Counter-Controlled Repetition Four essential elements of counter-controlled repetition: –The name of a control variable (or loop counter) that is used to determine the whether the loop continues to iterate –The initial value of a control variable –The increment (or decrement) by which the control variable is modified after each iteration –The condition that tests for the final value of the control variable
8
2003 Prentice Hall, Inc. All rights reserved. Outline 8 Figure 11.3 Counter-controlled repetition example. Final value condition increment Control variable name Initial value
9
2003 Prentice Hall, Inc. All rights reserved. 9 11.3 Introducing the For…Next Repetition Statement Figure 11.4 For … Next header components. For intCounter = 2 To 10 Step 2 For keywordInitial value of control variableFinal value of control varaibleIncrement of control variable Control variable name To keyword Step keyword
10
2003 Prentice Hall, Inc. All rights reserved. 10 11.3 Introducing the For…Next Repetition Statement Figure 11.5 For … Next repetition statement UML activity diagram.
11
2003 Prentice Hall, Inc. All rights reserved. Outline 11 Figure 11.6 Code segment for the Car Payment Calculator application that demonstrates the For … Next statement. Initialize control variable to 1 Counter’s final value The Next keyword
12
2003 Prentice Hall, Inc. All rights reserved. 12 11.5 Constructing the Interest Calculator Application
13
2003 Prentice Hall, Inc. All rights reserved. 13 11.5 Constructing the Interest Calculator Application Template Form in Design view –Adding NumericUpDown control –Adding a multiline TextBox Figure 11.8 Template Interest Calculator application Form in design view.
14
2003 Prentice Hall, Inc. All rights reserved. 14 11.5 Constructing the Interest Calculator Application NumericUpDown control –Increment property –Increment property default value –ReadOnly property
15
2003 Prentice Hall, Inc. All rights reserved. 15 11.5 Constructing the Interest Calculator Application Figure 11.9 NumericUpDown control added to Interest Calculator application. NumericUpDown control
16
2003 Prentice Hall, Inc. All rights reserved. 16 11.5 Constructing the Interest Calculator Application Multiline TextBox –Can use scrollbar –Enable vertical scrollbar
17
2003 Prentice Hall, Inc. All rights reserved. 17 11.5 Constructing the Interest Calculator Application Figure 11.10 Multiline TextBox with vertical scrollbar added to the Form. Vertical scrollbar (disabled) Multiline TextBox
18
2003 Prentice Hall, Inc. All rights reserved. 18 11.5 Constructing the Interest Calculator Application Declaring variables –Declaring a counter variable Retrieving user input –Storing user input into variables
19
2003 Prentice Hall, Inc. All rights reserved. 19 11.5 Constructing the Interest Calculator Application Figure 11.11 Application code for retrieving and storing user input. Input variable declaration Counter variable declaration Retrieve user input
20
2003 Prentice Hall, Inc. All rights reserved. 20 11.5 Constructing the Interest Calculator Application Figure 11.12 Application code for displaying a header in multiline TextBox. Appending header text to the output String Displaying header text in multiline TextBox Using ControlChars.Tab Using ControlChars.CrLf
21
2003 Prentice Hall, Inc. All rights reserved. 21 11.5 Constructing the Interest Calculator Application Figure 11.13 Application code for For…Next statement. Using the For…Next statement to format and append text to the output String
22
2003 Prentice Hall, Inc. All rights reserved. 22 11.5 Constructing the Interest Calculator Application Figure 11.14 Application code for displaying calculation results. Displaying in the multiline TextBox the result of the calculations performed in the For…Next statement Displaying results in a multiline TextBox
23
2003 Prentice Hall, Inc. All rights reserved. Outline 23 InterestCalculator.vb (1 of 2)
24
2003 Prentice Hall, Inc. All rights reserved. Outline 24 InterestCalculator.vb (2 of 2) Using a For…Next statement to calculate amount on deposit
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.