Calculate how long it will take to pay back a loan
The Payback Period Calculator helps determine how long it will take to repay a loan based on the loan amount, interest rate, and monthly payment. This is calculated using the NPer function in Visual Basic.
The formula uses the following parameters:
Try the calculator below to determine your payback period.
The payback period is calculated using the NPer function, which determines the number of periods for an investment based on periodic, constant payments and a constant interest rate.
Annual rate is converted to monthly rate: monthlyRate = annualRate / 100 / 12
NPer(monthlyRate, monthlyPayment, -loanAmount, 0, 0)
Months to years: years = totalMonths / 12
Below are implementations of the payback period calculation in both VB6 and VB.NET:
Private Sub Command1_Click() Dim payment, Loan, Int_Rate As Double Dim Num_months, Num_years As Single ' Get user input payment = Val(Txt_Payment.Text) Int_Rate = (Val(Txt_Rate.Text) / 100) / 12 ' Convert to monthly rate Loan = Val(Txt_PV.Text) ' Calculate number of months using NPer function Num_months = NPer(Int_Rate, payment, -Loan, 0, 0) Num_years = Num_months / 12 ' Display results Lbl_Years.Caption = Format(Num_years, "0.0") & " years" Lbl_Months.Caption = Format(Num_months, "0") & " months" ' Visualize the payback period Call VisualizePayback(Num_years) End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim payment, loanAmount, annualRate As Double Dim monthlyRate, numMonths, numYears As Double ' Get user input If Not Double.TryParse(txtPayment.Text, payment) Then MessageBox.Show("Please enter a valid payment amount") Return End If If Not Double.TryParse(txtLoanAmount.Text, loanAmount) Then MessageBox.Show("Please enter a valid loan amount") Return End If If Not Double.TryParse(txtInterestRate.Text, annualRate) Then MessageBox.Show("Please enter a valid interest rate") Return End If ' Calculate monthly interest rate monthlyRate = (annualRate / 100) / 12 ' Calculate number of months using Financial.NPer numMonths = Financial.NPer(monthlyRate, payment, -loanAmount, 0, DueDate.EndOfPeriod) numYears = numMonths / 12 ' Display results lblResultYears.Text = numYears.ToString("F1") & " years" lblResultMonths.Text = numMonths.ToString("F0") & " months" ' Visualize the payback period VisualizePayback(numYears) End Sub