Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 4610 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted

I have two times that I need to calculate the difference between. This is never more than 24 hours.

StartTime and EndTime are four-digit numbers (integers) representing 24-hour military time. The FileMaker time field, while it could support 24 hour time, was too buggy with copy/paste and the colons between hours, minutes, and seconds. I've changed the user-entered fields to text fields validated as "numeric only" between 0000 and 2359. Working to add the ability to prevent times like 2284, but the time function will actually account for that. Anyways, my calculation to find the different between StartTime and EndTime is working, as long as the EndTime is greater than the StartTime. If it's not, I need to add 24 hours to the result time.

I'm currently getting the following error with the last line of this function.

A number, text constant, field name or “(” is expected here.

Here's the function, which works fine, aside from the last if statement.


Let ( [

theData1=  StartTime

; theHour1= Left ( theData1 ; 2 )

; theMinute1= Right ( theData1 ; 2 )

; theSeconds1= "00"

; theTime1= Time ( theHour1 ; theMinute1 ; theSeconds1 )

; theData2=  EndTime

; theHour2= Left ( theData2 ; 2 )

; theMinute2= Right ( theData2 ; 2 )

; theSeconds2= "00"

; theTime2= Time ( theHour2 ; theMinute2 ; theSeconds2 )

; result = GetAsNumber(theTime2) - GetAsNumber(theTime1)

; If  ( result < 0 ; result = result + Time(24;0;0) ) ;

];

result

)

Does anyone have an idea what I might need to do? I've tried a Case statement, and gotten the same error. Do I just not understand how to use If statements in FilemakerCode?

Thanks!

Posted

The problem is that you are in the midst of the Let() function. You need to either define a new variable, or move to calculate the result.

BTW, quite a few of your steps are redundant. Try, for example =

Let ( [

startHour = Left ( StartTime ; 2 ) ;

startMinute = Right ( StartTime ; 2 ) ;

start = Time ( startHour ; startMinute ; 0 ) ;  



endHour = Left ( EndTime ; 2 ) ;

endMinute = Right ( EndTime ; 2 ) ;

end = Time ( endHour ; endMinute ; 0 ) ;



duration = end - start

] ;

duration + If  ( duration < 0 ; Time ( 24 ; 0 ; 0 ) )

)

---

P.S. semi-colons signify the end of an argument and therefore should be placed at the end of the argument, not at the beginning of a new line.

  • Newbies
Posted

Thanks for the advice. I've just been cobbling together bits of code from other sources, but it looks like I should probably invest in a book or at least a well written tutorial. You made that look so easy.

If I declare a variable in one let statement, can I still reference it later on? What exactly is the purpose of putting this all in a let statement?

Posted

If I declare a variable in one let statement, can I still reference it later on?

Not, not unless it's a "script variable", i.e. prefixed by a $ or $$. Otherwise the variables expire where the Let() function ends.

What exactly is the purpose of putting this all in a let statement?

In this case, it's mostly aesthetics - i.e. it's more convenient to follow the code than the purist's version =

Let ( [

duration = Time ( Left ( EndTime ; 2 ) ; Right ( EndTime ; 2 ) ; 0 ) - Time ( Left ( StartTime ; 2 ) ; Right ( StartTime ; 2 ) ; 0 )

] ;

duration + If ( duration < 0 ; Time ( 24 ; 0 ; 0 ) )

)

The other reason is to calculate variables only once - as in duration above.

This topic is 4610 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.