Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCalculate the future value of a monthly investment with interest in Visual Basic 6
DescriptionThis example shows how to calculate the future value of a monthly investment with interest in Visual Basic 6.
Keywordsalgorithms, mathematics, finance, interest, monthly investment, investment, example, example program, Windows Forms programming, Visual Basic 6, VB 6
CategoriesAlgorithms
 

The magic of compound interest is that, over time, you get interest on the interest

For each month the program calculates the interest on the account balance. It then adds the interest and a monthly contribution to the balance and displays the result. (Note that interest is compounded monthly not continuously.)

The following code shows how the program performs its calculations.

 
' Calculate the interest compounded monthly.
Private Sub cmdGo_Click()
Dim monthly_contribution As Double
Dim num_months As Integer
Dim interest_rate As Double
Dim balance As Double
Dim i As Integer
Dim new_item As ListItem
Dim interest As Double

    ' Get the parameters.
    monthly_contribution = _
        ParseCurrency(txtMonthlyContribution.Text)
    num_months = Val(txtNumMonths.Text)
    interest_rate = ParsePercent(txtInterestRate.Text) / 12

    ' Calculate.
    lvwBalance.ListItems.Clear
    balance = 0
    For i = 1 To num_months
        ' Display the month.
        Set new_item = _
            lvwBalance.ListItems.Add(Text:=Format$(i))

        ' Display the interest.
        interest = balance * interest_rate
        new_item.ListSubItems.Add _
            Text:=FormatCurrency$(interest)

        ' Add the contribution.
        balance = balance + monthly_contribution

        ' Display the balance.
        balance = balance + interest
        new_item.ListSubItems.Add _
            Text:=FormatCurrency$(balance)
    Next i

    ' Scroll to the last entry.
    lvwBalance.ListItems(lvwBalance.ListItems.Count).EnsureVisible
End Sub
 
 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated