Hello, this problem has been posted before on Chegg and I copied it just as it i
ID: 3852249 • Letter: H
Question
Hello, this problem has been posted before on Chegg and I copied it just as it is shown, but I repeatedly get an "argumentException" error on one of the lines of code. The error comes from the line with: ----- monthlyPay.Text = -Financial.Pmt(rate / 12, 12 * terms, principal) ------ written in the code. When the error displays there is a red underline underneath the last ) after the word principle. If its possible to redo this problem that would be awesome! The problem is from the "Microsoft Visual Basic 2015 RELOADED 6th edition" book, chapter 7, Case Project "Loan Calculator", page 401. Also, I am a beginner with a beginner's experience in using Visual Basic.
Here is the problem:
Here is the given Interface:
Tools in the interface:
Principle: with TextBox
Annual interest rate (%): with ComboBox
Term (years): with ComboBox
Monthly payment: with Label
Principle and interest: with ListBox
Display = Button
Exit = Button
As always, thank you for your help with this!
Explanation / Answer
Ans: ArgumentException is thrown once method is invoked and minimum of one amongst the passed arguments doesn't meet the parameter specification of called_method.
'frm_Loan
Public Class frmLoan
'clear btn
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
' Clears values of the text boxes
' amount
txtAmount.Text = ""
' interest_rate
txtRate.Text = ""
' term
txtDuration.Text = ""
' monthly_payment
txtPayment.Text = ""
End Sub
' calculate
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
' checks if invalid enters
' true
If InputIsValid() = True Then
' calculates
CalculateValue()
' if false
Else
' error
MessageBox.Show("please enter data")
End If
' end
End Sub
' boolean
Function InputIsValid() As Boolean
' IF true
Dim blank As Boolean = True
' TRUE
If (radAmount.Checked = True) Then
' if blank
blank = False
' principle amount
ElseIf txtAmount.Text = "" Then
' true
blank = True
End If
' term
If (radDuration.Checked = True) Then
' false_blank
blank = False
ElseIf txtDuration.Text = "" Then
blank = True
End If
' monthly pay
If (radPayment.Checked = True) Then
' blank
blank = False
' true
ElseIf txtPayment.Text = "" Then
blank = True
End If
' interest rate checked
If (radRate.Checked = True) Then
' false
blank = False
ElseIf txtRate.Text = "" Then
' true
blank = True
End If
' return
Return (blank = False)
' ends functn
End Function
' calculation
Sub CalculateValue()
' if checked
If radAmount.Checked = True Then
' calc
txtAmount.Text = PV(CDbl(txtRate.Text) / 1200, CDbl(txtDuration.Text), -CDbl(txtPayment.Text)).ToString("C")
End If
' calcultn part
' if checked
If radRate.Checked = True Then
txtRate.Text = (1200 * Rate(CDbl(txtDuration.Text), CDbl(txtPayment.Text), -CDbl(txtAmount.Text))).ToString("N1")
End If
' term
' if checked
If radDuration.Checked = True Then
' formula
txtDuration.Text = NPer(CDbl(txtRate.Text) / 1200, CDbl(txtPayment.Text), -CDbl (txtAmount.Text)).ToString("N0")
End If
' monthly payment
' if checked
If radPayment.Checked = True Then
' calculation
txtPayment.Text = Pmt(CDbl(txtRate.Text) / 1200, CDbl(txtDuration.Text), -CDbl (txtAmount.Text)).ToString("C")
End If
' ends
End Sub
' ends class
End Class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.