Solved

Help with code for interest calculation formula visual basic 2008

Posted on 2011-03-22
3
732 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

816 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

10 Experts available now in Live!

Get 1:1 Help Now