Solved

Help with code for interest calculation formula visual basic 2008

Posted on 2011-03-22
3
729 Views
Last Modified: 2013-11-27
Im having problems with getting the correct formula for this assignment. I did what the book says and its not working. I have to enter a principal and then in the multiline text box I have to have one column with the rate(%) which are 5,6,7,8,9 and 10 and then the other column has to be the amount after 10 years. It says the interest calculation formula is a=p(1+r)^n. This is what I got so far and nothing is appearing in my multiline text box.
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
        ' Declare Variables
        Dim Principal As Decimal
        Dim Rate As Double
        Dim Amount As Decimal
        Dim Output As String

        ' Retrieve User Input
        Principal = Val(principalTextBox.Text)
        Output = ResultTextBox.Text

        ' Set Output Header
        Output = "Rate(%)" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

        ' Calculate Amount
        For years As Integer = 5 To 10
            Amount = _
            Principal * ((1 + Rate) ^ 10)
            Output = ("5" & ControlChars.Tab & ControlChars.Tab & _
                       String.Format("{0:C}", Amount) & ControlChars.CrLf)
        Next
       

    End Sub

Any help please im getting frustrated.
0
Comment
Question by:goldfingerpunk
  • 2
3 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35195777
Try this:

Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
        ' Declare Variables
        Dim Principal As Decimal
        Dim Rate As Double
        Dim Amount As Decimal
        Dim Output As String

        ' Retrieve User Input
        Principal = Val(principalTextBox.Text)
        Output = ResultTextBox.Text & ControlChars.CrLf

        ' Set Output Header
        Output = Output & "Rate(%)" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

        ' Calculate Amount
        For years As Integer = 5 To 10
            Amount = _
            Principal * ((1 + Rate) ^ 10)
            Output = Output & ("5" & ControlChars.Tab & ControlChars.Tab & _
                       String.Format("{0:C}", Amount) & ControlChars.CrLf)
        Next
       
        ResultTextBox.Text = Output

    End Sub

Open in new window

0
 

Author Comment

by:goldfingerpunk
ID: 35196041
It calculated but now the problem is it has one column of all 5's and the other column is the same number too
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35198747
That's what you instructed it to print on:

            Output = Output & ("5" & ControlChars.Tab & ControlChars.Tab & _
                       String.Format("{0:C}", Amount) & ControlChars.CrLf)

Try this:

Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
        ' Declare Variables
        Dim Principal As Decimal
        Dim Rate As Double
        Dim Amount As Decimal
        Dim Output As String

        ' Retrieve User Input
        Principal = Val(principalTextBox.Text)
        Output = ResultTextBox.Text & ControlChars.CrLf

        ' Set Output Header
        Output = Output & "Rate(%)" & ControlChars.Tab & ControlChars.Tab & "Amount after 10 years" & ControlChars.CrLf

        ' Calculate Amount
        For years As Integer = 5 To 10
            Rate = years / 100
            Amount = _
            Principal * ((1 + Rate) ^ 10)
            Output = Output & (years.ToString() & ControlChars.Tab & ControlChars.Tab & _
                       String.Format("{0:C}", Amount) & ControlChars.CrLf)
        Next
       
        ResultTextBox.Text = Output

    End Sub

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now