Chapter 3- Data Types and Operators Boolean Expressions Page 2 3 4

Introduction

The If Statement Page 2 3 4 5 6 7 8 9
Arithmetic Operations Page 2 3 4 5 6 Boolean Operators and Nested If Statements Page 2 3 4 5 6 7
Events and Sequential Processing Page 2 3 4 5 More Examples Page 2 3 4 5 6 7 8 9 10 11 12
Datatypes and Conversions Page 2 3 4 5 6 7 Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10
Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Exercises Page 2 3 4 5 6 7 8
Chapter 4- Selection Statements Review Questions
Introduction

3-5: Variable Declarations (continued)

There are a number of new things to note in this code:

The btnCalculate_Click event can be completed rather easily now. Simply repeat the last six lines twice changing txtYear1.Text, txtInterest1.Text and txtCapital1.Text to txtYear2.Text, txtInterest2.Text and txtCapital2.Text, and then to txtYear3.Text, txtInterest3.Text and txtCapital3.Text! You end up with:

Private Sub btnCalculate_Click( ... )
Dim capital As Double, interestAmount as Double
Dim interestRate As Double

' Assign values from textboxes to variables ...
capital = Convert.ToDouble(txtInitialCap.Text)
interestRate = CDbl(txtRate.Text)

' For year 1 ...
interestAmount = interestRate * capital
capital = capital + interestAmount
txtYear1.Text = 1
txtInterest1.Text = interestAmount
txtCapital1.Text = capital

' For year 2 ...
interestAmount = interestRate * capital
capital = capital + interestAmount
txtYear2.Text = 2
txtInterest2.Text = interestAmount
txtCapital2.Text = capital

' For year 3 ...
interestAmount = interestRate * capital
capital = capital + interestAmount
txtYear3.Text = 3
txtInterest3.Text = interestAmount
txtCapital3.Text = capital
End Sub

Start the program and make sure that it behaves as it should. Enter some simple values for the interest rate and initial capital so that you can check the calculations by hand. Also make sure that the Clear and Exit buttons work correctly.