Solved

Help with code for interest calculation formula visual basic 2008

Posted on 2011-03-22
3
738 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

695 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