Link to home
Start Free TrialLog in
Avatar of manch03
manch03

asked on

Visual Studio .Net - creating an amortization payment schedule - need help

I am trying to create an amortization schedule where the user can input numbers for the principal and interest amount, term of loan and have the form  list the loan balance and interest paid for each payment over the term of the loan.  The list is longer than the screen, so I have to use loops to display a partial list, hesitate, and then display more of the list.  I have some of it done, but I keep getting a debug error on the variables keyword - I originally had   As Double, but after I added the RichTextFormat, it does not like the keyword As Double.  I have no idea what to change it do.  I am new at this so any help would be much appreciated.  Here is what I have so far.  I am using Visual Studio .Net and the program cannot be web based, just a simple form.  

Public Class Form1
    Inherits System.Windows.Forms.Form
    'To calculate the monthly payment the dbl variable should be declared'

    'declare your variables here
    Dim dblPrincipal, dblRate, dblYears, dblAmount, dblMonths, MyPos, myRichTextBox, interestPaid, loanBalance, As (this is where I am stuck as to the keyword)  I had Double, but it does not like that after I added myRichTextBox,.....

 
#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 Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents ExitButton As System.Windows.Forms.Button
    Friend WithEvents btnCalculate As System.Windows.Forms.Button
    Protected WithEvents txtPrincipal As System.Windows.Forms.TextBox
    Protected WithEvents txtRate As System.Windows.Forms.TextBox
    Protected WithEvents txtYears As System.Windows.Forms.TextBox
    Friend WithEvents MonthlyPayment As System.Windows.Forms.Label
    Friend WithEvents txtAmount As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Protected WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtPrincipal = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtRate = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.txtYears = New System.Windows.Forms.TextBox
        Me.btnCalculate = New System.Windows.Forms.Button
        Me.txtAmount = New System.Windows.Forms.TextBox
        Me.ExitButton = New System.Windows.Forms.Button
        Me.MonthlyPayment = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Label2
        '
        Me.Label2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(8, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(55, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Principal:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtPrincipal
        '
        Me.txtPrincipal.Location = New System.Drawing.Point(16, 60)
        Me.txtPrincipal.Name = "txtPrincipal"
        Me.txtPrincipal.Size = New System.Drawing.Size(48, 20)
        Me.txtPrincipal.TabIndex = 2
        Me.txtPrincipal.Text = "200000"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(96, 40)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(55, 16)
        Me.Label3.TabIndex = 3
        Me.Label3.Text = "Rate:"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtRate
        '
        Me.txtRate.Location = New System.Drawing.Point(104, 60)
        Me.txtRate.Name = "txtRate"
        Me.txtRate.Size = New System.Drawing.Size(32, 20)
        Me.txtRate.TabIndex = 4
        Me.txtRate.Text = "5.75"
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(168, 40)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(80, 16)
        Me.Label4.TabIndex = 5
        Me.Label4.Text = "Term (years):"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtYears
        '
        Me.txtYears.AcceptsTab = True
        Me.txtYears.AllowDrop = True
        Me.txtYears.Location = New System.Drawing.Point(192, 60)
        Me.txtYears.Name = "txtYears"
        Me.txtYears.ReadOnly = True
        Me.txtYears.Size = New System.Drawing.Size(24, 20)
        Me.txtYears.TabIndex = 6
        Me.txtYears.Text = "30"
        '
        'btnCalculate
        '
        Me.btnCalculate.Location = New System.Drawing.Point(0, 100)
        Me.btnCalculate.Name = "btnCalculate"
        Me.btnCalculate.Size = New System.Drawing.Size(120, 24)
        Me.btnCalculate.TabIndex = 7
        Me.btnCalculate.Text = "Calculate Payment"
        '
        'txtAmount
        '
        Me.txtAmount.Location = New System.Drawing.Point(152, 140)
        Me.txtAmount.Name = "txtAmount"
        Me.txtAmount.ReadOnly = True
        Me.txtAmount.Size = New System.Drawing.Size(96, 20)
        Me.txtAmount.TabIndex = 8
        Me.txtAmount.Text = ""
        '
        'ExitButton
        '
        Me.ExitButton.BackgroundImage = CType(resources.GetObject("ExitButton.BackgroundImage"), System.Drawing.Image)
        Me.ExitButton.Location = New System.Drawing.Point(152, 100)
        Me.ExitButton.Name = "ExitButton"
        Me.ExitButton.Size = New System.Drawing.Size(104, 24)
        Me.ExitButton.TabIndex = 9
        Me.ExitButton.Text = "Exit"
        '
        'MonthlyPayment
        '
        Me.MonthlyPayment.Location = New System.Drawing.Point(0, 140)
        Me.MonthlyPayment.Name = "MonthlyPayment"
        Me.MonthlyPayment.Size = New System.Drawing.Size(96, 16)
        Me.MonthlyPayment.TabIndex = 10
        Me.MonthlyPayment.Text = "Monthly Payment"
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(16, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(216, 23)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "Insert Principal Amount, Rate and Term"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label5
        '
        Me.Label5.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(16, 180)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(88, 16)
        Me.Label5.TabIndex = 12
        Me.Label5.Text = "Loan Balance:"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label6
        '
        Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.Location = New System.Drawing.Point(120, 180)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(200, 16)
        Me.Label6.TabIndex = 13
        Me.Label6.Text = "Interest Paid Over Term of Loan:"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(24, 200)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(72, 20)
        Me.TextBox1.TabIndex = 14
        Me.TextBox1.Text = ""
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(160, 200)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.ReadOnly = True
        Me.TextBox2.Size = New System.Drawing.Size(96, 20)
        Me.TextBox2.TabIndex = 15
        Me.TextBox2.Text = ""
        '
        'Form1
        '
        Me.AllowDrop = True
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(322, 348)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.MonthlyPayment)
        Me.Controls.Add(Me.ExitButton)
        Me.Controls.Add(Me.txtAmount)
        Me.Controls.Add(Me.txtYears)
        Me.Controls.Add(Me.txtRate)
        Me.Controls.Add(Me.txtPrincipal)
        Me.Controls.Add(Me.btnCalculate)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.ForeColor = System.Drawing.SystemColors.Desktop
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "Form1"
        Me.Text = "Monthly Mortgage Calculator"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()
        'The close tag must be used in order to allow the user to exit the program.'
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'This is where the values from the textboxes are assigned.'

        'Convert the Loan amount to a double and store in dLoan
        'assign the values from textboxes to the variables
        dblPrincipal = CDbl(txtPrincipal.Text)
        dblRate = CDbl(txtRate.Text)
        dblYears = CDbl(txtYears.Text)
        dblMonths = dblYears * 12
        dblRate = dblRate / 100



        'calculate the final amount as principal + interest
        dblAmount = Pmt(dblRate /12, dblMonths, -dblPrincipal)
        'put the calculated amount in Payment Amount textbox
        txtAmount.Text = dblAmount.ToString("C")
        myRichTextBox.ResetText()    'reset (clear) the contents of the box

        myRichTextBox.AppendText(CStr(interestPaid))
        myRichTextBox.AppendText(CStr(loanBalance))

        myRichTextBox.AppendText(ControlChars.Tab)    'tab to the next column
        myRichTextBox.AppendText(ControlChars.Cr)      'go to a new line
    End Sub


    Private Sub txtPrincipal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrincipal.TextChanged
        MsgBox("Continue", MsgBoxStyle.OKOnly)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Help!

Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

first you need to ADD a RichTextBox control (from the VS.NET ToolBox), and name it MyRichTextBox .  It is NOT a varaible of type Double, but a control that you would place on the form. (remove the MyRichTextBox item from the Dim statement)

What are you trying to accomplish with this RichTextBox control?

AW
Avatar of manch03
manch03

ASKER

My intent with the MyRichTextBox is to display the amortization table.  Is this the best way to go about this?
Avatar of manch03

ASKER

I added the myRichTextBox and I am still getting the error  

'keyword not a valid identifier' in line 7 which is the line I originally had  As Double as an identifier.


    'declare your variables here
    Dim dblPrincipal, dblRate, dblYears, dblAmount, dblMonths, MyPos, myRichTextBox, interestPaid, loanBalance, As Double

My debug comes up with the error 'keyword is not valid as an identifier'

The richtextbox will display the amortization table until it runs of space, I then have to display the information to fill up the box, stop and display more information.  After the box runs out of space, the user will be prompted with a box to ask if they wish to continue with the display.   In order to do that I will have to use nested loops.
Avatar of Mike Tomlinson
Take the comma out before the word "As" and remove "myRichTextBox" so it becomes:

    Dim dblPrincipal, dblRate, dblYears, dblAmount, dblMonths, MyPos, interestPaid, loanBalance As Double
Avatar of manch03

ASKER

I got rid of that error.  Now I just have no data after adding the RichTextBox.  Originally I added one richtextbox, thought I got rid of it, because it does not appear when I debug, but it will not let me name my new one which is the size I want MyRichTextBox - only MyRichTextBox1.  When I debug - it prompts me to continue, so I must have put some code in there someplace to continue.  Here is what I have now.

'declare your variables here
    Dim dblPrincipal, dblRate, dblYears, dblAmount, dblMonths, MyPos As Double


 
#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 Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents ExitButton As System.Windows.Forms.Button
    Friend WithEvents btnCalculate As System.Windows.Forms.Button
    Protected WithEvents txtPrincipal As System.Windows.Forms.TextBox
    Protected WithEvents txtRate As System.Windows.Forms.TextBox
    Protected WithEvents txtYears As System.Windows.Forms.TextBox
    Friend WithEvents MonthlyPayment As System.Windows.Forms.Label
    Friend WithEvents txtAmount As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents MyRichTextBox As System.Windows.Forms.RichTextBox
    Friend WithEvents MyRichTextBox1 As System.Windows.Forms.RichTextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtPrincipal = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtRate = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.txtYears = New System.Windows.Forms.TextBox
        Me.btnCalculate = New System.Windows.Forms.Button
        Me.txtAmount = New System.Windows.Forms.TextBox
        Me.ExitButton = New System.Windows.Forms.Button
        Me.MonthlyPayment = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.MyRichTextBox1 = New System.Windows.Forms.RichTextBox
        Me.SuspendLayout()
        '
        'Label2
        '
        Me.Label2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(8, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(55, 16)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Principal:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtPrincipal
        '
        Me.txtPrincipal.Location = New System.Drawing.Point(16, 60)
        Me.txtPrincipal.Name = "txtPrincipal"
        Me.txtPrincipal.Size = New System.Drawing.Size(48, 20)
        Me.txtPrincipal.TabIndex = 2
        Me.txtPrincipal.Text = "200000"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(96, 40)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(55, 16)
        Me.Label3.TabIndex = 3
        Me.Label3.Text = "Rate:"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtRate
        '
        Me.txtRate.Location = New System.Drawing.Point(104, 60)
        Me.txtRate.Name = "txtRate"
        Me.txtRate.Size = New System.Drawing.Size(32, 20)
        Me.txtRate.TabIndex = 4
        Me.txtRate.Text = "5.75"
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(168, 40)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(80, 16)
        Me.Label4.TabIndex = 5
        Me.Label4.Text = "Term (years):"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'txtYears
        '
        Me.txtYears.AcceptsTab = True
        Me.txtYears.AllowDrop = True
        Me.txtYears.Location = New System.Drawing.Point(192, 60)
        Me.txtYears.Name = "txtYears"
        Me.txtYears.ReadOnly = True
        Me.txtYears.Size = New System.Drawing.Size(24, 20)
        Me.txtYears.TabIndex = 6
        Me.txtYears.Text = "30"
        '
        'btnCalculate
        '
        Me.btnCalculate.Location = New System.Drawing.Point(0, 100)
        Me.btnCalculate.Name = "btnCalculate"
        Me.btnCalculate.Size = New System.Drawing.Size(120, 24)
        Me.btnCalculate.TabIndex = 7
        Me.btnCalculate.Text = "Calculate Payment"
        '
        'txtAmount
        '
        Me.txtAmount.Location = New System.Drawing.Point(152, 140)
        Me.txtAmount.Name = "txtAmount"
        Me.txtAmount.ReadOnly = True
        Me.txtAmount.Size = New System.Drawing.Size(96, 20)
        Me.txtAmount.TabIndex = 8
        Me.txtAmount.Text = ""
        '
        'ExitButton
        '
        Me.ExitButton.BackgroundImage = CType(resources.GetObject("ExitButton.BackgroundImage"), System.Drawing.Image)
        Me.ExitButton.Location = New System.Drawing.Point(152, 100)
        Me.ExitButton.Name = "ExitButton"
        Me.ExitButton.Size = New System.Drawing.Size(104, 24)
        Me.ExitButton.TabIndex = 9
        Me.ExitButton.Text = "Exit"
        '
        'MonthlyPayment
        '
        Me.MonthlyPayment.Location = New System.Drawing.Point(0, 140)
        Me.MonthlyPayment.Name = "MonthlyPayment"
        Me.MonthlyPayment.Size = New System.Drawing.Size(96, 16)
        Me.MonthlyPayment.TabIndex = 10
        Me.MonthlyPayment.Text = "Monthly Payment"
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(16, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(216, 23)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "Insert Principal Amount, Rate and Term"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label5
        '
        Me.Label5.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.Location = New System.Drawing.Point(16, 180)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(88, 16)
        Me.Label5.TabIndex = 12
        Me.Label5.Text = "Loan Balance:"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label6
        '
        Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.Location = New System.Drawing.Point(120, 180)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(200, 16)
        Me.Label6.TabIndex = 13
        Me.Label6.Text = "Interest Paid Over Term of Loan:"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'MyRichTextBox1
        '
        Me.MyRichTextBox1.Location = New System.Drawing.Point(8, 200)
        Me.MyRichTextBox1.Name = "MyRichTextBox1"
        Me.MyRichTextBox1.Size = New System.Drawing.Size(296, 140)
        Me.MyRichTextBox1.TabIndex = 14
        Me.MyRichTextBox1.Text = ""
        '
        'Form1
        '
        Me.AllowDrop = True
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(322, 348)
        Me.Controls.Add(Me.MyRichTextBox1)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.MonthlyPayment)
        Me.Controls.Add(Me.ExitButton)
        Me.Controls.Add(Me.txtAmount)
        Me.Controls.Add(Me.txtYears)
        Me.Controls.Add(Me.txtRate)
        Me.Controls.Add(Me.txtPrincipal)
        Me.Controls.Add(Me.btnCalculate)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.ForeColor = System.Drawing.SystemColors.Desktop
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "Form1"
        Me.Text = "Monthly Mortgage Calculator"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()
        'The close tag must be used in order to allow the user to exit the program.'
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'This is where the values from the textboxes are assigned.'

        'Convert the Loan amount to a double and store in dLoan
        'assign the values from textboxes to the variables
        dblPrincipal = CDbl(txtPrincipal.Text)
        dblRate = CDbl(txtRate.Text)
        dblYears = CDbl(txtYears.Text)
        dblMonths = dblYears * 12
        dblRate = dblRate / 100



        'calculate the final amount as principal + interest
        dblAmount = Pmt(dblRate /12, dblMonths, -dblPrincipal)
        'put the calculated amount in Payment Amount textbox
        txtAmount.Text = dblAmount.ToString("C")

    End Sub


    Private Sub txtPrincipal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrincipal.TextChanged
        MsgBox("Continue", MsgBoxStyle.OKOnly)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

End Class
here is where the 'prompt' to continue is coming from:

    Private Sub txtPrincipal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrincipal.TextChanged
        MsgBox("Continue", MsgBoxStyle.OKOnly)
    End Sub
 at the very bottom of the code you posted.

as for the RichTextBox...you are NOT ever filling it with the amortization schedule.  That would require a loop, to go through all of the months of the repayment plan.

AW
Avatar of manch03

ASKER

I put the "continue" in so that when prompted, the user can continue to display the amortization schedule.

I know this would require a loop - that is my question, how do I do the loop?
Avatar of manch03

ASKER

If you look at my 11:07 a.m. question, it refers to a "nested loop" - this is what I do not know how to do.  Please help with this part.
Avatar of manch03

ASKER

I also took out the "fixed amounts in my text boxes"  I want to be able to type in a $ amount, interest rate % and term and have the form display the amortized schedule in the RichTextBox until it fills up, after it fills up, prompt the user to continue or exit and if continue then continue to display in the RichTextbox until the user does not want to continue any longer.  The display should show the principal balance, interest paid.
Avatar of manch03

ASKER

Anyone?  I really need an answer to this question as soon as possible.  
but you put the Continue Prompt in the Event Handler that is used EVERY TIME the text in the txtPrincipal control changes (and that means EVERY time a digit is entered - seems a bit clumsy to me).  I would add a Coimmand Button (Show Amortization Schedule or some such caption), and then show the next N months (where N is the number required to fill the Rich Text Box control (or make the nTextBox tall enough to show 6 or 12 months at a time, then N would be 6 or 12)

Then you would have a loop, like this (declare a Module level variable, outside the CommandButton_Click routine, iStart)

Dim iStart as Integer = 0
Dim N as Integer = 6

Private Sub ShowSched(sender as Object, e as System.EventArgs) Handles cmdShowSched.Click
Dim iMonth as Integer

for iMonth = iStart to iStart + N
   ' add the next month's shedule line to the TextBox
Next
   Start = Start + N + 1
End Sub


<Warning> The code I just gave you is AIR_CODE, as I do not have VB.NET installed on the PC where I am typing this.</WARNING>

AW
   
Avatar of manch03

ASKER

I got rid of that continue - I realized after I ran the debug that every time I tried to enter a number, it prompted me.  I will give this a try and let you know.
Avatar of manch03

ASKER

Remember I am a novice at this -

I added the code as follows:


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim iStart As Integer = 0
        Dim N As Integer = 6

Private Sub ShowSched(sender as Object, e as System.EventArgs) Handles cmdShowSched.Click
        Dim iMonth As Integer

        For iMonth = iStart To iStart + N
            ' add the next month's shedule line to the TextBox
        Next
        Start = Start + N + 1


I now get two errors on the debug:

Statement cannot appear within a method body. End of method assumed.
Handles clause requires a WithEvents variable.

Not too bad for AIR_CODE.
ASKER CERTIFIED SOLUTION
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of manch03

ASKER

I am still uncertain where to put the Dim statements.  I placed the Dim statements right after Public Class Form1 before Inherits System.Windows.Forms.Form and still got the same two errors.

Statement cannot appear within a method body. End of method assumed.
Handles clause requires a WithEvents variable.

Here is the top part of the form:

Public Class Form1
    Inherits System.Windows.Forms.Form
    'To calculate the monthly payment the dbl variable should be declared'

    'declare your variables here
    Dim dblPrincipal, dblRate, dblYears, dblAmount, dblMonths, interestPaid, loanBalance, Start, iMonth, MyPos As Double



#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

 
that's precisely where they go.  Since the Dim statement is NOT part of any one SUB, they are declared for the ENTIRE FORM, and are thus accessible from ANY sub, and they values remain set between calls to any Sub.  That is precisdly the behavior that you want in this case.

Are ALL of those variables (iMonth would appear to be an INTEGER value) supposed to be declared as DOUBLE?

The Handles clause should reference the name of the Command Button that you actually have on your form.

What line is identified for the error message:

Statement cannot appear within a method body. End of method assumed.

In the Errors list, if you Double click on that error message, what line does Visual Studio jump to:  That is the line that is in error.

AW
Avatar of manch03

ASKER

Ok - I now see the problem.  On my form I have a button that the user clicks to display the amortization schedule in the richTextbox.  I am not sure how to add a command button.  I do not see this as an option in Visual Studio - Here is the part I think needs to be fixed.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    'The For...Next statement should go here, but I do not know how to code this.
    'I want the principal loan balance to display in the RichTextBox and the amount of
    'interest paid.  The user will have the option to continue displaying the table or exit.
    'I will try this method.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'calculates the monthly payment on a loan, displays in the text box.
        'declare variables


Private Sub ShowSched(sender as Object, e as System.EventArgs) Handles  cmdShowSched.Click
        Dim iMonth As Integer

        For iMonth = iStart To iStart + N
            ' add the next month's schedule line to the TextBox
            'add the code here to accomplish this
        Next
        Start = Start + N + 1


The error is happening on the Line  Private Sub ShowSched(sender as Object,....

Avatar of manch03

ASKER

I took that line out that had the error and added the code below the Button1_Click and I did not get any errors, but I still cannot get the amortized schedule to show up in the richTextBox and display the continuing balance and interest paid.
Avatar of manch03

ASKER

I am going to ask a new question to see if there are any more vb.net experts out there.
are you actually wrting any cocde to add lines to the RichTextBox control? That was what my two comment lines were in place of.  You must actually write code to add a line for each mnonth that you want to display.  And as this would seem to be a class assignment, I am not going to write those ilines for you - that you will need to figure out for yourself.  Take a stab at it, and we will help you get it right - but we WILL NOT write the code for you - That is a violation of the membership agreement.

AW
Avatar of manch03

ASKER

I figured this one out  and have this all taken care of.