Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

Need VB.net tutor

I need a VB.net tutor to help me with a program for a class project.  I am at stuck at step 9 in the instructions.  If possible, Program Sharing in MSN Messenger would be most efficient, but if you have a way to talk me through this in the forum that will be okay also.  I have a couple of open questions about this project in this EE category already, and I will award points from those open question to whomever can help me get this app running as specified below.

Here is what my app currently looks like:  http://www.stevetout.com/current.jpg


1.) Write a VB.NET program using a graphical user interface
2.) Calculates and display 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.  
3.) Allow the user to loop back and enter new data or quit.  
4.) Modify the mortgage program to allow the user to input the amount of a mortgage and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.5 %, and 30 year at 5.75%.  
5.) Use an array for the different loans.  
6.) Display the mortgage payment amount.  
7.) Then, list the loan balance and interest paid for each payment over the term of the loan.  
8.) Allow the user to loop back and enter a new amount and make a new selection, or quit.  
9.) Modify the mortgage program to allow the user to select which way they want to calculate a mortgage: by input of the
amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage payment (as was done in the Step 2) or by input of the amount of a mortgage and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year
at 5.5 %, and 30 year at 5.75% (as was done in Step 3).  
10.) In either case, display the mortgage payment amount.  
11.) Then, list the loan balance and interest paid for each payment over the term of the loan.  
12.) Allow the user to loop back and enter a new amount and make a new selection, or quit.  
13.) Load the interest rates for the 7 year, 15 year, and 30 year loans from a file.
0
gmahler5th
Asked:
gmahler5th
  • 5
  • 4
1 Solution
 
Bob LearnedCommented:
Look at a combination RadioButtons and TextBoxes.

Bob
0
 
gmahler5thAuthor Commented:
I understand what you are saying Bob, but I don't know how to tie all the logic together once I get the radio buttons on the page.  
0
 
Bob LearnedCommented:
Have you added the RadioButtons, such as:

Calculation method:
( ) By amount, term, and interest rate
( ) By amount and selected loan

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
gmahler5thAuthor Commented:
No i was thinking i would use tabs to allow the user to select which method to calculate the loan.  I guess you are suggesting radio buttons would be easier?
0
 
Bob LearnedCommented:
I am not a big fan of tabs--they hide functionality.  Although, tabs start to make sense when there are a lot of controls, but if that is true, then I try to evaluate why there are so many and redistribute to different forms.  It's all about personal preference, though.  While learning something new, you should experiment with it both ways and see which way you like best.  Just because I feel one way doesn't mean that you have to.

Bob
0
 
gmahler5thAuthor Commented:
Actually I'm stuck at step 4.  

I can't quite visualize the UI if I keep it all on the same form using radio buttons.

Can you provide any suggestions?
0
 
gmahler5thAuthor Commented:
Okay I finally have a UI that meets the requirements. (Step 4 and Step 9)

http://www.stevetout.com/current.jpg

Now I need to build in the logic to display the payment for steps 5/6/10.  My form code can be seen at the following URL

http://www.stevetout.com/code.txt

Can someone please help me with the code for steps 5, 6, 10, 11 and 13?
0
 
Bob LearnedCommented:
Second lesson:

Learn early that code in the form control's event sink is generally poor practice.  Put that code in a class (Study the Model-View-Controller pattern).

Third lesson:

Create a method that will calculate the mortgage based on parameters defined from the form so that you set up.

Bob
0
 
gmahler5thAuthor Commented:
I am stuck on steps 9 and 13 now.  Alllowing the user to choose which calculation method they want to use... and using an array to calculate from predefined rates... and loading the predefined rates from a file...

Someone please help?
0
 
platinumbayCommented:
   'declare your variables here
    Dim iRates As New Rates

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim Fmt As String
        Dim TotPmts As Integer
        Dim PVal, APR, FVal, Payment, dblMonth, dblRateMonth As Double

        'assign the values from textboxes to the variables
        If CT1.Checked = True Then ' Choose own rates
            APR = Convert.ToDouble(txtRate.Text)
            TotPmts = Convert.ToInt32(txtYears.Text)
        ElseIf CT2.Checked = True Then ' Predefined
            If PDR1.Checked = True Then
                APR = iRates.Item(0).Num2
                TotPmts = Convert.ToInt32(iRates.Item(0).Num1)
            ElseIf PDR2.Checked = True Then
                APR = iRates.Item(1).Num2
                TotPmts = Convert.ToInt32(iRates.Item(1).Num1)
            ElseIf PDR3.Checked = True Then
                APR = iRates.Item(2).Num2
                TotPmts = Convert.ToInt32(iRates.Item(2).Num1)
            End If
        End If

        PVal = Convert.ToDouble(txtPrincipal.Text)
        TotPmts = TotPmts * 12

        If APR > 1 Then APR = APR / 100 ' Ensure proper form.
        dblMonth = TotPmts * 12
        dblRateMonth = APR / 12

        'calculate the final amount as principal + interest
        Fmt = "###,###,##0.00"   ' Define money format.
        FVal = 0   ' Usually 0 for a loan.
        Payment = PVal / ((1 - (1 + dblRateMonth) ^ -dblMonth) / dblRateMonth)

        'put the calculated amount in Payment Amount textbox
        txtAmount.Text = FormatNumber(Payment, 2, TriState.True, TriState.True, TriState.False)

        Application.DoEvents()

        Dim objDT As New DataTable
        objDT.Columns.Add("Month", GetType(Integer))
        objDT.Columns.Add("Balance", GetType(Double))
        objDT.Columns.Add("Installment", GetType(Double))
        objDT.Columns.Add("Interest Paid", GetType(Double))
        objDT.Columns.Add("Principal Paid", GetType(Double))

        MyBase.Height = 536
        Application.DoEvents()

        Dim balanceLeft As Double = PVal '- downPayment
        Dim interestPaid As Double
        Dim LoanDuration As Integer = TotPmts '* 12

        For i As Integer = 1 To LoanDuration
            Dim strRow(4) As Object

            interestPaid = balanceLeft * APR / 100 / 12
            balanceLeft = balanceLeft + interestPaid - Payment

            strRow(0) = i
            strRow(1) = Convert.ToDouble(FormatNumber(balanceLeft, 2))
            strRow(2) = Convert.ToDouble(FormatNumber(Payment, 2))
            strRow(3) = Convert.ToDouble(FormatNumber(interestPaid, 2))
            strRow(4) = Convert.ToDouble(FormatNumber(interestPaid - Payment, 2))

            'al.Add(New repayment(i, balanceLeft, monthlyInstallment, interestPaid, interestPaid - monthlyInstallment))

            objDT.Rows.Add(strRow)
            Application.DoEvents()
        Next

        Me.dgAmortization.DataSource = objDT
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oFile As System.IO.File
        Dim oRead As System.IO.StreamReader
        Dim strLine As String
        Dim isEnd As Boolean = False
        Dim strRegExp As String = "PDR(?:\[|\()(?<Seq>\d{1})(?:\]|\))\s\((?<Num1>\d+)(?:,|\.)(?<Num2>[0-9\.]+)\)"

        oRead = oFile.OpenText("C:\rates.txt")
        Do While isEnd = False
            If oRead.Peek = -1 Then
                isEnd = True
                Exit Do
            End If
            strLine = oRead.ReadLine

            Dim iMatch As Match = Regex.Match(strLine, strRegExp)

            'MsgBox(iMatch.Groups("").Value.ToString & ":" & iMatch.Groups(1).Value.ToString & ":" & iMatch.Groups(2).Value.ToString)
            Dim seq As Integer = Convert.ToInt32(iMatch.Groups("Seq").Value.ToString)
            Dim num1 As Double = Convert.ToInt32(iMatch.Groups("Num1").Value.ToString)
            Dim num2 As Double = Convert.ToDouble(iMatch.Groups("Num2").Value)

            Dim iRate As New Rate(seq, num1, num2)
            iRates.add(iRate)
            Select Case seq
                Case 0
                    Me.PDR1.Text = num1 & " Years " & num2 & "%"
                Case 1
                    Me.PDR2.Text = num1 & " Years " & num2 & "%"
                Case 2
                    Me.PDR3.Text = num1 & " Years " & num2 & "%"
            End Select
        Loop
    End Sub

    Public Class Rates
        Inherits CollectionBase

        Public Sub add(ByVal r As Rate)
            MyBase.InnerList.Add(r)
        End Sub

        Public Overloads Function Item(ByVal Index As Integer) As Rate
            ' To retrieve an item from the InnerList, pass the index of that item to the .Item property.
            Return CType(Me.InnerList.Item(Index), Rate)
        End Function

        Public Overloads Sub Remove(ByVal Index As Integer)
            ' This Remove expects an index.
            Dim iRate As Rate
            iRate = CType(Me.InnerList.Item(Index), Rate)
            If Not iRate Is Nothing Then
                Me.InnerList.Remove(iRate)
            End If
        End Sub
    End Class

    Public Class Rate
        Public Seq As Integer
        Public Num1 As Double
        Public Num2 As Double

        Public Sub New(ByVal oseq As Integer, ByVal onum1 As Double, ByVal onum2 As Double)
            Me.Seq = oseq
            Me.Num1 = onum1
            Me.Num2 = onum2
        End Sub
    End Class
End Class
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now