HELP HELP HELP HELP Amortize results not displaying correctly in ListView
Hi All,
I am hoping you can help me understand what I am missing or have incorrect in the below code. This is a simple loan calculator that in turn should display amortization schedule through the ListView. however, I am getting "some" data to return but it isn't correct. Can you please help me understand this as I have this as a project that I have to turn in this week. Any help will be greatly appreciated :-)
Also, as shown below in the screenshot, it displays some of the data, but incorrectly.
Code:
Dim Num, n1 As Integer
Dim I, P, PVIFA, r, lnpmt, PI, PP As Double
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
P = txtLoanAmount.Text
Num = txtMonths.Text
r = txtInterestRate.Text
I = r / 100
PVIFA = 1 / I - 1 / (I * (1 + I) ^ Num)
lnpmt = P / PVIFA
lblTotal.Text = Math.Round(lnpmt, 2)
End Sub
Private Sub btnAmortize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAmortize.Click
Do
n1 = n1 + 1
PI = P * I
PP = lnpmt - PI
P = P - PP
ListView1.Items.Add(n1.ToString())
ListView1.Items.Add(PP.ToString("$,####.00"))
ListView1.Items.Add(PI.ToString("C"))
ListView1.Items.Add(P.ToString("$,####.00"))
ListView1.Items.Add(lnpmt.ToString("$,####.00"))
If P = 0 Then
End If
Exit Do
Loop
End Sub
Re: HELP HELP HELP HELP Amortize results not displaying correctly in ListView
Apparently your formula is wrong, to begin with. This is how it should be.
Let:
A : Amount borrowed
N : Number of months (in this example)
I : Interest rate = I / 1200 (convert annual interest rate to monthly rate)
P : Payment
W : Principal
The payment is calculated by this formula:
P = (A x I)/(1-(1 + I)^(-N))
Now that P is defined, let's calculate the other variables. Note that I'm just using
pseudocode"
For a As Integer = 1 To N
If a <> N Then
InterestAmount = A * I
W = P - InterestAmount
A = A - W
Else
InterestAmount = A * I
W = A
P = W + InterestAmount
A = 0
End If