Public Class Form1

    Inherits System.Windows.Forms.Form

 

    ' Name: Jim Lane

    ' Assignment Number P2

    ' Date: September 15, 2005

    ' Description: This program will calculate monthly mortgage and

    ' lifetime interest payments based on loan amount, interest rate,

    ' and duration. It includes error checking.

 

    Private Sub cmdCalcPayment_Click(ByVal sender As System.Object, _
       ByVal
e As System.EventArgs) Handles cmdCalcPayment.Click

 

        ' Declare number of payments per year as constant

        Const paymentsPerYear As Integer = 12

 

        ' Declare variables

        Dim loanAmount As Decimal = 0

        Dim percent As Single = 0

        Dim loanDuration As Integer = 0

        Dim totalPayments As Integer = 0

        Dim decIntPerPayment As Decimal = 0

        Dim decIntPerYr As Decimal = 0

        Dim factor As Decimal = 0

        Dim paySize As Decimal = 0

        Dim totalInt As Decimal = 0

 

        ' Read variables input by user

        loanAmount = txtLoanAmount.Text

        percent = txtPercent.Text

        loanDuration = txtLoanDuration.Text

 

        ' Perform calculations to determine monthly payment and

        ' lifetime interest

        totalPayments = loanDuration * paymentsPerYear

        decIntPerYr = percent / 100

        decIntPerPayment = decIntPerYr / paymentsPerYear

        factor = (1 - ((1 + decIntPerPayment) ^ -totalPayments)) / decIntPerPayment

        paySize = loanAmount / factor

        totalInt = (paySize * paymentsPerYear * loanDuration) - loanAmount

 

        ' Display output

        txtPaySize.Text = FormatCurrency(paySize)

        txtTotalInt.Text = FormatCurrency(totalInt)

 

        ' Move focus to Exit button

        cmdExit.Focus()

    End Sub

 

    ' The Me.Close statement closes the current form. When the last

    ' loaded form in a program is closed, the application is terminated.

    ' To terminate the entire application regardless of how many forms

    ' are open, call Application.Exit().

    Private Sub cmdExit_Click(ByVal sender As System.Object, _
       ByVal
e As System.EventArgs) Handles cmdExit.Click

         ' terminate program

        Me.Close

    End Sub

 

End Class