|
|
Title | Calculate compound interest over time in Visual Basic 6 |
Description | This example shows how to calculate compound interest over time in Visual Basic 6. |
Keywords | Windows Forms programming,example program,calculate compound interest,compound interest,example,Visual Basic 6,interest |
Categories | Algorithms |
|
|
Enter the principle amount, interest rate, and number of years in the textboxes. When you click Calculate, the program uses the following code to display your balance for the following years.
|
|
Private Sub cmdCalculate_Click()
Dim principle As Double
Dim interest_rate As Double
Dim num_years As Integer
Dim i As Integer
Dim current_value As Double
lstBalances.Clear
principle = Val(txtPrinciple.Text)
interest_rate = Val(txtInterestRate.Text)
num_years = Val(txtYears.Text)
For i = 1 To num_years
current_value = principle * (1 + interest_rate) ^ i
lstBalances.AddItem i & ": " & _
vbTab & FormatCurrency(current_value)
Next i
End Sub
|
|
The program simply loops through the years, evaluating the compound interest formula:
balance = principle * Math.Pow(1 + interestRate, i)
Interesting tidbit: To estimate how long it will take to double your money, you can use the "Rule of 72." Divide the interest rate into 72 and the result tells you roughly how many years it will take to double your money. For example, at 7.2% it'll take about 10 years. It's a pretty decent estimate.
|
|
|
|
|
|