Page 443 - Computer Software Application TP - Volume 1
P. 443

COMPUTER SOFTWARE APPLICATION - CITS




              when the user form is initialized, all text boxes’ contents are cleared or set to default values, and the focus is
              set to the txtid text box. This ensures a clean and focused user interface when the form is opened, providing
              a clear starting point for user input or interaction.
           •  Step 7: Now add the code to the Calculate and Submit button. Upon clicking the submit button, the user should
              be able to add the values into the worksheet.  The following VBA code seems to be part of a user interface for
              calculating salaries based on certain inputs such as employee ID, name, basic pay, and deductions.
              Dim row As Long  ‘in general declaration
              Private Sub cmdcalculate_Click()
              Dim eid As Integer, ename As String, bp As Single, da As Single, hra As Single, ts As Single, ns As Single, ded
              As Single
              Cells(2, 1).Value = “Employee Id”
              Cells(2, 2).Value = “Employee Name”

              Cells(2, 3).Value = “Basic Pay”
              Cells(2, 4).Value = “DA”
              Cells(2, 5).Value = “HRA”
              Cells(2, 6).Value = “Deduction”

              Cells(2, 7).Value = “Total Salary”
              Cells(2, 8).Value = “Net Salary”
              eid = txtid.Value
              ename = txtname.Text
              bp = txtbp.Value
              da = bp * (107 / 100)

              txtda.Text = da
              hra = bp * (25 / 100)
              txthra.Text = hra
              ded = txtded.Value

              txtts.Value = bp + hra + da
              txtns.Value = txtts.Value - ded
              End Sub
           This VBA code seems to be part of a user interface for calculating salaries based on certain inputs such as
           employee ID, name, basic pay, and deductions. Let’s break down the code and explain each part:
           1  Variable Declarations:
              •  row As Long: This declares a variable named row as a Long data type. However, this variable is not used
                 in the provided code snippet.
              •  eid As Integer, ename As String, bp As Single, da As Single, hra As Single, ts As Single, ns As
                 Single, ded As Single: These lines declare several variables:

              •  eid as an Integer to store Employee ID,
              •  ename as a String to store Employee Name,
              •  bp, da, hra, ts, ns, and ded as Single data types to store Basic Pay, Dearness Allowance, House Rent
                 Allowance, Total Salary, Net Salary, and Deductions respectively.
           2  Command Button Click Event (cmdcalculate_Click()):
              •  This subroutine is executed when the user clicks the “Calculate” button.



                                                           428

                               CITS : IT & ITES - Computer Software Application - Exercise 71
   438   439   440   441   442   443   444   445   446   447   448