Wednesday, April 29, 2020

Payroll Source code in VB6.0






 Private Sub cmdAddDelete_Click()
    Load frmAddDelete
    frmAddDelete.Show vbModeless
End Sub

Private Sub cmdExit_Click()
    End
End Sub

Private Sub cmdPay_Click()
    Load frmPay
    frmPay.Show vbModeless
End Sub

Private Sub m_add_delete_Click()
    cmdAddDelete_Click
End Sub

Private Sub m_center_Click()
    frmMenu.Move 3000, 3000
End Sub

Private Sub m_close_Click()
    End
End Sub

Private Sub m_green_Click()
    Me.BackColor = RGB(51, 102, 51)
End Sub

Private Sub m_blue_Click()
    Me.BackColor = RGB(0, 0, 51)
End Sub

Private Sub m_Pay_Click()
    cmdPay_Click
End Sub

Private Sub m_Programmer_Click()
    MsgBox "Program written by the world's best Programmer", vbInformation + vbOKOnly, "Programmer?"
End Sub

Private Sub m_Red_Click()
    Me.BackColor = RGB(153, 51, 51)
End Sub








 Option Explicit
    Dim strEmployee As String
    Dim strEmployeeRead As String
    Dim intCounter As Integer
    Dim intIndex As Integer
    Dim intX As Integer
  
Private Sub cmdAdd_Click()
    If txtAdd.Text = "" Then
        MsgBox "You must enter an employee!!", vbCritical + vbOKOnly, "Enter Name!"
    Else
        Open App.Path & "\employee.txt" For Append As #4
  
        strEmployee = txtAdd.Text
  
        Write #4, strEmployee
        strEmployee = txtAdd.Text
        lstEmployee.AddItem (strEmployee)
        txtAdd.Text = ""
        Close #4
    End If
End Sub

Private Sub cmdReturn_Click()
    Unload Me
End Sub

Private Sub cmdDelete_Click()
    If txtAdd.Text = "" Then
        MsgBox "You must click on an employee!!", vbCritical + vbOKOnly, "Enter Name!"
    Else
        Open App.Path & "\employee.txt" For Input As #1
        Open App.Path & "\Temp.txt" For Output As #2
  
        intX = intIndex
        strEmployee = lstEmployee.Text
        lstEmployee.RemoveItem intX
  
        Do Until EOF(1)
            Input #1, strEmployeeRead
          
            If (LCase(strEmployeeRead) = LCase(strEmployee)) Then
                intCounter = intCounter + 1
            Else
                Write #2, strEmployeeRead
            End If
        Loop
        Close #1
        Close #2
  
  
        If intCounter > 0 Then
            Open App.Path & "\employee.txt" For Output As #1
            Open App.Path & "\Temp.txt" For Input As #2
      
            Do Until EOF(2)
                Input #2, strEmployeeRead
                Write #1, strEmployeeRead
            Loop
            Close #1
            Close #2
        End If
        txtAdd.Text = ""
    End If
End Sub

Private Sub Form_Load()
    Open App.Path & "\employee.txt" For Input As #3
  
    Do While (Not EOF(3))
        Input #3, strEmployeeRead
        lstEmployee.AddItem (strEmployeeRead)
    Loop
    Close #3
End Sub

Private Sub lblMessage_Click()
    MsgBox "You must select an employee and click Delete or enter a name and click Add!", vbInformation + vbOKOnly, "Aide"
End Sub

Private Sub lstEmployee_Click()
    txtAdd.Text = lstEmployee.Text
    intIndex = lstEmployee.ListIndex
End Sub

Private Sub m_center_Click()
    frmAddDelete.Move 3000, 3000
End Sub

Private Sub m_close_Click()
    Unload Me
    Load frmMenu
    frmMenu.Show vbModeless
End Sub

Private Sub m_menu_Click()
    Unload Me
    Load frmMenu
    frmMenu.Show vbModeless
End Sub

Private Sub m_pay_calc_Click()
   Unload Me
   Load frmPaye
   frmPaye.Show vbModeless
End Sub






Option Explicit
    Dim sngGrossPay As Single
    Dim sngNetPay As Single
    Dim sngTaxRate As Single
    Dim sngTaxAmount As Single
    Dim sngOt As Single
    Dim sngHours As Single
    Dim sngRate As Single
    Dim sngNbrOt As Single
    Dim strRate As String
    Dim strEmployee As String
   
   
Private Sub cmdAddDelete_Click()
    Load frmAddDelete
    frmAddDelete.Show vbModeless
End Sub


Private Sub cmdCalc_Click()
    sngHours = Val(txtNbrHours.Text)
    sngRate = Val(txtRate.Text)
    sngNbrOt = Val(txtNbrOt2.Text)
    sngOt = 0
   
    If txtNbrHours.Text = "" Then
        MsgBox "Input number of hours!!", vbCritical + vbOKOnly, "Nb hours?"
    ElseIf txtRate.Text = "" Then
        MsgBox "Input hourly rate!!", vbCritical + vbOKOnly, "Rate?"
    Else
       
       
       
    'Tax rate depends on Province selected
    If lstProvince.ListIndex = 0 Then
        sngTaxRate = 35
    ElseIf lstProvince.ListIndex = 1 Then
        sngTaxRate = 30
    ElseIf lstProvince.ListIndex = 2 Then
        sngTaxRate = 28
    ElseIf lstProvince.ListIndex = 3 Then
        sngTaxRate = 25
    Else
        sngTaxRate = 33
    End If
       
    'Check if employee selected
    If lstEmployee.ListIndex > -1 Then
        'Check if province selected
        If lstProvince.ListIndex < 0 Then
            MsgBox "You must enter Province!", vbCritical + vbOKOnly, "Province??"
        Else
            'Check if hours entered!
            If sngHours <= 0 Then
                MsgBox "You must enter Hours!", vbCritical + vbOKOnly, "Nb hours??"
      
            'Check if hourly rate entered!
            Else
                If sngRate <= 0 Then
                    MsgBox "You must enter hourly rate!", vbCritical + vbOKOnly, "Rate??"
                Else
                   
                    sngHours = Val(txtNbrHours.Text)
                    sngRate = Val(txtRate.Text)
                    sngNbrOt = Val(txtNbrOt2.Text)
                    sngOt = 0#
                   
                    If sngNbrOt > 0 Then
                        sngOt = sngNbrOt * sngRate * 1.5
                    Else
                        sngOt = 0#
                    End If
                   
                    If sngHours < 40 Then
                        lblOT.Visible = True
                        lblOt2.Visible = True
                       
                        sngGrossPay = sngHours * sngRate
                        sngTaxAmount = (sngGrossPay * sngTaxRate) / 100
                        sngNetPay = sngGrossPay - sngTaxAmount
                       
                        text_fields
                        lblNet2.BackColor = vbRed
                        lblNet2.ForeColor = vbBlack
                    Else
                        lblOT.Visible = True
                        lblOt2.Visible = True
                       
                        sngGrossPay = (((sngHours - sngNbrOt) * sngRate) + sngOt)
                        sngTaxAmount = sngGrossPay * sngTaxRate / 100
                        sngNetPay = sngGrossPay - sngTaxAmount
                       
                        text_fields
                       
                        lblNet2.BackColor = vbRed
                        lblNet2.ForeColor = vbBlack
                    End If
                End If
            End If
        End If
   
    Else
        MsgBox "Select an employee, Please!!", vbCritical + vbOKOnly, "Employee?"
    End If
    End If
End Sub

Private Sub cmdClear_Click()
    Clear
End Sub

Private Sub cmdExit_Click()
    Unload Me
    Load frmMenu
    frmMenu.Show vbModeless
End Sub

Private Sub Form_Load()
    Clear
    txtDate.Text = Format(Date, "yyyy-mm-dd")
    Open App.Path & "\employee.txt" For Input As #1
   
    Do While Not EOF(1)
        Input #1, strEmployee
        lstEmployee.AddItem (strEmployee)
    Loop
    Close #1
   
    lstProvince.AddItem "Ontario"
    lstProvince.AddItem "Quebec"
    lstProvince.AddItem "Manitoba"
    lstProvince.AddItem "New-Brunswick"

   
    chkOT.Visible = False
    chkOT.Value = vbUnchecked
    'lblNbrOT.Visible = False
    txtNbrOt2.Visible = False
    lblOT.Visible = False
    lblOt2.Visible = False
    lblRate3.Caption = "0 %"
End Sub

Private Sub lstProvince_Click()
    If lstProvince.ListIndex = 0 Then
        lblRate3.Caption = "35 %"
    ElseIf lstProvince.ListIndex = 1 Then
        lblRate3.Caption = "30 %"
    ElseIf lstProvince.ListIndex = 2 Then
        lblRate3.Caption = "28 %"
    ElseIf lstProvince.ListIndex = 3 Then
        lblRate3.Caption = "25 %"
    Else
        lblRate3.Caption = "33 %"
    End If
End Sub

Private Sub m_add_delete_Click()
    Load frmAddDelete
    frmAddDelete.Show vbModeless
    Unload Me
End Sub

Private Sub m_center_Click()
    frmPay.Move 2000, 2000
End Sub

Private Sub m_close_Click()
    Unload Me
    Load frmMenu
    frmMenu.Show vbModeless
End Sub

Private Sub m_green_Click()
    Me.BackColor = RGB(51, 102, 51)
End Sub

Private Sub m_Red_Click()
    Me.BackColor = RGB(153, 51, 51)
End Sub

Private Sub m_blue_Click()
    Me.BackColor = RGB(0, 0, 51)
End Sub


Private Sub txtNbrHours_Change()
    If Not IsNumeric(txtNbrHours.Text) Then
        MsgBox "Must be numeric", vbCritical + vbOKOnly, "Numeric, Please!"
        txtNbrHours.Text = "0"
    Else
        If txtNbrHours.Text <= 40 And txtNbrHours.Text >= 0 Then
            lblOT.Visible = False
            txtNbrOt2.Visible = False
            txtNbrOt2.Text = "0"
            chkOT.Value = vbUnchecked
            lblOT.Visible = False
            lblOt2.Visible = False
            lblOt2.Caption = "0.00"
        Else
            'Max. number of hours in pay period is 100
            If txtNbrHours.Text > 100 Then
                MsgBox "Max. of 100 hours!", vbCritical + vbOKOnly, "Max 100!!"
                txtNbrHours.Text = "0"
            Else
                lblOT.Visible = True
                txtNbrOt2.Visible = True
                txtNbrOt2.Text = (txtNbrHours.Text - 40)
                lblOt2.Caption = ""
                chkOT.Visible = True
                chkOT.Value = vbChecked
                lblOt2.Visible = True
                lblOT.Visible = True
            End If
        End If
    End If
End Sub

Private Sub txtNbrHours_GotFocus()
    txtNbrHours.BackColor = RGB(255, 0, 0)
    txtNbrHours.ForeColor = RGB(255, 255, 255)
    txtNbrHours.SelStart = 0
    txtNbrHours.SelLength = Len(txtNbrHours.Text)
End Sub

Private Sub txtNbrHours_LostFocus()
    txtNbrHours.BackColor = RGB(255, 255, 255)
    txtNbrHours.ForeColor = RGB(0, 0, 0)
End Sub

Private Sub txtRate_Change()
    If Not IsNumeric(txtRate.Text) Then
        MsgBox "Must be numeric!", vbCritical + vbOKOnly, "Numeric, Please!"
        txtRate.Text = "0"
    Else
        If txtRate.Text > 50 Then
            MsgBox "Max. hourly rate is $50!", vbCritical + vbOKOnly, "Max 50/hr!!"
            txtRate.Text = "0"
        End If
    End If
End Sub

Private Sub text_fields()
    lblOt2.Caption = Format(sngOt, "currency")
    lblGross2.Caption = Format(sngGrossPay, "currency")
    lblTax2.Caption = Format(sngTaxAmount, "currency")
    lblNet2.Caption = Format(sngNetPay, "currency")
End Sub

Private Sub Clear()
    lblOt2.Caption = "0"
    lblGross2.Caption = "0"
    lblTax2.Caption = "0"
    txtRate.Text = "0"
    lblNet2.Caption = "0"
    txtNbrHours.Text = "0"
    txtNbrOt2.Text = "0"
    lblRate3.Caption = "0"
    lstProvince.ListIndex = -1
    lstEmployee.ListIndex = -1
    lblNet2.BackColor = vbWhite
    lblNet2.ForeColor = vbBlack
End Sub

Private Sub txtRate_GotFocus()
    txtRate.BackColor = RGB(255, 0, 0)
    txtRate.ForeColor = RGB(255, 255, 255)
    txtRate.SelStart = 0
    txtRate.SelLength = Len(txtRate.Text)
End Sub

Private Sub txtRate_LostFocus()
    txtRate.BackColor = RGB(255, 255, 255)
    txtRate.ForeColor = RGB(0, 0, 0)
End Sub



No comments:

Post a Comment