If from a beginner

If from a beginner

am 01.10.2007 16:18:53 von MattG

I am sure it has been discussed before but I am not sure how to get my
if to work.

I am trying to figure out how to figure out my overtime

I have a record with fields that include Start Time, End Time, Total
Hours, and OT Hours

I first am trying to get the Total hours to round to the 1/4 hour. I
cannot seem to get that.

My OT Hours I want to work like this. Total Hours -10 (because that
is where I start getting overtime) If the result is positive I want
to list it. If the result is negative I want it to show a 0 or be
left blank.

Any Help?

Re: If from a beginner

am 01.10.2007 16:59:17 von Greg Dember

In article <1191248333.762230.61670@w3g2000hsg.googlegroups.com>,
mattG wrote:

> I am sure it has been discussed before but I am not sure how to get my
> if to work.
>
> I am trying to figure out how to figure out my overtime
>
> I have a record with fields that include Start Time, End Time, Total
> Hours, and OT Hours
>
> I first am trying to get the Total hours to round to the 1/4 hour. I
> cannot seem to get that.
>
> My OT Hours I want to work like this. Total Hours -10 (because that
> is where I start getting overtime) If the result is positive I want
> to list it. If the result is negative I want it to show a 0 or be
> left blank.
>
> Any Help?

If (Total Hours-10>0; Total Hours -10; 0)

Re: If from a beginner

am 01.10.2007 18:10:34 von ursus.kirk

"mattG" schreef in bericht
news:1191248333.762230.61670@w3g2000hsg.googlegroups.com...
>I am sure it has been discussed before but I am not sure how to get my
> if to work.
>
> I am trying to figure out how to figure out my overtime
>
> I have a record with fields that include Start Time, End Time, Total
> Hours, and OT Hours
>
> I first am trying to get the Total hours to round to the 1/4 hour. I
> cannot seem to get that.
>
> My OT Hours I want to work like this. Total Hours -10 (because that
> is where I start getting overtime) If the result is positive I want
> to list it. If the result is negative I want it to show a 0 or be
> left blank.
>
> Any Help?
>

You don't state, but assume you allways want to round down to the nearest
quarter. Your time is in a field Called MyTime

create a calculated field, return as time

LET
( [
A = Hours (MyTime) ;
B = Minutes (MyTime) ;
C = case ( B >= 00 AND B <= 15 ; 00 ;
B >= 15 AND B <= 30 ; 15 ;
B >= 30 AND B <= 45 ; 30 ;
B <= 45 AND B <= 59 ; 45 ) ] ;
Time ( A ; C ; 00 )
)

Untested, but this should get you going

Keep well, Ursus

Re: If from a beginner

am 01.10.2007 19:54:16 von MattG

On Oct 1, 11:10 am, "Ursus" wrote:
> "mattG" schreef in berichtnews:1191248333.762230.61670@w3g2000hsg.googlegroups. com...
>
>
>
> >I am sure it has been discussed before but I am not sure how to get my
> > if to work.
>
> > I am trying to figure out how to figure out my overtime
>
> > I have a record with fields that include Start Time, End Time, Total
> > Hours, and OT Hours
>
> > I first am trying to get the Total hours to round to the 1/4 hour. I
> > cannot seem to get that.
>
> > My OT Hours I want to work like this. Total Hours -10 (because that
> > is where I start getting overtime) If the result is positive I want
> > to list it. If the result is negative I want it to show a 0 or be
> > left blank.
>
> > Any Help?
>
> You don't state, but assume you allways want to round down to the nearest
> quarter. Your time is in a field Called MyTime
>
> create a calculated field, return as time
>
> LET
> ( [
> A = Hours (MyTime) ;
> B = Minutes (MyTime) ;
> C = case ( B >= 00 AND B <= 15 ; 00 ;
> B >= 15 AND B <= 30 ; 15 ;
> B >= 30 AND B <= 45 ; 30 ;
> B <= 45 AND B <= 59 ; 45 ) ] ;
> Time ( A ; C ; 00 )
> )
>
> Untested, but this should get you going
>
> Keep well, Ursus

Now to do this wouldn't I have to have two seperate fields one for the
hours and one for the minutes? Sorry for not knowing more on this.

Re: If from a beginner

am 01.10.2007 20:57:54 von d-42

On Oct 1, 9:10 am, "Ursus" wrote:
> "mattG" schreef in berichtnews:1191248333.762230.61670@w3g2000hsg.googlegroups. com...
>
>
>
> >I am sure it has been discussed before but I am not sure how to get my
> > if to work.
>
> > I am trying to figure out how to figure out my overtime
>
> > I have a record with fields that include Start Time, End Time, Total
> > Hours, and OT Hours
>
> > I first am trying to get the Total hours to round to the 1/4 hour. I
> > cannot seem to get that.
>
> > My OT Hours I want to work like this. Total Hours -10 (because that
> > is where I start getting overtime) If the result is positive I want
> > to list it. If the result is negative I want it to show a 0 or be
> > left blank.
>
> > Any Help?
>
> You don't state, but assume you allways want to round down to the nearest
> quarter. Your time is in a field Called MyTime
>
> create a calculated field, return as time
>
> LET
> ( [
> A = Hours (MyTime) ;
> B = Minutes (MyTime) ;
> C = case ( B >= 00 AND B <= 15 ; 00 ;
> B >= 15 AND B <= 30 ; 15 ;
> B >= 30 AND B <= 45 ; 30 ;
> B <= 45 AND B <= 59 ; 45 ) ] ;
> Time ( A ; C ; 00 )
> )
>
> Untested, but this should get you going

Yep, its the right approach, although the details are off a bit.

First, the above intervals overlap (You test B <= 15 ... and then in
the next case B >= 15) which means that if B=15 it matches both cases.
That isn't a problem if it gets it right, but it doesn't. The cases
are evaluated in order so it will end up rounded to 00 if its 15. You
want to test for B < 15 in the first case, and B >= 15 in the second
to avoid overlap, and be correct; or since the range is integers test
B <= 14 in case 1 and B >=15 in case 2... etc.

That was the only outright error in the calc, but its also got a fair
share of redundancy:

Testing B >=0 is redundant. Minutes() returns an integer value in the
range 0..59 so that test is never going to fail.

In fact, testing for the lower bound at each step is redundant. You
don't need to test that B >= 15 in the second case, because if was
less than 15 it would already have been picked up by the first case.

Finally, explicitly testing the last upper bound is redundant; if
minutes() hasn't been picked up by the first three cases its implicit
that it it will fall into the fourth. Minutes() can't return -5 or 76
so you can use the default case.

Fixing it all up and simplifying gets you this version:

LET
( [
A = Hours (MyTime) ;
B = Minutes (MyTime) ;
C = case (
B < 15 ; 00 ;
B < 30 ; 15 ;
B < 45 ; 30;
00;
)
];
Time ( A ; C ; 00 )

(Note that not trusting the inputs is a good thing, and Ursus' range
explicit and complete range checking isn't a bad thing in general, but
it isn't really needed here since I trust Minutes() to return 0..59.

And if we didn't trust minutes, then we should have a fail condition
that does something if minutes goes out of spec. In Ursus' calc if
Minutes did somehow return -5 it wouldn't match any case, C="" and the
time would convert that to a 0, letting the error go undetected. My
calc is no better, in that regard, but I trust Minutes() to return
0..59 and use that to simplify the calc.

If I didn't trust Minutes() I'd have a boolean D variable that checked
(B >=0 and B <60) and then at the the end instead of "Time(a;c0) I
have:

if (D=true; time(a;c;0); "holy crap Minutes() is broken")

-cheers,
Dave

Re: If from a beginner

am 01.10.2007 23:01:54 von Helpful Harry

In article <1191261256.951149.256680@22g2000hsm.googlegroups.com>,
mattG wrote:

> On Oct 1, 11:10 am, "Ursus" wrote:
> > "mattG" schreef in
> > berichtnews:1191248333.762230.61670@w3g2000hsg.googlegroups. com...
> >
> >
> >
> > >I am sure it has been discussed before but I am not sure how to get my
> > > if to work.
> >
> > > I am trying to figure out how to figure out my overtime
> >
> > > I have a record with fields that include Start Time, End Time, Total
> > > Hours, and OT Hours
> >
> > > I first am trying to get the Total hours to round to the 1/4 hour. I
> > > cannot seem to get that.
> >
> > > My OT Hours I want to work like this. Total Hours -10 (because that
> > > is where I start getting overtime) If the result is positive I want
> > > to list it. If the result is negative I want it to show a 0 or be
> > > left blank.
> >
> > > Any Help?
> >
> > You don't state, but assume you allways want to round down to the nearest
> > quarter. Your time is in a field Called MyTime
> >
> > create a calculated field, return as time
> >
> > LET
> > ( [
> > A = Hours (MyTime) ;
> > B = Minutes (MyTime) ;
> > C = case ( B >= 00 AND B <= 15 ; 00 ;
> > B >= 15 AND B <= 30 ; 15 ;
> > B >= 30 AND B <= 45 ; 30 ;
> > B <= 45 AND B <= 59 ; 45 ) ] ;
> > Time ( A ; C ; 00 )
> > )
> >
> > Untested, but this should get you going
> >
> > Keep well, Ursus
>
> Now to do this wouldn't I have to have two seperate fields one for the
> hours and one for the minutes? Sorry for not knowing more on this.

It depends on what version of FileMaker you're using. Newer versions
have the above "Let" / custom function ability, while in older versions
you have to split that custom function into separate fields.

You could achieve the same affect with a bit of mathematical
manipulation, but the above is easier to understand and change if you
decided to move to 10 minute rounding (for example).

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)