Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27212

VS 2010 [RESOLVED] Financial.Pmt Help

$
0
0
I am trying to get a program to work for class...but obviously it is not working. I have spent 5 hours trying to figure out what is wrong and have rewritten this several times to no avail.

Here are the basics:
  1. Create application to calculate monthly car payments for 2 financing options
  2. Option 1: Dealer financing using just the price, interest rate and term of loan
  3. Option 2: Bank financing using price, rebate, bank interest rate, and term of loan
  4. Display each result in appropriate payment boxes

The test values are:
Price = 22000
Rebate = 1500
Dealer Rate = 0.02
Bank Rate = 0.08
Term = 5

The returned values should be:
Dealer = $385.61
Bank = $415.67

I have attached a screenshot of what I end up with.
Attachment 95587

Here is what I have at the moment:

Code:

Option Strict On

Public Class Form

    Private Dealer As Double
    Private Bank As Double

    Private Sub DealerPrice()
        Dim DRate As Double = CDbl(dealerBox.SelectedItem)
        Dim Price As Double
        Dim Rebate As Double
        Dim Term As Integer = CInt(termBox.SelectedItem)
        Dim DPayment As Double

        'Converts variables
        Double.TryParse(priceBox.Text, Price)
        Double.TryParse(rebateBox.Text, Rebate)

        If Price > 0 And Rebate > 0 Then
            DPayment = Financial.Pmt(DRate / 12, Term * 12, Price)
            Dealer = DPayment

        End If

    End Sub

    Private Sub BankPrice()
        Dim BRate As Double = CDbl(bankBox.SelectedItem)
        Dim Price As Double
        Dim Rebate As Double
        Dim BPrice As Double = Price - Rebate
        Dim Term As Integer = CInt(termBox.SelectedItem)
        Dim BPayment As Double

        'Converts variables
        Double.TryParse(priceBox.Text, Price)
        Double.TryParse(rebateBox.Text, Rebate)

        If Price > 0 And Rebate > 0 Then
            BPayment = Financial.Pmt(BRate / 12, Term * 12, BPrice)
            Bank = BPayment
        End If
    End Sub

    'Load default values to list boxes

    Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'Add Items to dealerBox
        dealerBox.Items.Add("0.02")
        dealerBox.Items.Add("0.03")
        dealerBox.Items.Add("0.04")
        dealerBox.Items.Add("0.05")
        dealerBox.Items.Add("0.06")
        dealerBox.Items.Add("0.07")
        dealerBox.Items.Add("0.08")
        dealerBox.Items.Add("0.09")

        'Add Items to bankBox
        bankBox.Items.Add("0.02")
        bankBox.Items.Add("0.03")
        bankBox.Items.Add("0.04")
        bankBox.Items.Add("0.05")
        bankBox.Items.Add("0.06")
        bankBox.Items.Add("0.07")
        bankBox.Items.Add("0.08")
        bankBox.Items.Add("0.09")

        'Add Items to termBox
        termBox.Items.Add("2")
        termBox.Items.Add("3")
        termBox.Items.Add("4")
        termBox.Items.Add("5")

        'Set Default list box items
        dealerBox.SelectedIndex = 0
        bankBox.SelectedIndex = 0
        termBox.SelectedIndex = 0

    End Sub

    '------------------------------------------------------------------------
    'priceBox and bankBox KeyPress Event Procedure/salvageBox KeyPress Event Procedure
    '------------------------------------------------------------------------

    Private Sub priceBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles priceBox.KeyPress
        'Only numbers, period, and Backspace are accepted
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
            e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If
    End Sub

    Private Sub bankBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles bankBox.KeyPress
        'Only numbers, period, and Backspace are accepted
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
            e.KeyChar <> "." AndAlso e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If

    End Sub

    '------------------------------------------------------------------------
    'exitButton Click Event Procedure.
    '------------------------------------------------------------------------

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

    '------------------------------------------------------------------------
    'calcButton Click Event Procedure.
    '------------------------------------------------------------------------

    Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calcButton.Click

        'Clears previous calculated payments from dpymtBox and bpymntBox
        dpymtBox.Text = String.Empty
        bpymtBox.Text = String.Empty

        If priceBox.Text <> String.Empty And rebateBox.Text <> String.Empty Then
            'Calculate payments based upon inputs, display results for each type
            Call DealerPrice()
            Call BankPrice()
        Else
            MsgBox("Must enter a valid sales price and rebate amount!!", CType(vbExclamation + vbOKOnly, MsgBoxStyle), Title:="Input Error")
        End If

        'Display results
        dpymtBox.Text = Dealer.ToString("C2")
        bpymtBox.Text = Bank.ToString("C2")

    End Sub

End Class

Attached Images
 

Viewing all articles
Browse latest Browse all 27212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>