In visual basic i have a basic interest rate problem I have

In visual basic i have a basic interest rate problem. I have it set up so the user can enter the principal, the interest rate, how many years that it will run and it will give you a total balance at the end. All of this works but I want to have it show each year end balance in a list box. I am using a list box because the years is a variable and not a constant since it is entered by the user. How do I get each year end balance to show up in a list box? Or is there a better option than a list box in this case?

Public Class frmNestEgg
Private Sub btnPrincipal_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
\' Declare and Initialize the variables

Dim Principal As Double = txtPrincipal.Text
Dim InterestRate As Double = txtInterestRate.Text / 100
Dim Years As Integer
Dim FinalTotal As Double
Dim YrEndAmt As Double

Years = Integer.Parse(txtYears.Text)

\'Calculate the interest from the principal payment over the years input to create a total value.

For Years = 1 To Years
FinalTotal = Principal * (1 + InterestRate) ^ Years
lblFinalTotal.Text = FinalTotal.ToString(\"F1\")

Next

lstYrEndAmt.Items.Add(YrEndAmt)


End Sub
End Class

Solution

Public Class Form1
Private Sub btnCalculate_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnCalculate.Click
Dim principal, years As Integer
Dim rate, interest, amount As Single

principal = txtPrincipal.Text
years = txtYears.Text
rate = txtRate.Text

If rbSimpleInterest.Checked = True Then
interest = (principal * years * rate) / 100
Else
amount = principal * Math.Pow((1 + rate / 100), years)
interest = amount - principal
End If
txtInterest.Text = interest
End Sub

Private Sub btnClear_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnClear.Click
txtPrincipal.Text = \" \"
txtYears.Text = \" \"
txtRate.Text = \" \"
txtInterest.Text = \" \"
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
End Class

In visual basic i have a basic interest rate problem. I have it set up so the user can enter the principal, the interest rate, how many years that it will run a
In visual basic i have a basic interest rate problem. I have it set up so the user can enter the principal, the interest rate, how many years that it will run a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site