Public Class frmMortgageCalculator
Private Sub frmMortgageCalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Setting control attributes used in the form when it loads
Me.lblMonthlyPayment.Visible = False
Me.txtLoanAmount.Focus()
Me.btnCalculate.Enabled = False
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
' Actions that occur when the Calculate button is clicked.
Me.lblMonthlyPayment.Visible = True
' Variable declarations.
Dim strLoanAmount As String
Dim dblLoanAmount As Double
Dim strIntRate As String
Dim dblIntRate As Double
Dim strLoanTerm As String
Dim intloanTerm As Integer
Try
strLoanAmount = txtLoanAmount.Text
If Not IsNumeric(strLoanAmount) Then
MessageBox.Show("Please enter a valid loan amount")
Me.txtLoanAmount.Clear()
Me.txtLoanAmount.Focus()
End If
dblLoanAmount = Convert.ToDouble(strLoanAmount)
Catch ex As Exception
End Try
Try
strIntRate = txtIntRate.Text
If Not IsNumeric(strIntRate) Then
MessageBox.Show("Please enter a valid interest rate")
Me.txtIntRate.Clear()
Me.txtIntRate.Focus()
End If
dblIntRate = Convert.ToDouble(strIntRate / 100)
Catch ex As Exception
End Try
Try
strLoanTerm = txtLoanTerm.Text
If Not IsNumeric(strLoanTerm) Then
MessageBox.Show("Please enter a valid term in years")
Me.txtLoanTerm.Clear()
Me.txtLoanTerm.Focus()
End If
intloanTerm = Convert.ToInt32(strLoanTerm * 12)
Catch ex As Exception
End Try
' Converting APR to monthly rate.
Dim dblMonthlyRate As Double = dblIntRate / 12
' Formula for Calculating monthly payments of a loan
' from data that is input by the user.
Dim dblMonthlyPayment As Double = dblLoanAmount * (dblMonthlyRate * _
Math.Pow((1 + dblMonthlyRate), intloanTerm)) / _
(Math.Pow((1 + dblMonthlyRate), intloanTerm) - 1)
' Displays the monthly payment in currency format.
Me.lblMonthlyPayment.Text = FormatCurrency(dblMonthlyPayment)
' Declaring variable Setting the Payment number to 0.
Dim intPaymentNumber As Integer = 0
' Declaring a new variable to be used in the manipulation
' of two other variables.
Dim dblBalance As Double = dblLoanAmount - dblMonthlyPayment
Dim dblInterestPaid As Double = dblBalance * dblMonthlyRate
Dim intCount As Integer = 0
' The loop for displaying the payment #, balance,
' and interset paid.
Do
Me.lblMonthlyPayment.Text = FormatCurrency(dblMonthlyPayment)
dblInterestPaid = dblBalance * dblMonthlyRate
intPaymentNumber = intPaymentNumber + 1
intCount = intCount + 1
dblBalance -= dblMonthlyPayment - dblBalance * dblMonthlyRate
txtBalanceList.Text = txtBalanceList.Text & intPaymentNumber _
& vbTab & " " & FormatCurrency(dblBalance) & vbTab & _
FormatCurrency(dblInterestPaid) & vbNewLine
' Condition for ending the loop.
' This is for the very last payment.
If dblBalance < dblMonthlyPayment Then
dblMonthlyPayment = dblBalance
Exit Do
End If
' Condition for displaying 15 lines, then pausing
' for 1000 miliseconds.
If intCount Mod 12 = 0 Then
txtBalanceList.Selectionstart = txtBalanceList.Text.Length
' Scrols content of the control to the
' current caret position.
txtBalanceList.ScrollToCaret()
' Refreshes screen output.
txtBalanceList.Refresh()
' Pauses the printing to the screen
' for better reading.
System.Threading.Thread.Sleep(500)
End If
Loop Until dblMonthlyPayment <= 0.0
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' For clearing the text in all fields
' when the Clear button is clicked
Me.txtLoanAmount.Clear()
Me.txtIntRate.Clear()
Me.txtLoanTerm.Clear()
Me.txtBalanceList.Clear()
Me.lblMonthlyPayment.Visible = False
End Sub
Private Sub txtLoanAmount_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLoanAmount.TextChanged
'Conditions for enabling the calculate button after
' valid data is entered into these fields.
If txtLoanAmount.Text.Length > 0 And txtIntRate.Text.Length > 0 _
And txtLoanTerm.Text.Length > 0 Then
btnCalculate.Enabled = True
Else
btnCalculate.Enabled = False
End If
End Sub
Private Sub txtIntRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtIntRate.TextChanged
'Conditions for enabling the calculate button after
' text is entered into these fields.
If txtLoanAmount.Text.Length > 0 And txtIntRate.Text.Length > 0 _
And txtLoanTerm.Text.Length > 0 Then
btnCalculate.Enabled = True
Else
btnCalculate.Enabled = False
End If
End Sub
Private Sub txtLoanTerm_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLoanTerm.TextChanged
'Conditions for enabling the calculate button after
' text is entered into these fields.
If txtLoanAmount.Text.Length > 0 And txtIntRate.Text.Length > 0 _
And txtLoanTerm.Text.Length > 0 Then
btnCalculate.Enabled = True
Else
btnCalculate.Enabled = False
End If
End Sub
End Class
Any and all suggestions are greatly appreciated... I just think that my instructor and I speak different languages and perhaps I am not understanding what he is asking of me.

New Topic/Question
Reply



MultiQuote








|