SR-mf-003, Mortgage Payment Calculator #20

‘Programmer: Me
‘Class: POS/409
‘Project:Mortgage Payment Calculator – Change Request #20
‘   Write the program in VB.Net (not Web based) with a graphical user interface.
‘   Have the user input the amount of the mortgage, the term of the mortgage and the interest rate.
‘   Display the mortgage payment amount based on the user’s inputs.
‘   Allow the user to loop back and enter new data or quit.
‘   Insert comments to document the program.
‘Version:2.02
‘Version Notes:
‘   1: Set up GUI
‘       Input Mortgage equation
‘   2: Set up validation and error checking
‘   2.01: Corrected some minor misspellings and deleted some unnesessary code

Public Class Form1

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
‘declare variables
Dim varMortgageAmount As Double
Dim varInterestRate As Double
Dim varMortgageLength As Double
Dim varMortgagePayment As Double
Dim varMonthlyInterestRate As Double
Dim varMortgageLengthInMonths As Double

‘Make sure only numeric, usable data is entered.
If txtMortgageAmount.Text <> “” And txtMortgageAmount.Text <> “” And txtMortgageAmount.Text <> “” Then ‘Not Blank
Try
‘Enter data into variables
varMortgageAmount = Double.Parse(txtMortgageAmount.Text)
varInterestRate = Double.Parse(txtInterestRate.Text)
varMortgageLength = Double.Parse(txtMortgageLength.Text)

‘P = principal, the initial amount of the loan
‘I = the annual interest rate (from 1 to 100 percent)
‘L = length, the length (in years) of the loan, or at least the length over which the loan is amortized.
‘The following assumes a typical conventional loan where the interest is compounded monthly.
‘First I will define two more variables to make the calculations easier:
‘J = monthly interest in decimal form = I / (12 x 100)
varMonthlyInterestRate = varInterestRate / (12 * 100)

‘N = number of months over which loan is amortized = L x 12
varMortgageLengthInMonths = -(varMortgageLength * 12)

‘M = P * ( J / (1 – (1 + J) ^ -N))
varMortgagePayment = varMortgageAmount * (varMonthlyInterestRate / (1 – (1 + varMonthlyInterestRate) ^ varMortgageLengthInMonths))

‘Display Mortgage Payment on form as currency
txtMortgagePayment.Text = (varMortgagePayment).ToString(“C”)

Catch ‘NonNumeric Data
MessageBox.Show(“Nonnumeric data entered.  Please only enter numeric data”, “Data Entry Error”, MessageBoxButtons.OK)
End Try
Else ‘data missing
MessageBox.Show(“Please fill out Mortgage Amount, Interest Rate, And Mortgage Length”, “Data Entry Error”, MessageBoxButtons.OK)
End If

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
‘clears text boxes
txtMortgageAmount.Text = “”
txtInterestRate.Text = “”
txtMortgageLength.Text = “”
txtMortgagePayment.Text = “”
End Sub

Private Sub ExiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExiToolStripMenuItem.Click
‘closes the program
Me.Close()
End Sub

Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
MessageBox.Show(“Programmed by Jocelyn Williams”, “POS/409”, MessageBoxButtons.OK)
End Sub

Private Sub InstructionsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InstructionsToolStripMenuItem.Click
MessageBox.Show(“Enter the amount of the mortgage requested into the mortgage amount box, the monthly interest rate into the interest rate box, and the length of the mortgage(in years) into the mortgage length box.  Hit the calculate button to learn the monthly payment amount.  Press clear to enter new mortgage data.”, “Instructions”, MessageBoxButtons.OK)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘clears text boxes
txtMortgageAmount.Text = “”
txtInterestRate.Text = “”
txtMortgageLength.Text = “”
txtMortgagePayment.Text = “”
End Sub
End Class
?

© 2010, Within this mind. All rights reserved.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Blogosphere
  • Fark
  • Google Buzz
  • LinkedIn
  • Reddit
  • Slashdot
  • Suggest to Techmeme via Twitter

About Kinda Strange

I am a student at the University of Phoenix majoring in information technology. This is where I come to babble incoherently…err…make notes, talk about things that catch my interest, share ideas, etc...
This entry was posted in Homework and tagged . Bookmark the permalink.

Comments are closed.