Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar MSDN Visual Basic Community

Title Calculate compound interest over time in Visual Basic .NET This example shows how to calculate compound interest over time in Visual Basic .NET. Windows Forms programming,example program,calculate compound interest,interest,example,Visual Basic .NET, VB.NET 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 btnCalculate_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles _
btnCalculate.Click
lstBalances.Items.Clear()

Dim principle As Double = Val(txtPrinciple.Text)
Dim interest_rate As Double = Val(txtInterestRate.Text)
Dim num_years As Integer = Val(txtYears.Text)

For i As Integer = 1 To num_years
Dim current_value As Double = _
principle * (1 + interest_rate) ^ i
lstBalances.Items.Add(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.