Daily Wage Calculator in Vb 6

Advertisements
Advertisements

 51 total views

In this example, we are going to build an application to calculate the daily wage of temporary employees.

To compute the daily wage we need following inputs

  1. The number of Hours Employee worked.
  2. Hourly pay rate

The application computes the gross pay and displays it on the screen.

Wage Calculator Interface

To design the interface we go step by step.

Advertisements

Step 1: Open a new vb form and name it Daily Wage Calculator and save the project as wage_calculator. The following diagram shows the new form which we renamed.

Project - Wage Calculator
Project – Wage Calculator

You will get a new form as soon as you open the standard VB project windows. To change the name and caption of the form, go to property window located to the right-bottom of the project window.

Property - Wage Calculator
Property – Wage Calculator

In the property window, change the form name to Daily_Wage_Calc and caption to Daily Wage Calculator.

Step 2: Add Controls

Now its time to add more control. To complete the interface you need – two textboxes, 5 labels, and two command buttons.

The detailed settings for each control element are given below.

Textboxes

Name: txtHoursWorked
Caption: ' '
Height: 500
Width: 2400
Name: txtHoulyRate
Caption: ' '
Height: 500
Width: 2400

Labels

Name : lblTotEarnDisplay
Caption: ' '
Height: 500
Width: 2400
Name: lblHoursWorked
Caption: Hours Worked
Height: 495
Width: 1995
Name: lblHourlyRate
Caption: Hourly Rate
Height: 495
Width: 1995
Name: lblTotEarning
Caption: Total Earnings
Height: 495
Width: 1995

Command Buttons

Name: cmdGross
Caption: &Gross Pay
Height: 700
Width: 2400
Name: cmdClose
Caption: &Close
Height: 700
Width: 2400

The interface will look like the following after adding all the controls.

Advertisements
Interface - Wage Calculator
Interface – Wage Calculator

To align or to adjust the spacing between the controls go to Format tab > select Align or select Horizontal or Vertical spacing options.

You can add color to background and foreground in the property window so that the application look better visually.

Wage Calculator Window
Wage Calculator Window

Coding the Daily Wage Calculator Application

The application design is ready but it does not do anything. You need to write code for the application to work.

Step 3: Understand the logic and write code for the wage calculator application. You can do this in the following stages,

  • Get the inputs from textboxes
  • Store them in variables
  • Compute the gross pay
  • Display the output

First, we declare three variables to get the input values and use them later. We will store them in the variables.

Dim hours As Integer
Dim rate As Integer
Dim gross As Integer

Code for textboxes

Now write the code for textboxes are follows.

Private Sub txtHoursWorked_Change()

hours = Val(txtHoursWorked.Text)

End Sub
Private Sub txtHourlyRate_Change()

rate = Val(txtHourlyRate.Text)

End Sub

Code for Command Buttons

The code for command buttons is given below. To compute gross pay, the value of hoursandratevariable are multiplied and stored the variable -gross$.

\begin{aligned}gross pay = hours \hspace{3px} worked \times hourly \hspace{3px} rate\end{aligned}

The code for command button gross pay. Note than the caption for lblTotEarningDisplay is used to display the output.

Private Sub cmdGross_Click()
gross = hours * rate
lblTotEarnDisplay.Caption = Str(gross)
End Sub

The code for command button close is as follows.

Private Sub cmdClose_Click()

Unload Daily_Wage_Calc

End Sub

Test the Application

Now that we have coded the application, it is time to test the program.

Testing Wage Calculator
Testing Wage Calculator

The calculator is correctly calculating the daily wage of an employee given the inputs required.

VB 6 - Black Book

Visual Basic 6 Programming Black Book

The book completely explains the crucial Visual Basic tool set in detail. The book is designed to help save hours of time & perfect the best Visual Basic programming skills. From design tools to flowcharts, it covers everything from graphics & image processing, ActiveX controls, database development & data-bound controls. The book is packed with insights, programming tips and techniques, and real-world solutions. The CD contains demo copies of Coffee Cup HTML Editor++98, Quick Site, SQL-Station, Q-Diagnostic Software, and more.

Advertisements
Advertisements
Advertisements