Financial Functions in VB

 

 

Visual basic provides some very handy financial functions which makes  accounting and financial calculations effortless. Some of the financial functions are listed below.

 

Function

Meaning

Pmt

compute the payment for an annuity

Ipmt

computes the interest payment for a certain period

PPmt

computes the principal payment

IRR

computes internal rate of return for cash flows

Rate

 computes interest rate per period

FV

Calculate the future value
PV Computes the present value
NPV computes net present value
Nper Computes the value of Tangent  of an angle in radian

Below is an example of using Pmt function to calculate the monthly payment for a loan. The format of Pmt is

Pmt(Rate, NPer, PV, FV,Due)

Rate=Interest rate, Nper=Number of payment periods, PV=present value, FV=future value, Due=set to 1 if payment due at the beginning of period and 0 for payment due at end of period.

 

The codes

Private Sub cmd_Compute_Click()
Dim N As Integer
Dim amt, payment, rate As Double
amt = Val(Txt_loan.Text)
rate = (Val(Txt_Int.Text) / 100) / 12
N = Val(Txt_N.Text) * 12
payment = Pmt(rate, N, -amt, 0, 0)
Lbl_payment.Caption = Format(payment, "$#,##0.00")

End Sub

Explanation:

Normally people will just key in the annual interest rate as integer rather than as %, so I have to divide that rate by 100 and then by 12 to get the monthly interest. Why use negative sign for the present value(PV)? Because that is the amount we borrowed, so it must be negative. The future value is set to 0 because by then you have pay up all the payment. Finally, due is set to 0 as the payment is due at end of the month.

 

 

[Back to VB Today]