Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Help with code for interest calculation formula visual basic 2008

Posted on 2011-03-22
Medium Priority
743 Views
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

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
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
• 2

LVL 23

Expert Comment

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

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
0

Author Comment

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

wdosanjos earned 2000 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

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
0

## Featured Post

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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ā¦
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
###### Suggested Courses
Course of the Month8 days, 3 hours left to enroll