' Project Mortgage2 Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents txtPrincipal As System.Windows.Forms.TextBox Friend WithEvents txtRate As System.Windows.Forms.TextBox Friend WithEvents txtYears As System.Windows.Forms.TextBox Friend WithEvents txtPayment As System.Windows.Forms.TextBox Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents txtCompute As System.Windows.Forms.Button Private Sub InitializeComponent() Me.txtPrincipal = New System.Windows.Forms.TextBox Me.txtRate = New System.Windows.Forms.TextBox Me.txtYears = New System.Windows.Forms.TextBox Me.txtPayment = New System.Windows.Forms.TextBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label4 = New System.Windows.Forms.Label Me.txtCompute = New System.Windows.Forms.Button Me.SuspendLayout() ' 'txtPrincipal ' Me.txtPrincipal.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtPrincipal.Location = New System.Drawing.Point(32, 24) Me.txtPrincipal.Name = "txtPrincipal" Me.txtPrincipal.Size = New System.Drawing.Size(208, 31) Me.txtPrincipal.TabIndex = 0 Me.txtPrincipal.Text = "" ' 'txtRate ' Me.txtRate.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtRate.Location = New System.Drawing.Point(32, 72) Me.txtRate.Name = "txtRate" Me.txtRate.Size = New System.Drawing.Size(208, 31) Me.txtRate.TabIndex = 1 Me.txtRate.Text = "" ' 'txtYears ' Me.txtYears.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtYears.Location = New System.Drawing.Point(32, 120) Me.txtYears.Name = "txtYears" Me.txtYears.Size = New System.Drawing.Size(208, 31) Me.txtYears.TabIndex = 2 Me.txtYears.Text = "" ' 'txtPayment ' Me.txtPayment.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.txtPayment.Location = New System.Drawing.Point(32, 184) Me.txtPayment.Name = "txtPayment" Me.txtPayment.ReadOnly = True Me.txtPayment.Size = New System.Drawing.Size(208, 31) Me.txtPayment.TabIndex = 3 Me.txtPayment.Text = "" ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(248, 24) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(168, 32) Me.Label1.TabIndex = 5 Me.Label1.Text = "Principal ($)" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(248, 72) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(168, 32) Me.Label2.TabIndex = 6 Me.Label2.Text = "Rate (%)" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(248, 120) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(184, 32) Me.Label3.TabIndex = 7 Me.Label3.Text = "Duration (Years)" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(248, 184) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(224, 32) Me.Label4.TabIndex = 8 Me.Label4.Text = "Monthly Payment ($)" ' 'txtCompute ' Me.txtCompute.Location = New System.Drawing.Point(88, 240) Me.txtCompute.Name = "txtCompute" Me.txtCompute.Size = New System.Drawing.Size(320, 40) Me.txtCompute.TabIndex = 4 Me.txtCompute.Text = "Compute Monthly Payment" ' 'Form1 ' Me.AcceptButton = Me.txtCompute Me.AutoScaleBaseSize = New System.Drawing.Size(11, 24) Me.ClientSize = New System.Drawing.Size(496, 318) Me.Controls.Add(Me.txtCompute) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.txtPayment) Me.Controls.Add(Me.txtYears) Me.Controls.Add(Me.txtRate) Me.Controls.Add(Me.txtPrincipal) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "Form1" Me.Text = "Monthly Payment Calculator" Me.ResumeLayout(False) End Sub #End Region Private Sub txtCompute_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles txtCompute.Click Dim n As Integer Dim p, r, m As Double p = txtPrincipal.Text r = txtRate.Text n = txtYears.Text m = (p * r / 1200) / (1 - (1 + r / 1200) ^ (-12 * n)) txtPayment.Text = m.ToString("#0.00") End Sub Private Sub EnterHandler(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles _ txtPrincipal.Enter, txtRate.Enter, txtYears.Enter, txtPayment.Enter CType(sender, TextBox).ForeColor = Color.Blue End Sub Private Sub LeaveHandler(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles _ txtPrincipal.Leave, txtRate.Leave, txtYears.Leave, txtPayment.Leave CType(sender, TextBox).ForeColor = Color.Black End Sub End Class