Public Class frmBank

  Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
    'Find the future value of a bank deposit
    Dim p As Double = CDbl(txtAmount.Text)
    Dim r As Double = CDbl(txtRate.Text)
    Dim c As Integer = CInt(txtNumComp.Text)
    Dim n As Integer = CInt(txtNumYrs.Text)
    Dim balance As Double = FutureValue(p, r, c, n)
    txtBalance.Text = FormatCurrency(balance)
  End Sub

  Function FutureValue(ByVal p As Double, ByVal r As Double, _
                       ByVal c As Integer, ByVal n As Integer) As Double
    'Find the future value of a bank savings account
    'p  principal, the amount deposited
    'r  annual rate of interest in decimal form
    'c  number of times interest is compounded per year
    'n  number of years
    Dim i As Double     'interest rate per period
    Dim m As Integer    'total number of times interest is compounded
    i = r / c
    m = c * n
    Return p * ((1 + i) ^ m)
  End Function

End Class
