Library tutorials & articles

Mathematical Functions

Compound Interest

Here is a little function that calulates the compound interest of an amount, over the specified period.

Function CompoundInterest(cStartAmount As Currency, fInterestPerPeriod As Single, lPeriods As Long) As Currency
    Dim i As Long
    Dim cTotal As Currency
    cTotal = cStartAmount
    For i = 1 To lPeriods
        cTotal = cTotal + (cTotal * (fInterestPerPeriod))
    Next i
    CompoundInterest = cTotal - cStartAmount
End Function

Private Sub cmdCalculate_Click()
    '// 100 = starting amount
    '// 0.1 = 10% Interest per period
    '// 2   = 2 periods
    MsgBox CompoundInterest(100, 0.1, 2)
End Sub

Comments

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...
AddThis

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback