Public Class Form1
Private Sub btnCalcInterest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcInterest.Click
Dim Interest, AmountInvested As Decimal
Dim RateOfInterest As Single
Dim Years As Short
AmountInvested = txtamountinvested.text
RateOfInterest = txtInterestRate.Text
Years = txtYears.Text
Interest = CalculateInterest(AmountInvested, RateOfInterest, Years)
lblinterestrate.Text = Format(Interest, "Currency")
End Sub
Function CalculateInterest(ByVal Principal As Decimal, ByVal InterestRate As Single, ByVal numberYears As Short) As Decimal
Dim Interest As Decimal
Dim Year As Short
Interest = 0
For Year = 1 To numberYears
Interest = Interest + ((Principal + Interest) * InterestRate / 100)
Next Year
Return Interest
CalculateInterest = Interest
End Function
End Class
No comments:
Post a Comment