Description

We are learning to create computer applications using the Visual Basic language. This is one of our intrpductory lessons to desktop applications. In exercise, we will use Microsoft Visual Studio to create a project. We will create a Windows Forms application, also called WinForms app.

One of the strengths of the Visual Basic language is that it has its own library that provides many functions you can directly use in your applications. One of the categories of functions deals with investments calculations. This means that the Visual Basic language provides functions that allow you to calculate the present value of an investments, the future value, the interest rate, etc. In this exercise, we will calculate the future value and the interest earned on an investment.

Practical LearningPractical Learning: Creating the Application

  1. Start Microsoft Visual Studio
  2. On the Visual Studio 2026 dialog box, click Create a New Project
  3. In the Create a New Project dialog box, in the Languages combo box, select Visual Basic
  4. In the list project templates, click Windows Forms App
  5. Click Next
  6. In the Configure Your New Project dialog box, set the Project Name to AnnuityEvaluation
  7. Click Next
  8. In the Additional Information dialog box, in the Framework combo box, select the highest version (.NET 10.0 (Long Term Support)).
    Click Create
  9. In the Solution Explorer, right-click Form1.cs and click Rename
  10. Type Exercise (to get Exercise.cs) and press Enter twice
  11. Click the body of the form to select it
  12. In the Properties window, change the following characteristics:
    Text:          Annuity Evaluation
    StartPosition: CenterScreen
    MaximizeBox:   False
  13. Design the form as followed:

    Compound Interest - Form Design

    Control Name Text Additional Properties
    GroupBox GroupBox   Annuity Preparation  
    Label Label   Present Value:  
    TextBox TextBox TxtPresentValue TextAlign: Right
    Label Label   Interest Rate:  
    TextBox TextBox TxtInterestRate TextAlign: Right
    Label Label   %  
    Label Label   Number of Payments:  
    TextBox TextBox TxtNumberOfPayments TextAlign: Text
    Label Label   Months  
    Label Label   Periodic Payment:  
    TextBox TextBox TxtPeriodicPayment TextAlign: Right
    Label Label   Payment Made At:  
    ComboBox Combo Box CbxDueDates Items:
    End of Period
    Beginning of Period
    Button Button btnEvaluate Evaluate  
    GroupBox GroupBox   Annuity Results  
    Label Label   Future Value:  
    TextBox TextBox TxtFutureValue TextAlign: Right
    Button Button btnClose Close  
  14. On the form, double-click the Calculate button and implement its Click() event as follows:
    Private Sub BtnEvaluate_Click(sender As Object, e As EventArgs) Handles BtnEvaluate.Click
        Dim DateDue As DueDate
        Dim PresentValue As Double
        Dim TotalPayments As Integer
        Dim InterestRate As Double
        Dim PeriodicPayment As Double
    
        PresentValue = CDbl(TxtPresentValue.Text)
        InterestRate = CDbl(TxtInterestRate.Text) / 100
        TotalPayments = CInt(TxtNumberOfPayments.Text)
        PeriodicPayment = CDbl(TxtPeriodicPayment.Text)
    
    
        DateDue = IIf(CbxDueDates.SelectedIndex = 0, DueDate.EndOfPeriod, DueDate.BegOfPeriod)
    
        Dim FutureValue As Double = FV(InterestRate / 12, TotalPayments, -PeriodicPayment, 0, DateDue)
    
        TxtFutureValue.Text = FormatNumber(FutureValue)
    End Sub
  15. Return to the form and double-click the Close button
  16. Implement its OnClick() event as follows:
    Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
        Close()
    End Sub
  17. To test the application, press Ctrl + F5

    Compound Interest - Results

  18. In the top text boxes, specify the values as follows:
    Present Value:      100
    Interest Rate:      2.725
    Number of Payments: 60
    Periodic Payment:   150
    Payment Made At:    Beginning of Period
  19. Click the Evaluate button:

    Compound Interest - Results

  20. Close the form and return to your programming environment
  21. Close your programming environment

Application


Home Copyright © 2010-2026, FunctionX Friday 27 December 2024, 13:02 Home