Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Programming (https://www.askmehelpdesk.com/forumdisplay.php?f=437)
-   -   I'm not sure how to desk check this subroutine (https://www.askmehelpdesk.com/showthread.php?t=374307)

  • Jul 11, 2009, 05:16 AM
    wogdog2000
    I'm not sure how to desk check this subroutine
    if someone could start me off and ill finish the rest, that would be great.

    Q1. In this question you have to desk check what this piece of code is doing. It calculates the number of hours that an employee works by reading the .txt files produced by the fingerprint reader.

    SUB CalcHours ( IDnumber AS INTEGER, PaidHours (1 TO 7) AS SINGLE, PayDate AS STRING)
    DIM FileName AS STRING
    DIM FileNum AS INTEGER
    DIM hours AS INTEGER
    DIM day AS INTEGER
    FileName = "E:\" + LTRIM$(STR$(IDnumber)) + ".txt"
    FileNum = FREEFILE
    OPEN FileName FOR INPUT AS #FileNum
    LINE INPUT #FileNum, PayDate
    LINE INPUT #FileNum, a$
    FOR day = 1 TO 7
    INPUT #FileNum, in1$
    INPUT #FileNum, out1$
    INPUT #FileNum, in2$
    INPUT #FileNum, out2$

    IF in1$ <> "-" THEN
    hours = VAL(LEFT$(out1$, 2)) - VAL(LEFT$(in1$, 2))
    PaidHours(day) = hours * 60 + VAL(RIGHT$(out1$, 2)) - VAL(RIGHT$(in1$, 2))
    ELSE
    PaidHours(day) = 0
    END IF

    IF in2$ <> "-" THEN
    hours = VAL(LEFT$(out2$, 2)) - VAL(LEFT$(in2$, 2))
    PaidHours(day) = PaidHours(day) + hours * 60 + VAL(RIGHT$(out2$, 2)) - VAL(RIGHT$(in2$, 2))
    END IF
    PaidHours(day) = PaidHours(day) / 60
    NEXT
    CLOSE
    END SUB



    a) Perform a desk check on this subroutine, using the fingerprint file from above (1005.txt) with the following headings:

    day in1 out1 in2 out2 hours PaidHours(day)


    its supposed to be in a table

    the 1005.txt is under here

    6 April 2008 this is when he worked
    Marcus Fixit this is his name
    0730, 1145, 1245, 1600 this is what time he workes on Monday the times in the middle is his brakes so here it is from 11:45 to 12:45
    0800, 1215, 1245, 1715 this is what time he workes on Tuesday
    0815, 1200, 1245, 1730 this is what time he workes on Wednesday
    0811, 1155, 1233, 1700 this is what time he workes on Thursday
    -, -, -, - he did not work.
    0747, 1210, -, - today he only worked from 7:47 to 12:10.
    -, -, -, - he did not work


    this the hours that his guy worked and when he worked and his name.


    any questions to do with this just reply to the question
  • Jul 11, 2009, 05:45 AM
    Perito

    Basically, a Desk Check means to perform the calculation the same as the computer would do it.

    Quote:

    SUB CalcHours ( IDnumber AS INTEGER, PaidHours (1 TO 7) AS SINGLE, PayDate AS STRING)
    DIM FileName AS STRING
    DIM FileNum AS INTEGER
    DIM hours AS INTEGER
    DIM day AS INTEGER
    Declaration of variables and declaration of the subroutine. No desk checking here.

    Quote:

    1. FileName = "E:\" + LTRIM$(STR$(IDnumber)) + ".txt"
    2. FileNum = FREEFILE
    3. OPEN FileName FOR INPUT AS #FileNum
    4. LINE INPUT #FileNum, PayDate
    5. LINE INPUT #FileNum, a$
    Figure out file name (FileName) for input data. This should be straight-forward.
    1. Filename = "E:\1005.txt"
    2. FileNum = #(whatever)
    3. File is opened as #(whatever)
    4. PayDate = "6 April 2008"
    5. a$ = "Marcus Fixit"

    Quote:

    FOR day = 1 TO 7
    INPUT #FileNum, in1$
    INPUT #FileNum, out1$
    INPUT #FileNum, in2$
    INPUT #FileNum, out2$

    IF in1$ <> "-" THEN
    hours = VAL(LEFT$(out1$, 2)) - VAL(LEFT$(in1$, 2))
    PaidHours(day) = hours * 60 + VAL(RIGHT$(out1$, 2)) - VAL(RIGHT$(in1$, 2))
    ELSE
    PaidHours(day) = 0
    END IF

    IF in2$ <> "-" THEN
    hours = VAL(LEFT$(out2$, 2)) - VAL(LEFT$(in2$, 2))
    PaidHours(day) = PaidHours(day) + hours * 60 + VAL(RIGHT$(out2$, 2)) - VAL(RIGHT$(in2$, 2))
    END IF
    PaidHours(day) = PaidHours(day) / 60
    NEXT

    This is the main loop of the subroutine - the location where everything is done. This is what you have to concentrate on for your "desk check".

    Initially, the person's pay date and name are read (one line at a time). Then the program assumes that there will be seven days of data. For each of those days, four pieces of data are read into in1$, out1$, in2$, out2$. Those are on the same line.

    On day 1, they will be
    in1$="0730"
    out1$="1145"
    in2$="1245"
    out2$="1600"

    for Monday (BTW, people take breaks, not brakes).

    "in1$" is inspected to see if it's a "-" (not worked). If he did work, the pay calculation is made.

    If in1$ <> "-" Then ' Did he work?
    ' calculate hours to pay. Note that in each string only the two left characters are used to calculate the hours. The minutes are taken care of in the subsequent line..
    hours = Val(Left$(out1$, 2)) - Val(Left$(in1$, 2))
    ' The hours are multiplied by 60. Then the fractional minutes are added. Note that "PaidHours(day)" is actually in MINUTES!
    PaidHours(day) = hours * 60 + Val(Right$(out1$, 2)) - Val(Right$(in1$, 2))
    Else
    PaidHours(day) = 0 ' since he didn't work, no paid hours.
    End If

    ' Repeat the above calculation for the second set of times.
    If in2$ <> "-" Then
    hours = Val(Left$(out2$, 2)) - Val(Left$(in2$, 2))
    ' Note that PaidHours is added to.
    PaidHours(day) = PaidHours(day) + hours * 60 + Val(Right$(out2$, 2)) - Val(Right$(in2$, 2))
    End If
    PaidHours(day) = PaidHours(day) / 60

    Quote:

    CLOSE
    END SUB
    These last two lines don't have anything to do with a desk check.

    You just continue with the calculation with all of the data. I would suggest writing down the result of each calculation on a single line on a piece of paper. Indicate what the value of each variable is on each line. You could give each program line a number and then on the desk check paper, write down the line number and the results of that line's calculations.
  • Jul 22, 2009, 04:04 AM
    wogdog2000
    I have done the desk check so is it just the table which has

    Day In1 Out1 In2 Out2 Hours(amount of hours Paidhours(how much in the worked today)

    Monday 0730 1145 1245 1600 14.5hrs
    Tuesday 0800 1215 1245 1715 14.5hrs
    Wednesday 0815 1200 1245 1715
    Thursday
    Friday
    Saturday
    Sunday
  • Jul 22, 2009, 04:07 AM
    wogdog2000
    To perito
    I have done the desk check so is it just the table
    For the days, amount of hours worked and how much the person earned in that day.

  • All times are GMT -7. The time now is 12:58 PM.