Jump to content
Server Maintenance This Week. ×

HowTo: Timeout a Script Loop


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

Recommended Posts

[color:blue]Hello,

This is my first post, so plese excuse if something is wrong. I've found it useful to timeout a loop if it is taking too long.


Set Field [ Settings::gTime; Get (CurrentTime ) ]

Loop

   Exit Loop If [GetAsTime ( Get ( CurrentTime) ) -  GetAsTime ( Settings::gTime ) > 3

   Exit Loop If [ ... ]

   ... Do what ever here ...

End Loop

I assume you can have multiple exits of a loop as long as one is met. Which is what I have. I have set it to exit after 3 seconds.

Thanks and God Bless!

David Garza

Link to comment
Share on other sites

Nice idea. Note that in FileMaker 8 you can use a variable rather than a global field.

Another option for an "escape hatch" is to use the Get ( ActiveModifierKeys ) function.

Link to comment
Share on other sites

Hey, thank you for your suggestions! I will keep the ActiveModifierKey in mind for secrete such as logging into another user for permissions.

Here is a revised copy of the script:


Set Variable [$starttime; Get ( CurrentTime )]

Loop

   Exit Loop If [GetAsTime ( Get ( CurrentTime) - $starttime ) > GetAsTime ( 00:00:03 )

   Perform Script Here....

End Loop

I changed the time to timeout format because it makes it better if you want to use hours, because before it would default to only seconds. Not you can use hours, such as: 13:27:32

It will timeout in 13 hours, 27 minutes and 32 seconds.

Please let me know if there is a better way!

Thanks and God Bless!

David

Link to comment
Share on other sites

GetAsTime() is meant to convert TEXT type data into TIME type. GetAsTime (time) does nothing. The correct syntax for your exit condition would be:

Exit Loop If [ Get ( CurrentTime) - $starttime > Time ( 0 ; 0 ; 3 ) ]

Using a timestamp might be more suitable here - just in case someone starts the script shortly before midnight...

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

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