# Creating a Loan Calculator in VB

• ### Question

• Hello,

I am trying to create a Loan Calculator but I cannot get the payments to come out correctly, the decimal point is in the wrong place and the payment amounts are way off.

' Project name: Loan Calculator
' Project purpose: Display the principal and interest of a loan

Option Explicit On
Option Infer Off
Option Strict Off

Public Class MainForm
Private Sub exitButton_Click(sender As Object, e As EventArgs) Handles exitButton.Click
Me.Close()
End Sub

Private Sub DisplayButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayButton.Click
Dim Rate As Double
Dim Per As Integer
Dim NPer As Double
Dim PV As Double
Dim Principal As Double
Dim Interest As Double

Rate = ((airComboBox.Text / 100) / 12)
NPer = (termComboBox.Text * 12)
PV = pTextBox.Text
piListBox.Items.Add("Principal " & vbTab & "Interest")
For Per = 1 To NPer
' calculate Principle using Financial method
Principal = -Financial.PPmt(Rate, Per, NPer, PV)
'interest calculation
Interest = Principal * Rate
piListBox.Items.Add(Format(Principal, "0.00") & vbTab & Interest)
mpTextBox.Text = -Financial.Pmt(Rate, NPer, PV:=Principal)
Next
End Sub
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For rate As Decimal = 2 To 10 Step 1
Next
For term As Integer = 1 To 30 Step 1
Next
End Sub
End Class

Wednesday, September 26, 2018 11:55 PM

• Hi ,

Interest=

`-Financial.IPmt(Rate, Per, NPer, PV)`
not Principal*Rate
```Public Class Form1
Dim Rate As Double
Dim Per As Integer
Dim NPer As Double
Dim PV As Double
Dim Principal As Double
Dim Interest As Double
For rate_ As Decimal = 2 To 10 Step 1
Next
For term As Integer = 1 To 30 Step 1
Next

End Sub

Private Sub DisplayButton_Click(sender As Object, e As EventArgs) Handles DisplayButton.Click
Rate = ((airComboBox.Text / 100) / 12)
NPer = (termComboBox.Text * 12)
PV = pTextBox.Text
piListBox.Items.Add("Principal " & vbTab & "Interest")
For Per = 1 To NPer
'calculate Principle using Financial method
Principal = -Financial.PPmt(Rate, Per, NPer, PV)

'Interest calculation
Interest = -Financial.IPmt(Rate, Per, NPer, PV)
piListBox.Items.Add(Format(Principal, "0.00") & vbTab & Interest)
mpTextBox.Text = -Financial.Pmt(Rate, Per, PV, 1)
Next

End Sub

End Class
```

Best Regards,

Alex

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Marked as answer by Friday, September 28, 2018 4:13 PM
• Unmarked as answer by Friday, September 28, 2018 5:15 PM
• Marked as answer by Friday, September 28, 2018 5:15 PM
Friday, September 28, 2018 7:00 AM

### All replies

• Hi RedWar12,

Welcome to the MSDN forum.

Refer to your description, your issue is about VB.NET development. Since our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum for a better support, thank you for your understanding.

Best regards,

Sara

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

Friday, September 28, 2018 3:30 AM
• Hi ,

Interest=

`-Financial.IPmt(Rate, Per, NPer, PV)`
not Principal*Rate
```Public Class Form1
Dim Rate As Double
Dim Per As Integer
Dim NPer As Double
Dim PV As Double
Dim Principal As Double
Dim Interest As Double
For rate_ As Decimal = 2 To 10 Step 1
Next
For term As Integer = 1 To 30 Step 1
Next

End Sub

Private Sub DisplayButton_Click(sender As Object, e As EventArgs) Handles DisplayButton.Click
Rate = ((airComboBox.Text / 100) / 12)
NPer = (termComboBox.Text * 12)
PV = pTextBox.Text
piListBox.Items.Add("Principal " & vbTab & "Interest")
For Per = 1 To NPer
'calculate Principle using Financial method
Principal = -Financial.PPmt(Rate, Per, NPer, PV)

'Interest calculation
Interest = -Financial.IPmt(Rate, Per, NPer, PV)
piListBox.Items.Add(Format(Principal, "0.00") & vbTab & Interest)
mpTextBox.Text = -Financial.Pmt(Rate, Per, PV, 1)
Next

End Sub

End Class
```

Best Regards,

Alex

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Marked as answer by Friday, September 28, 2018 4:13 PM
• Unmarked as answer by Friday, September 28, 2018 5:15 PM
• Marked as answer by Friday, September 28, 2018 5:15 PM
Friday, September 28, 2018 7:00 AM