I am writing a mortgage calculator that will populate a DataGridView all the payments and how much interest and principal for each payment. Then the last column is the remaining balance after the payment.
Here is the problem:
The Mortgage payment, interest and principal calculations are all good, but for some reason the remaining balance calculation seems wrong because at the end of the payment period there is still a large balance.
My code may be sloppy, because I am still new to vb. In fact it's my first class.
Private Sub AmortButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AmortButton.Click 'initiate click event'
Dim Amt As Double = Amount.Text() 'read in amount'
Dim Intr As Double = Intrest.Text() 'read in intrest'
Dim Yrs As Double = Term.Text() 'read in years'
Dim payment As Double = (Yrs * 12) 'convert years to payment periods
'
Dim IntrDec As Double = ((Intr / 100) / 12) 'convert APR to monthly rate as a decimal'
Dim TempAmt As Double = Amt 'setting Temperory balance
For i As Double = 1 To payment Step i + 1 'setting for-loop paramaters'
Dim MP = Math.Round((Pmt(IntrDec, payment, Amt) * -1), 2) 'calculate Mortgage payment'
Dim IP = Math.Round((IPmt(IntrDec, i, payment, Amt) * -1), 2) 'calculate Intrest paid'
Dim PP = Math.Round((PPmt(IntrDec, i, payment, Amt) * -1), 2) 'calculate priciple paid
Amt = Amt - PP 'setting new balance'
Dim RM = Math.Round((Amt), 2) 'rounding balance to two decimals'
AmortTable.Rows.Add(i, MP, IP, PP, RM) 'adding row entry to table'
Next 'end for-loop'