Post by Tasp on Aug 19, 2021 14:26:46 GMT -5
Hi All.....
I am yet again having issues with calculating time, this seems to be a regular occurrence which I never seem to master!
The program is to assist me completing my monthly timesheet. We are paid for 8 hour 30 minutes each day. However we have a flexible start and finish time. Whenever we work past the 8 hours 30 minutes we are able to claim overtime, we have to insert this manually but in decimal format. Since I work overtime nearly everyday I normally have 20 plus entries to add on to. Aha! lets turn to LB to speed up the process!
For instance we start at 0700 and finish at 1530, if we actually finish at 1545, we have to add 0.25 to the timesheet. The program below works fine for this. However if I insert a finish time after say 1600 (for this example) the calculation is way off.
I've tried many different attempts to calculate this, but the calculation still eludes me. It would also be nice to round it up to the nearest quarter. But thats just being cheeky!
Rather than DATA statements holding the start and finishing times it was easier to write a few lines of LB to a file to hold the info and just load it in each time (file attached).
Any pointers are gratefully received!
times.txt (3.24 KB)
I am yet again having issues with calculating time, this seems to be a regular occurrence which I never seem to master!
The program is to assist me completing my monthly timesheet. We are paid for 8 hour 30 minutes each day. However we have a flexible start and finish time. Whenever we work past the 8 hours 30 minutes we are able to claim overtime, we have to insert this manually but in decimal format. Since I work overtime nearly everyday I normally have 20 plus entries to add on to. Aha! lets turn to LB to speed up the process!
For instance we start at 0700 and finish at 1530, if we actually finish at 1545, we have to add 0.25 to the timesheet. The program below works fine for this. However if I insert a finish time after say 1600 (for this example) the calculation is way off.
I've tried many different attempts to calculate this, but the calculation still eludes me. It would also be nice to round it up to the nearest quarter. But thats just being cheeky!
Rather than DATA statements holding the start and finishing times it was easier to write a few lines of LB to a file to hold the info and just load it in each time (file attached).
Any pointers are gratefully received!
'NOMAINWIN
DIM StartTime$(500), FinishTime$(500)
Calculation$ = "xx.xx"
'Collect times and put them into arrays
OPEN DefaultDir$ + "\times.txt" FOR INPUT AS #times
WHILE filelength = 0
INPUTCSV #times, a$, b$
StartTime$(i) = a$
FinishTime$(i) = b$
IF a$ = "END" THEN
filelength = 1
ELSE
i = i + 1
END IF
WEND
CLOSE #times
'Define window
WindowWidth = 400 : WindowHeight = 250
STYLEBITS #main, _DS_CENTER,0,_WS_EX_TOPMOST,0 'centers dialog modal window and sets Z order to topmost
STATICTEXT #main.stxt1, "Start Time", 10, 10, 80, 18
TEXTBOX #main.1, 10, 30, 60, 35
STATICTEXT #main.stxt2, "Finish Time", 100, 10, 100, 18
TEXTBOX #main.2, 100, 30, 60, 35
STATICTEXT #main.stxt3, "Calculation:", 10, 100, 300, 25
STATICTEXT #main.stxt4, "Start Time:", 10, 125, 300, 25
STATICTEXT #main.stxt5, "Finish Time:", 10, 150, 300, 25
STATICTEXT #main.stxt6, "Actual Finish:", 10, 175, 300, 25
BUTTON #main.default, "Calculate", [Calculate], UL, 200, 20, 70, 50
BUTTON #main.clear, "Clear", [Clear], UL, 300, 20, 70, 50
OPEN "Timesheet Assist" FOR WINDOW AS #main
#main, "trapclose [Close]"
#main, "font Tahoma 10"
#main.stxt3, "!font Tahoma 14"
#main.1, "!font Tahoma 14"
#main.2, "!font Tahoma 14"
#main.1, "!setfocus"
[main.wait]
WAIT
[Calculate]
#main.1, "!Contents? StartTime$";
#main.2, "!Contents? ActualFinishTime$";
'Check for 4 chars
IF LEN(StartTime$) <> 4 THEN NOTICE "Start time isn't correct!" : WAIT
IF LEN(ActualFinishTime$) <> 4 THEN NOTICE "Finish time isn't correct!" : WAIT
'Find start and correct finish times from the data list
'Then once found calculate the difference.
FOR a = 1 TO i
DataStartTime$ = StartTime$(a)
IF DataStartTime$ = StartTime$ THEN
FinishTime$ = FinishTime$(a)
Difference = VAL(ActualFinishTime$) - VAL(FinishTime$)
'Calculate the difference in decimal.
' Difference = Difference MOD 60
' Difference = INT(Difference / 60)
Difference = Difference / 60
#main.stxt3, "Calculation:";USING("##.##", Difference)
#main.stxt4, "Start Time: ";StartTime$
#main.stxt5, "Finish Time: ";FinishTime$
#main.stxt6, "Actual Finish: ";ActualFinishTime$
PRINT "StartTime = ";StartTime$;" Finish Time = ";FinishTime$; " Actual Finish Time: ";ActualFinishTime$
PRINT "Difference = ";Difference
EXIT FOR
END IF
NEXT
WAIT
[Clear]
#main.1, ""
#main.2, ""
#main.1, "!setfocus"
#main.stxt4, ""
#main.stxt5, ""
#main.stxt6, ""
WAIT
[Close]
CLOSE #main
END
times.txt (3.24 KB)