Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCalculate compound interest over time in Visual Basic 6
DescriptionThis example shows how to calculate compound interest over time in Visual Basic 6.
KeywordsWindows Forms programming,example program,calculate compound interest,compound interest,example,Visual Basic 6,interest
CategoriesAlgorithms
 
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.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated