Introduction

In this introductory lesson to the Visual Basic Language, we will create a small console application and perform some simple calculations.

Practical LearningPractical Learning: Creating the Application

  1. Start Microsoft Visual Studio
  2. In the Visual Studio 2022 dialog box, click Create a New Project
  3. In the Create a New Project dialog box, in the Languages combo box, select Visual Basi.
    In the list of projects templates, select Console App (it should be selected already)
  4. Click Next
  5. In the Configure Your New Project dialog box, change the Project Name to PayrollEvaluation and set the Location of your choice
  6. Click Next
  7. In the Additional Information dialog box, in the Framework combo box, select the highest version (.NET 9.0 (Standard Term Support).
    Click Create
  8. Change the document as follows:
    Module Program
        Sub Main(args As String())
            Console.WriteLine("Payroll Evaluation")
            Console.WriteLine("===================================================")
            Console.WriteLine("Enter the following pieces of information")
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine("Employee Information")
            Console.WriteLine("---------------------------------------------------")
            Console.Write("First Name:        ")
            Dim FirstName = Console.ReadLine()
            Console.Write("Last Name:         ")
            Dim LastName = Console.ReadLine()
            Console.Write("Hourly Salary:     ")
            Dim HourlySalary = CDbl(Console.ReadLine())
            Console.WriteLine("===================================================")
            Console.WriteLine("Time worked - First Week")
            Console.WriteLine("---------------------------------------------------")
    
            Console.Write("Monday:            ")
            Dim Wk1Monday = CDbl(Console.ReadLine())
    
            Console.Write("Tuesday:           ")
            Dim Wk1Tuesday = CDbl(Console.ReadLine())
    
            Console.Write("Wednesday:         ")
            Dim Wk1Wednesday = CDbl(Console.ReadLine())
    
            Console.Write("Thursday:          ")
            Dim Wk1Thursday = CDbl(Console.ReadLine())
    
            Console.Write("Friday:            ")
            Dim Wk1Friday = CDbl(Console.ReadLine())
            Console.WriteLine("===================================================")
            Console.WriteLine("Time worked - Second Week")
            Console.WriteLine("---------------------------------------------------")
    
            Console.Write("Monday:            ")
            Dim Wk2Monday = CDbl(Console.ReadLine())
    
            Console.Write("Tuesday:           ")
            Dim Wk2Tuesday = CDbl(Console.ReadLine())
    
            Console.Write("Wednesday:         ")
            Dim Wk2Wednesday = CDbl(Console.ReadLine())
    
            Console.Write("Thursday:          ")
            Dim Wk2Thursday = CDbl(Console.ReadLine())
    
            Console.Write("Friday:            ")
            Dim Wk2Friday = CDbl(Console.ReadLine())
    
            Dim Wk1TimeWorked = Wk1Monday + Wk1Tuesday + Wk1Wednesday + Wk1Thursday + Wk1Friday
            Dim Wk2TimeWorked = Wk2Monday + Wk2Tuesday + Wk2Wednesday + Wk2Thursday + Wk2Friday
    
            Dim Wk1RegularTime = 40.0
            Dim Wk1OverTime = Wk1TimeWorked - 40.0
            Dim Wk1RegularPay = HourlySalary * 40.0
            Dim Wk1OvertimePay = HourlySalary * 1.5 * Wk1OverTime
    
            Dim Wk2RegularTime = 40.0
            Dim Wk2OverTime = Wk2TimeWorked - 40.0
            Dim Wk2RegularPay = HourlySalary * 40.0
            Dim Wk2OvertimePay = HourlySalary * 1.5 * Wk2OverTime
    
            If Wk1TimeWorked <= 40.0 Then
                Wk1RegularTime = Wk1TimeWorked
                Wk1OverTime = 0.0
                Wk1RegularPay = HourlySalary * Wk1TimeWorked
                Wk1OvertimePay = 0.00
            End If
    
            If Wk2TimeWorked <= 40.0 Then
                Wk2RegularTime = Wk2TimeWorked
                Wk2OverTime = 0.0
                Wk2RegularPay = HourlySalary * Wk2TimeWorked
                Wk2OvertimePay = 0.00
            End If
    
            Dim Wk1NetPay = Wk1RegularPay + Wk1OvertimePay
            Dim Wk2NetPay = Wk2RegularPay + Wk2OvertimePay
            Dim NetPay = Wk1NetPay + Wk2NetPay
    
            Console.WriteLine("===================================================")
            Console.WriteLine("Payroll Evaluation")
            Console.WriteLine("===================================================")
            Console.WriteLine("Employee Information")
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine($"Full Name:     {FirstName} {LastName}")
            Console.WriteLine($"Hourly Salary: {HourlySalary:f}")
            Console.WriteLine("===================================================")
            Console.WriteLine("Time Worked Summary")
            Console.WriteLine("--------+---------+-----------+----------+---------")
            Console.WriteLine(" Monday | Tuesday | Wednesday | Thursday | Friday")
            Console.WriteLine("--------+---------+-----------+----------+---------")
            Console.WriteLine("{0,6:f}  | {1,6:f}  | {2,7:f}   | {3,7:f}  | {4,5:f}",
                              Wk1Monday, Wk1Tuesday, Wk1Wednesday, Wk1Thursday, Wk1Friday)
            Console.WriteLine("--------+---------+-----------+----------+---------")
            Console.WriteLine("{0,6:f}  | {1,6:f}  | {2,7:f}   | {3,7:f}  | {4,5:f}",
                              Wk2Monday, Wk2Tuesday, Wk2Wednesday, Wk2Thursday, Wk2Friday)
            Console.WriteLine("========+=========+===========+==========+=========")
            Console.WriteLine("                   Pay Summary")
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine("                                Time      Pay")
            Console.WriteLine("===================================================")
            Console.WriteLine("    First Week     Regular:{0,9:f}{1,12:f}", Wk1RegularTime, Wk1RegularPay)
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine("                   Overtime:{0,8:f}{1,12:f}", Wk1OverTime, Wk1OvertimePay)
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine("                   Weekly Pay:{0,18:f}", Wk1NetPay)
            Console.WriteLine("===================================================")
            Console.WriteLine("    Second Week    Regular:{0,9:f}{1,12:f}", Wk2RegularTime, Wk2RegularPay)
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine("                   Overtime:{0,8:f}{1,12:f}", Wk2OverTime, Wk2OvertimePay)
            Console.WriteLine("---------------------------------------------------")
            Console.WriteLine("                   Weekly Pay:{0,18:f}", Wk2NetPay)
            Console.WriteLine("===================================================")
            Console.WriteLine("                   Net Pay:{0,21:f}", NetPay)
            Console.WriteLine("===================================================")
        End Sub
    End Module
  9. To execute the project, on the main menu, click Debug -> Start Without Debugging
  10. When requested, type each of the following values and press Enter each time:
    First Name:    Michael
    Last Name:     Carlock
    Hourly Salary: 28.46
    Week 1
    Monday:         7
    Tuesday:        8
    Wednesday:      6.5
    Thursday:       8.5
    Friday:         7.5
    Week 2
    Monday:         9.5
    Tuesday:        8.5
    Wednesday:     10.5
    Thursday:       9
    Friday:         8
    Here are are the results:
    Payroll Evaluation
    ===================================================
    Enter the following pieces of information
    ---------------------------------------------------
    Employee Information
    ---------------------------------------------------
    First Name:        Michael
    Last Name:         Carlock
    Hourly Salary:     28.46
    ===================================================
    Time worked - First Week
    ---------------------------------------------------
    Monday:            7
    Tuesday:           8
    Wednesday:         6.5
    Thursday:          8.5
    Friday:            7.5
    ===================================================
    Time worked - Second Week
    ---------------------------------------------------
    Monday:            9.5
    Tuesday:           8.5
    Wednesday:         10.5
    Thursday:          9
    Friday:            8
    ===================================================
    Payroll Evaluation
    ===================================================
    Employee Information
    ---------------------------------------------------
    Full Name:     Michael Carlock
    Hourly Salary: 28.46
    ===================================================
    Time Worked Summary
    --------+---------+-----------+----------+---------
     Monday | Tuesday | Wednesday | Thursday | Friday
    --------+---------+-----------+----------+---------
      7.00  |   8.00  |    6.50   |    8.50  |  7.50
    --------+---------+-----------+----------+---------
      9.50  |   8.50  |   10.50   |    9.00  |  8.00
    ========+=========+===========+==========+=========
                       Pay Summary
    ---------------------------------------------------
                                    Time      Pay
    ===================================================
        First Week     Regular:    37.50     1067.25
    ---------------------------------------------------
                       Overtime:    0.00        0.00
    ---------------------------------------------------
                       Weekly Pay:           1067.25
    ===================================================
        Second Week    Regular:    40.00     1138.40
    ---------------------------------------------------
                       Overtime:    5.50      234.79
    ---------------------------------------------------
                       Weekly Pay:           1373.20
    ===================================================
                       Net Pay:              2440.45
    ===================================================
    
    Press any key to close this window . . .
  11. Press any key to close the window and return to your programming environment
  12. Close your programming environment

Home Copyright © 2001-2025, FunctionX Saturday 14 December 2024, 20:56 Home