[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Student needs help with sample app in VB.net

Posted on 2004-11-07
9
Medium Priority
?
323 Views
Last Modified: 2012-05-05
I need a sample app in VB that

Using a graphical user interface that calculates and displays the mortgage payment amount from user input of the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage.  Allow the user to loop back and enter new data or quit.

0
Comment
Question by:gmahler5th
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 7

Expert Comment

by:J_Mak
ID: 12521182
Have a look at this:

http://www.codeproject.com/netcf/BNMortCalc.asp

It is written in Compact Framework and C# but it should have the basic gist on how to create one. Cheers.
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12521202
0
 
LVL 2

Expert Comment

by:AmanBrar
ID: 12522511
Hi,

plz post ur email-id and i'll mail something to help u.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 27

Expert Comment

by:planocz
ID: 12523348
Here is a sample app that I made for Amortization......

'FORM 1

Imports System.IO
Imports System
Imports System.Drawing.Printing
Imports Microsoft.VisualBasic
Public Class frmAmort
    Inherits System.Windows.Forms.Form
    Private WithEvents pdoc As New PrintDocument
    Private cCollection As New Collection
    Private Msg As String
    Private sLineTemp As String
    Private sFileName As String
    Private sLine As String = Space(70)
    Private sHeader As String = Space(90)
    Private sHeader1 As String = Space(90)
    Private printFont As Font
    Private streamToPrint As StreamReader
    Private storedPageSettings As PageSettings
    Private TotPmts 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
        InitializeListview()
    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 lblCost As System.Windows.Forms.Label
    Friend WithEvents txtCost As System.Windows.Forms.TextBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents txtPercentage As System.Windows.Forms.TextBox
    Friend WithEvents txtMonths As System.Windows.Forms.TextBox
    Friend WithEvents lvwOut As System.Windows.Forms.ListView
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents lblPercentage As System.Windows.Forms.Label
    Friend WithEvents lblMonths As System.Windows.Forms.Label
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents lblIns As System.Windows.Forms.Label
    Friend WithEvents txtIns As System.Windows.Forms.TextBox
    Friend WithEvents txtTAX As System.Windows.Forms.TextBox
    Friend WithEvents btnPrint As System.Windows.Forms.Button
    Friend WithEvents lblTax As System.Windows.Forms.Label
    Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmAmort))
        Me.btnOK = New System.Windows.Forms.Button
        Me.lblCost = New System.Windows.Forms.Label
        Me.lblPercentage = New System.Windows.Forms.Label
        Me.lblMonths = New System.Windows.Forms.Label
        Me.txtCost = New System.Windows.Forms.TextBox
        Me.txtPercentage = New System.Windows.Forms.TextBox
        Me.txtMonths = New System.Windows.Forms.TextBox
        Me.lvwOut = New System.Windows.Forms.ListView
        Me.btnClear = New System.Windows.Forms.Button
        Me.btnSave = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.lblIns = New System.Windows.Forms.Label
        Me.lblTax = New System.Windows.Forms.Label
        Me.txtIns = New System.Windows.Forms.TextBox
        Me.txtTAX = New System.Windows.Forms.TextBox
        Me.btnPrint = New System.Windows.Forms.Button
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.SuspendLayout()
        '
        'btnOK
        '
        Me.btnOK.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnOK.Location = New System.Drawing.Point(8, 376)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(60, 24)
        Me.btnOK.TabIndex = 3
        Me.btnOK.Text = "&Ok"
        Me.ToolTip1.SetToolTip(Me.btnOK, "Runs the figures that are posted")
        '
        'lblCost
        '
        Me.lblCost.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCost.Location = New System.Drawing.Point(28, 8)
        Me.lblCost.Name = "lblCost"
        Me.lblCost.Size = New System.Drawing.Size(200, 20)
        Me.lblCost.TabIndex = 4
        Me.lblCost.Text = "How much do you want to borrow? :"
        '
        'lblPercentage
        '
        Me.lblPercentage.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblPercentage.Location = New System.Drawing.Point(28, 36)
        Me.lblPercentage.Name = "lblPercentage"
        Me.lblPercentage.Size = New System.Drawing.Size(196, 28)
        Me.lblPercentage.TabIndex = 5
        Me.lblPercentage.Text = "What is the annual percentage rate of your loan? :"
        '
        'lblMonths
        '
        Me.lblMonths.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMonths.Location = New System.Drawing.Point(28, 72)
        Me.lblMonths.Name = "lblMonths"
        Me.lblMonths.Size = New System.Drawing.Size(192, 28)
        Me.lblMonths.TabIndex = 6
        Me.lblMonths.Text = "How many monthly payments do you have to make? :"
        '
        'txtCost
        '
        Me.txtCost.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtCost.Location = New System.Drawing.Point(232, 8)
        Me.txtCost.Name = "txtCost"
        Me.txtCost.Size = New System.Drawing.Size(84, 20)
        Me.txtCost.TabIndex = 0
        Me.txtCost.Text = "txtCost"
        '
        'txtPercentage
        '
        Me.txtPercentage.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtPercentage.Location = New System.Drawing.Point(232, 40)
        Me.txtPercentage.Name = "txtPercentage"
        Me.txtPercentage.Size = New System.Drawing.Size(84, 20)
        Me.txtPercentage.TabIndex = 1
        Me.txtPercentage.Text = "txtPercentage"
        '
        'txtMonths
        '
        Me.txtMonths.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtMonths.Location = New System.Drawing.Point(232, 76)
        Me.txtMonths.Name = "txtMonths"
        Me.txtMonths.Size = New System.Drawing.Size(84, 20)
        Me.txtMonths.TabIndex = 2
        Me.txtMonths.Text = "txtMonths"
        '
        'lvwOut
        '
        Me.lvwOut.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lvwOut.Location = New System.Drawing.Point(12, 164)
        Me.lvwOut.Name = "lvwOut"
        Me.lvwOut.Size = New System.Drawing.Size(316, 200)
        Me.lvwOut.TabIndex = 12
        '
        'btnClear
        '
        Me.btnClear.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnClear.Location = New System.Drawing.Point(136, 376)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(64, 24)
        Me.btnClear.TabIndex = 15
        Me.btnClear.Text = "&Clear"
        Me.ToolTip1.SetToolTip(Me.btnClear, "Clears view list")
        '
        'btnSave
        '
        Me.btnSave.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnSave.Location = New System.Drawing.Point(200, 376)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(64, 24)
        Me.btnSave.TabIndex = 17
        Me.btnSave.Text = "&Save"
        Me.ToolTip1.SetToolTip(Me.btnSave, "You must save before it can be printed")
        '
        'btnCancel
        '
        Me.btnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnCancel.Location = New System.Drawing.Point(68, 376)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(68, 24)
        Me.btnCancel.TabIndex = 18
        Me.btnCancel.Text = "C&ancel"
        Me.ToolTip1.SetToolTip(Me.btnCancel, "Closes program")
        '
        'lblIns
        '
        Me.lblIns.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblIns.Location = New System.Drawing.Point(28, 108)
        Me.lblIns.Name = "lblIns"
        Me.lblIns.Size = New System.Drawing.Size(188, 16)
        Me.lblIns.TabIndex = 19
        Me.lblIns.Text = "Insurance cost based on first year:"
        '
        'lblTax
        '
        Me.lblTax.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblTax.Location = New System.Drawing.Point(28, 136)
        Me.lblTax.Name = "lblTax"
        Me.lblTax.Size = New System.Drawing.Size(188, 16)
        Me.lblTax.TabIndex = 20
        Me.lblTax.Text = "Tax base on first year cost:"
        '
        'txtIns
        '
        Me.txtIns.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtIns.Location = New System.Drawing.Point(232, 104)
        Me.txtIns.Name = "txtIns"
        Me.txtIns.Size = New System.Drawing.Size(84, 20)
        Me.txtIns.TabIndex = 21
        Me.txtIns.Text = "txtIns"
        Me.ToolTip1.SetToolTip(Me.txtIns, "Based on a yearly amount for the total years applied(estimated)")
        '
        'txtTAX
        '
        Me.txtTAX.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTAX.Location = New System.Drawing.Point(232, 132)
        Me.txtTAX.Name = "txtTAX"
        Me.txtTAX.Size = New System.Drawing.Size(84, 20)
        Me.txtTAX.TabIndex = 22
        Me.txtTAX.Text = "txtTAX"
        Me.ToolTip1.SetToolTip(Me.txtTAX, "Based on a yearly amount for the total years applied(estimated)")
        '
        'btnPrint
        '
        Me.btnPrint.Enabled = False
        Me.btnPrint.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnPrint.Location = New System.Drawing.Point(264, 376)
        Me.btnPrint.Name = "btnPrint"
        Me.btnPrint.Size = New System.Drawing.Size(64, 24)
        Me.btnPrint.TabIndex = 23
        Me.btnPrint.Text = "&Print"
        '
        'frmAmort
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(340, 414)
        Me.Controls.Add(Me.btnPrint)
        Me.Controls.Add(Me.txtTAX)
        Me.Controls.Add(Me.txtIns)
        Me.Controls.Add(Me.txtMonths)
        Me.Controls.Add(Me.txtPercentage)
        Me.Controls.Add(Me.txtCost)
        Me.Controls.Add(Me.lblTax)
        Me.Controls.Add(Me.lblIns)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.lvwOut)
        Me.Controls.Add(Me.lblMonths)
        Me.Controls.Add(Me.lblPercentage)
        Me.Controls.Add(Me.lblCost)
        Me.Controls.Add(Me.btnOK)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmAmort"
        Me.Text = "Amortization Program"
        Me.ResumeLayout(False)

    End Sub

#End Region

    <STAThread()> Public Shared Sub Main()
        Application.Run(New frmAmort)
    End Sub
    Private Sub InitializeListview()
        Cursor.Current = Cursors.WaitCursor
        lvwOut.Columns.Add("Month", 50, HorizontalAlignment.Center)
        lvwOut.Columns.Add("Payment", 70, HorizontalAlignment.Right)
        lvwOut.Columns.Add("Principal", 80, HorizontalAlignment.Right)
        lvwOut.Columns.Add("Interest", 80, HorizontalAlignment.Right)
        lvwOut.View = View.Details
        Cursor.Current = Cursors.Default
        txtCost.Text = "200,000"
        txtPercentage.Text = "6.0"
        txtMonths.Text = "360"
        txtIns.Text = "1,500"
        txtTAX.Text = "2,500"
    End Sub
    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        TestPPMT()
    End Sub
    Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        printPreView()
    End Sub
    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
    Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        lvwOut.Clear()
        lvwOut.Columns.Add("Month", 50, HorizontalAlignment.Center)
        lvwOut.Columns.Add("Payment", 70, HorizontalAlignment.Right)
        lvwOut.Columns.Add("Principal", 80, HorizontalAlignment.Right)
        lvwOut.Columns.Add("Interest", 80, HorizontalAlignment.Right)
        txtCost.Focus()
        sLineTemp = ""
        sLine = Space(70)
    End Sub
    Sub TestPPMT()
        Dim PVal As Double
        Dim APR As Double
        Dim MakeChart As Double
        Dim FVal As Double
        Dim Ins As Double
        Dim Tax As Double
        Dim Payment As Double
        Dim Period As Double
        Dim P, I As Double
        Dim PayType As DueDate
        Dim Fmt As String
        Dim Response As MsgBoxResult
        Dim iCounter As Short = 0
        Dim iCount As Short
        '******** Temp Vars **********
        Dim sCount As String
        Dim sPayment As String
        Dim sP As String
        Dim sI As String

        Cursor.Current = Cursors.WaitCursor

        Fmt = "###,###,##0.00"   ' Define money format.
        If txtIns.Text = "" Then
            Ins = 0
        Else
            Ins = CDbl(Trim(txtIns.Text)) / 12
        End If
        If txtIns.Text = "" Then
            Tax = 0
        Else
            Tax = CDbl(Trim(txtTAX.Text)) / 12
        End If


        FVal = 0   ' Usually 0 for a loan.
        PVal = CDbl(Trim(txtCost.Text))
        APR = CDbl(Trim(txtPercentage.Text))
        If APR > 1 Then APR = APR / 100 ' Ensure proper form.
        TotPmts = CDbl(Trim(txtMonths.Text))
        Response = MsgBox("Do you make payments at the end of month?", MsgBoxStyle.YesNo)
        If Response = MsgBoxResult.No Then
            PayType = DueDate.BegOfPeriod
        Else
            PayType = DueDate.EndOfPeriod
        End If
        Payment = Math.Abs(-Pmt(APR / 12, TotPmts, PVal, FVal, PayType)) + (Ins + Tax)
        Period = 1
        For iCount = 1 To TotPmts
            ' If Period > 12 Then Exit For ' Show only first 12.
            P = PPmt(APR / 12, Period, TotPmts, -PVal, FVal, PayType)
            P = (Int((P + 0.005) * 100) / 100)  ' Round principal.
            I = Payment - P
            I = (Int((I + 0.005) * 100) / 100)  ' Round interest.

            sCount = Format(iCount, "  00")
            sCount = Space(5 - Len(sCount)) & sCount
            Payment = Format(Payment, Fmt)
            sPayment = Payment
            sPayment = Space(15 - Len(sPayment)) & sPayment
            sP = Format(P, Fmt)
            sP = Space(15 - Len(sP)) & sP
            sI = Format(I, Fmt)
            sI = Space(15 - Len(sI)) & sI

            Mid(sLine, 5, 5) = sCount
            Mid(sLine, 15, 30) = sPayment
            Mid(sLine, 35, 50) = sP
            Mid(sLine, 55, 70) = sI
            sLineTemp &= sLine & vbNewLine
            sCount = ""
            sPayment = ""
            sP = ""
            sI = ""
            lvwOut.Items.Add(UCase(iCount))
            lvwOut.Items(iCounter).SubItems.Add(Payment) 'Format(Payment, Fmt))
            lvwOut.Items(iCounter).SubItems.Add(Format(P, Fmt))
            lvwOut.Items(iCounter).SubItems.Add(Format(I, Fmt))
            'Add each line to a collection for recalling later
            '  cCollection.Add(Msg, iCounter)
            iCounter += 1
            Period += 1
        Next
        Mid(sHeader, 5, 5) = "Month"
        Mid(sHeader, 20, 35) = "Payment"
        Mid(sHeader, 40, 55) = "Principal"
        Mid(sHeader, 60, 80) = "Interest       " & Now
        sHeader &= vbNewLine
        sHeader1 = ("________________________________________________________________________")
        sHeader1 &= vbNewLine
        Cursor.Current = Cursors.Default
    End Sub
    Private Sub txtCost_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCost.KeyPress, txtMonths.KeyPress, txtPercentage.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)
        Select Case KeyAscii
            Case System.Windows.Forms.Keys.Back
            Case 13
                e.Handled = True
                SendKeys.Send("{TAB}")
            Case Is >= 32
                KeyAscii = 0
            Case 48 To 57, 8
                Exit Sub
            Case Else
                e.Handled = True
        End Select
    End Sub
    Public Sub printPreView()
        If sFileName = "" Then
            OpenFile()
        End If
        Try
            Dim sWE As String
            sWE = sHeader & Msg
            Dim streamToPrint As StreamReader = New StreamReader(sFileName)
            Try
                'Assumes the default printer
                Dim pd As TextFilePrintDocument = New TextFilePrintDocument(streamToPrint)
                If Not (storedPageSettings Is Nothing) Then
                    pd.DefaultPageSettings = storedPageSettings
                End If
                Dim dlg As New PrintPreviewDialog
                dlg.Document = pd
                dlg.ShowDialog()
            Finally
                streamToPrint.Close()
            End Try
        Catch exp As Exception
            MessageBox.Show("An error occurred - " + exp.Message)
        End Try
    End Sub
    Private Sub OpenFile()
        ' Create the OpenFileDialog object
        Dim myOpenFileDialog As New OpenFileDialog
        With myOpenFileDialog
            .CheckFileExists = True
            .DefaultExt = "txt"
            .Filter = "Text files (*.txt)|*.txt"
            .InitialDirectory = "c:\Amortization\Reports\"
            .Multiselect = False
        End With
        ' Use the OpenFileDialog and put the path and name of the selected file in a var.
        If myOpenFileDialog.ShowDialog = DialogResult.OK Then
            sFileName = myOpenFileDialog.FileName
        End If
    End Sub
    Private Sub SaveNewFileName(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        ' Use the SaveFileDialog and put the path and name of the
        '   desired file in a var.
        ' Create the OpenFileDialog object
        Dim mySaveFileDialog As New SaveFileDialog
        With mySaveFileDialog
            .DefaultExt = "txt"
            .Filter = "Text files (*.txt)|*.txt"
            .InitialDirectory = "c:\Amortization\Reports\"
            sFileName = .FileName
        End With
        If mySaveFileDialog.ShowDialog = DialogResult.OK Then
            With mySaveFileDialog
                sFileName = .FileName
            End With
            If sFileName <> "" Then
                StreamWriterCREATEFile(sFileName, (sHeader & sHeader1 & sLineTemp))
                btnPrint.Enabled = True
            End If
        End If
    End Sub
    Public Sub StreamWriterCREATEFile(ByVal sFileName As String, ByVal sData As String)
        Dim myStreamWriter As StreamWriter
        Dim Temp As String
        Dim i As Short

        Try
            myStreamWriter = File.CreateText(sFileName)
            For i = 0 To TotPmts + 1
                Temp = Microsoft.VisualBasic.Mid(sData, 2, InStr(sData, vbNewLine) - 2)
                sData = Mid(sData, InStr(sData, vbNewLine) + 1)
                myStreamWriter.WriteLine(Temp)
                Select Case i
                    Case 56, 111, 166, 221, 276, 331, 386, 441, 496, 551, 606, 661
                        myStreamWriter.WriteLine(Microsoft.VisualBasic.Mid(sHeader, 2, InStr(sHeader, vbNewLine) - 2))
                        myStreamWriter.WriteLine(Microsoft.VisualBasic.Mid(sHeader1, 2, InStr(sHeader1, vbNewLine) - 2))
                End Select
            Next
            myStreamWriter.Flush()
        Catch exc As Exception
            MsgBox("File could not be created or written to." + vbCrLf + _
                "Please verify that the filename is correct, " + _
                "and that you have write permissions for the desired " + _
                "directory." + vbCrLf + vbCrLf + "Exception: " + exc.Message)
        Finally
            ' Close the object if it has been created.
            If Not myStreamWriter Is Nothing Then
                myStreamWriter.Close()
            End If
        End Try
    End Sub
End Class


'PRINT CLASS

Imports System
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.IO
Public Class TextFilePrintDocument
    Inherits PrintDocument

    Private printFont As Font
    Private streamToPrint As StreamReader

    Public Sub New(ByVal streamToPrint As StreamReader)
        MyBase.New()
        Me.streamToPrint = streamToPrint
    End Sub

    'Override OnBeginPrint to set up the font we are going to use
    Protected Overrides Sub OnBeginPrint(ByVal ev As PrintEventArgs)
        MyBase.OnBeginPrint(ev)
        printFont = New Font("Arial", 10)
    End Sub

    'Override the OnPrintPage to provide the printing logic for the document
    Protected Overrides Sub OnPrintPage(ByVal ev As PrintPageEventArgs)

        MyBase.OnPrintPage(ev)

        Dim lpp As Single = 0
        Dim yPos As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = ev.MarginBounds.Left
        Dim topMargin As Single = ev.MarginBounds.Top
        Dim line As String

        'Work out the number of lines per page
        'Use the MarginBounds on the event to do this
        lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

        'Now iterate over the file printing out each line
        'NOTE WELL: This assumes that a single line is not wider than the page width
        'Check count first so that we don't read line that we won't print
        line = streamToPrint.ReadLine()
        While (count < lpp And line <> Nothing)

            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics))

            ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
                                   yPos, New StringFormat)

            count = count + 1

            If (count < lpp) Then
                line = streamToPrint.ReadLine()
            End If

        End While

        'If we have more lines then print another page
        If (line <> Nothing) Then
            ev.HasMorePages = True
        Else
            ev.HasMorePages = False
        End If

    End Sub

End Class


0
 

Author Comment

by:gmahler5th
ID: 12529883
Hey planocz, that code seems interesting, but I can't figure out how to actually computer the monthly payment.  Your code seems way more complex then what I'm trying to do.  I need to calculate my monthly payment give the loan principal, the percentage, and the terms.  Here are my variables.

      dblPrincipal = CDbl(txtPrincipal.Text)
        dblRate = CDbl(txtRate.Text)
        dblYears = CDbl(txtYears.Text)

0
 
LVL 7

Accepted Solution

by:
J_Mak earned 1500 total points
ID: 12530393
USe the in built .NET functions NPmt and IPmt, I think that is what they are referred to.

Have a look at this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctipmt.asp

There are more links at the bottom of the page.
0
 

Author Comment

by:gmahler5th
ID: 12541282
Can't someone just type in the formua as I would use it in a VB app?  I didn't post this question so I could go on a scavanger hunt.  

I'm sorry, I appreciate your help, and I'm not blaming you personally.  I've posted 2 questions already for basically the same issue.  I guess it's time to post a 3rd.
0
 
LVL 27

Expert Comment

by:planocz
ID: 12543412
All the code that is posted is a simplest way to program what you want with the tools that Micro$oft provide in .NET.
0
 
LVL 2

Expert Comment

by:AmanBrar
ID: 12551663
Ok, well i dont exactly get what u mean by mortgage here, but u can try the following:

1. If u want to calculate the Total Amount to be paid after the given number of years, do this:
    dblAmount = dblPrincipal + (dblPrincipal * dblRate * dblYears) / 100.0

2. If u just want the Interest Amount after the given number of years, do this:
    dblInterest = (dblPrincipal * dblRate * dblYears) / 100.0

hope this helps.
   
 
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question