Visual Basic™ Framework

Software Engineering: Simple Payroll Program

[ Previous ] [ Quick Start Index ] [ Next ]

How to write event procedures for the objects

Table of Contents

 

Background Information

A Visual Basic form can be written with code for the objects.

 

Back to top

How does this work?

1.      In this program, the significant events are when you type Enter in the textboxes ‘Salary’, and ‘Overtime’.

TIP

To add an event procedure

 

Ø      Double click on the object.

Ø      Select the appropriate event from the pull-down list on the right.  In this case the Keypress event.  A procedure skeleton will appear.

2.      Type in the following codes. You may copy and paste only the bolded codes to the respective object and procedure.

 

Object: ‘Overtime  -  Procedure ‘KeyPress

Private Sub Overtime_KeyPress (KeyAscii As Integer)

   If KeyAscii = 13 Then

      If Salary <> "" Or Overtime <> "" Then

         Paycheque = Val(Salary) + Val(Overtime) * 5

      End If

   End If

End Sub

 

Object: ‘Salary’ - Procedure ‘KeyPress

Sub Salary_KeyPress (KeyAscii As Integer)

   If KeyAscii = 13 Then

      If Salary <> "" Or Overtime <> "" Then

         Paycheque = Val(Salary) + Val(Overtime) * 5

      End If

   End If

End Sub

 

3.      Test your program by clicking the Run icon  on the Toolbar or selecting ‘Start’ from the Run menu.  Enter values in the three textboxes and see how the program responds.  If any errors occur, correct them and start again.

4.      To stop the program, click the End icon  or select ‘End’ from the Run menu.


ALERT

At this check point, record 2nd Quarter Completion Time:  _____________


Back to top

What next?

Complete your program like any other Visual Basic applications by adding a command button to terminate the program.

 

Back to top

 

Last revised: 06 January 2004        13:00

 

If you spot an error, please contact sbho@mmu.edu.my   In addition, please contact me if you find some aspects of this task is not explained clearly so that I can improve this documentation.