 1. ## Time Clock Question

Hi Board users:

Can't get this time clock calculations to come out correct anyone see whats wrong! I have attached the program files!  Reply With Quote

2. ## RE: Time Clock Question

Bob:

The calculation is in a calculated field rule.There are a couple of problems.
-the select-case syntax is wrong. You treat it as if it were a simple if function which it is not. Look at the documention on Select-case and you'll see in a second what I'm talking about.
-the calculation is slightly flawed in that you don't want to use toseconds on the break time field. You need to subtract the number of seconds of the value of the field rather than the number of seconds since midnight.

Perhaps someone can advise whether select-case would work in a calculated field rule. I would have to experiment to verify its behavior.

Another, easier, way to approach this would be to write code to the on_depart event of break_time to calculate the total time and insert the value in the total time field. It would be much easier to debug the calculation there. And select case would work fine.

Bill  Reply With Quote

3. ## RE: Time Clock Question

Bob:

I devoted a bit more time (ha ha) to your question. As usual, the devil is in the details.

Consider the following cut from the interactive window:
?toseconds("0100")
= 100.000000

?toseconds("01:00")
= 3600.000000

You can see that the ":" changes how the function interprets the time string. Since you had checked "do not store mask literals" in field rules, the expression calculating total time never saw a colon. So I unchecked the option. The calculation works now.

Calculated rule for total time field:
TOTIME(TOSECONDS(TIME_OUT)-TOSECONDS(TIME_IN)-TOSECONDS(BREAK_TIME),1,0)

Note that I eliminated the need for a conditional calculation by using a validation rule on a different field to make sure the times are in the proper order.

Validation expression for Time_OUT field:
TOSECONDS(TIME_OUT)>TOSECONDS(TIME_IN)

A more elegant user experience could be produced by writing event code at the form level but then it would have to be reproduced on every form. Validating via field rule is thus a bit easier.

A demo is attached. Open it in its own folder.

Bill  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•