69) Design a form and write a program in visual basic to input employee code, employee name and address of some employees from one input data file named as employee.txt and in array. Input basic pay, DA, HRA, medical from second input data file named as salary.txt in an array. Both data files contain same number of records. Calculate gross pay with formula basic pay + DA + HRA + medical. Print employee code, employee name, address and calculated gross pay in ascending order on gross pay?

VBI 69.PNG

Private Sub Command1_Click()
    Dim STemp, EName(1 To 100), Address(1 To 100) As String
    Dim i, j, x, ITemp, Code(1 To 100), Basic(1 To 100), DA(1 To 100), HRA(1 To 100), Medical(1 To 100), Gross(1 To 100) As Integer
    Open "Employee.txt" For Input As #1
    i = 0
    Do While Not EOF(1)
        i = i + 1
        Input #1, Code(i), EName(i), Address(i)
    Loop
    x = i
    Close #1
    Open "Sallary.txt" For Input As #2
    For i = 1 To x
        Input #2, Basic(i), DA(i), HRA(i), Medical(i)
        Gross(i) = Basic(i) + DA(i) + HRA(i) + Medical(i)
    Next i
    Close #2
    For i = 1 To x - 1
        For j = i + 1 To x
            If Gross(i) > Gross(j) Then
                ITemp = Code(i)
                Code(i) = Code(j)
                Code(j) = ITemp
                STemp = EName(i)
                EName(i) = EName(j)
                EName(j) = STemp
                STemp = Address(i)
                Address(i) = Address(j)
                Address(j) = STemp
                ITemp = Basic(i)
                Basic(i) = Basic(j)
                Basic(j) = ITemp
                ITemp = DA(i)
                DA(i) = DA(j)
                DA(j) = ITemp
                ITemp = HRA(i)
                HRA(i) = HRA(j)
                HRA(j) = ITemp
                ITemp = Medical(i)
                Medical(i) = Medical(j)
                Medical(j) = ITemp
                ITemp = Gross(i)
                Gross(i) = Gross(j)
                Gross(j) = ITemp
            End If
        Next j
    Next i
    Cls
    Print "E Code", "E Name", "E Address", "Gross Pay"
    For i = 1 To x
        Print Code(i), EName(i), Address(i), Gross(i)
    Next i
End Sub

VBO 69.PNG

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: