 # Loan Payments Calculator

If you have taken a loan such as mortgage for a property you purchase, you often find it hard to calculate the monthly payments. Fortunately, you can create a loan payments calculator in Visual Basic 6. Visual basic 6 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 number of periods for an annuity

To create a loan payment calculator, we can use the Pmt function. 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 Code

```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 we 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 paid up all the payments. Finally, due is set to 0 as the payment is due at end of the month.