Solved

# Help with code for interest calculation formula visual basic 2008

Posted on 2011-03-22

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.