Solved

# How doI write a Programmer Defined Function that Computes a Future Value

Posted on 1998-10-15

I am doing a project that has to contain a Programmer Defined Function that Calculates a Future value. the formula I was given is;

FV = PV * (1+ (i/m)) m*y ('m*y are exponents)

PV=Present value

i=Annual Interest rate

m=Number of Compounding Periods Per Year

y=Number of years

Here is what I have;

'This Project will compute the Future Value of a given Present

'Value Amount.

Option Explicit

Private Sub Cmd_ComputeFutureValue_Click()

'This compute's the Future Value.

Dim Exponent As Double

Dim FutureValue As Currency

Dim InterestRate As Double

Dim NumberOfYears As Integer

Dim PeriodsPerYear As Integer

Dim PresentValue As Currency

PeriodsPerYear = Val(Txt_InputPmtPeriodsPerYear.Text)

InterestRate = Val(Format$(Txt_InputAnnualInterest.Text, "#0.00"))

NumberOfYears = Val(Txt_InputNumberOfYears.Text)

PresentValue = Val(Txt_InputPresentValue.Text)

Exponent = Exp(PeriodsPerYear * NumberOfYears)

FutureValue = PresentValue * (1 + (InterestRate / PeriodsPerYear)) ^ Exponent

Lbl_ShowFutureValue.Caption = Format$(FutureValue, "Currency")

End Sub 'Cmd_ComputefutureValue_Click

Private Sub Form_Load()

'This shows all Text Boxes clear at start of Program

Txt_InputAnnualInterest.Text = ""

Txt_InputNumberOfYears.Text = ""

Txt_InputPmtPeriodsPerYear = ""

Txt_InputPresentValue.Text = ""

Lbl_ShowFutureValue.Caption = ""

End Sub 'Form_Load

Here is what I get when I enter my values,

for present value; 1

for annual interest rate; 10

for payment periods per Year; 12

for Number of years; 1

I get the result for future value as, $1.83

I know the Ansewer should be $1.10

I Think one of the Problems is that the Interest Rate is not using the decimal. And The Exponent of m*y (Number of Compuonding Periods Per Year * Number of Years) Isnt being used Correctly.

How do I fix this In the Code?

And How would I Write it in a Programmer Defined Function?