Future Application Through Event Handler in VB.NET

In this article, I have discuss about the Future Value application through Event Handlers.
  • 3129

In this article, I have discuss about the Future Value application through Event Handlers. In this i have used a loop to calculate the Future Value. In this i have taken two Event Handlers one for the Calculate button and one for the Exit button but here main processing occur in Calculate button. Controls which i have taken are four LabelBox, four TextBox and two Buttons. This application is used to calculate Future Value, the user enter the monthly investment amount, the yearly interest rate and the number of years, all this will we be done in the first three boxes. When the user clicks on the calculate button, it will display the value in the last Textbox. This application uses a For loop to calculate the future value of a monthly investment amount. Each time monthly investment amount will be added through For loop to the future value, which starts at zero. Since it will not provide any data validation, the user will be able to enter invalid data, which will occur exception.
In the below code the first three statement is used to declare and initialize the variables that is used to store the values that is enter by the user. CDec and CInt functions are used to convert the string values that are entered in the Text property to the appropriate numeric Data Types. The next two statement is used to convert the Yearly values into Monthly values. In the last we have used For loop to calculate Future value for each month of the investment.

Steps for the coding are:

Step1: Open the Visual Studio 2010, click on the new project.


Step2: Now select the VB category and open a Windows Form application, a page with Form will open.




Step3: Now start adding controls on the Form from the Toolbar i.e 4 LabelBox, 4 TextBox, 2 Buttons.

Step4: Double click on the buttons , it will generate a default code in which you have to do the rest of the coding.

Here is the code:

Public Class Form1


    Private Sub btnCalculate_Click(ByVal sender As System.ObjectByVal e As System.EventArgs)Handles btnCalculate.Click

        Dim monthlyInvestment As Decimal = CDec(txtMonthlyInvestment.Text)

        Dim YearlyInterestRate As Decimal = CDec(txtInterestRate.Text)

        Dim Years As Integer = CInt(txtYears.Text)

        Dim monthlyInterestRate As Decimal = YearlyInterestRate / 12 / 80

        Dim months As Integer = Years * 12

        Dim futureValue As Decimal

        For i As Integer = 1 To months

            futureValue = (futureValue + monthlyInvestment) * (1 + monthlyInterestRate)


        txtFutureValue.Text = FormatCurrency(futureValue)


    End Sub

    Private Sub btnExit_Click(ByVal sender As System.ObjectByVal e As System.EventArgs)Handles btnExit.Click


    End Sub

End Class


Step5: Press F5 the output will appear like this.


Step6: Now enter the value and click on the calculate button, it will show the Future Value.



More Articles

© 2020 DotNetHeaven. All rights reserved.