Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,565 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,890 people online right now. Registration is fast and FREE... Join Now!




Struggling with the Financial.Pmt method

 
Reply to this topicStart new topic

Struggling with the Financial.Pmt method, Financial.Pmt trouble

XiJiangWoo
6 Apr, 2008 - 12:49 PM
Post #1

New D.I.C Head
*

Joined: 6 Apr, 2008
Posts: 15

Hello All,

I have been given an assignment in my VB crash course and I'm stuck on the Financial.Pmt method. The program is a loan calculator that has the user input the total amout of the loan, interest rate, and term in years. The program should then display the "total" overall interest to be paid and the total amount to be repaid. I think I am stuck on the Financial.PMT method.
Any help is greatly appreciated. I have my code shown below.


CODE
' Project name: Quick loans calculator
' Project purpose: The project allows a user to enter a loan amount, interest rate,
'                  and term. The project calculates and displays,
'                  the total amount of interest and the total amount to be repaid

Option Explicit On
Option Strict Off

Imports System.Globalization

Public Class Form1



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click
        ' calculates the total interest and total amout to be repaid

        ' declare constants and variables
        Dim Rate As Decimal
        Dim Term As Decimal
        Dim PV As Decimal
        Dim totalInterest As Decimal
        Dim totalAmount As Decimal
        Dim monthlyPayment As Decimal
        Dim isconverted As Boolean

        ' setting values to each variable
        Rate = interestTextBox.Text
        Term = termTextBox.Text
        PV = amountTextBox.Text

        ' convert input to numbers
        isconverted = Decimal.TryParse(amountTextBox.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, PV)
        isconverted = Decimal.TryParse(interestTextBox.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, Rate)
        isconverted = Decimal.TryParse(termTextBox.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, Term)

        monthlyPayment = Convert.ToDecimal(-Financial.Pmt(Rate / 12, Term * 12, PV))


        'totalInterest = PV * Rate * Term

        interestLabel.Text = Convert.ToString(totalInterest)
        totalLabel.Text = Convert.ToString(totalAmount)


    End Sub
End Class

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Struggling With The Financial.Pmt Method
6 Apr, 2008 - 12:59 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You need to tell us what the problem is. Are you getting an error? Is it not calculating right? We need a good detailed explanation of what the problem is smile.gif

Also, since you code is VB.Net I'm moving this to the VB.NET Forum smile.gif
User is offlineProfile CardPM
+Quote Post

XiJiangWoo
RE: Struggling With The Financial.Pmt Method
6 Apr, 2008 - 02:09 PM
Post #3

New D.I.C Head
*

Joined: 6 Apr, 2008
Posts: 15

The problem is I cannot get it to work. I have altered it a bunch of times and I am lost.
User is offlineProfile CardPM
+Quote Post

XiJiangWoo
RE: Struggling With The Financial.Pmt Method
7 Apr, 2008 - 02:29 PM
Post #4

New D.I.C Head
*

Joined: 6 Apr, 2008
Posts: 15

Okay, I modified the code but I am still not getting the proper modification.

Here is what I have.

CODE

Option Explicit On
Option Strict Off

Imports System.Globalization

Public Class Form1



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub calcButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcButton.Click
        ' calculates the total interest and total amout to be repaid

        ' declare constants and variables
        Dim Rate As Decimal
        Dim Term As Decimal
        Dim Loan As Decimal
        Dim totalInterest As Decimal
        Dim monthlyPayment As Decimal
        Dim repaid As Decimal
        Dim isconverted As Boolean

        'declare variables
        Rate = (interestTextBox.Text * 0.01)



        
        ' convert input to numbers
        isconverted = Decimal.TryParse(amountTextBox.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, Loan)
        isconverted = Decimal.TryParse(interestTextBox.Text, Rate)
        isconverted = Decimal.TryParse(termTextBox.Text, Term)

        ' calculate payment, amount repaid, and amount of interest
        monthlyPayment = Convert.ToDecimal(-Financial.Pmt(Rate / 12, Term * 12, Loan))
        repaid = Term * 12 * monthlyPayment
        totalInterest = repaid - Loan

        ' display amount repaid and amount of interest
        totalLabel.Text = repaid.ToString("C2")
        interestLabel.Text = totalInterest.ToString("C2")


        ' set the focus
        amountTextBox.Focus()


    End Sub
End Class


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:48PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month