Page 1 of 1

triggering a handler at a specific time

Posted: Wed Mar 19, 2014 11:34 am
by keram
Hi everybody,

In my stack I have 2 options: to either trigger a handler in the Next button at defined intervals (currently in seconds for testing purposes) or at a specific time.
Setting the the time intervals was easy although there may be some simpler or more correct way. But setting the specific time is not working.
I'm using this code:

Code: Select all

global gIncrement
on mouseUp
  set the twelveHourTime to false
   if the hilite of btn "Radio1" is "true" then
      --      put (label of btn "everyhours" * 3600 + label of btn "everyminutes" * 60) into gIncrement
      put (label of btn "everyhours" + label of btn "everyminutes") into gIncrement --used for development
      
      if timerIncrement is not in the pendingMessages then -- don't pile up timerIncrement
         send "timerIncrement" to me in gIncrement seconds
      end if
   else
      doItAtTime
   end if
end mouseUp

on timerIncrement
   send "timerIncrement" to me in gIncrement seconds
   send mouseUp to btn "next"
end timerIncrement

on doItAtTime
   if the short time =  (label of btn "onhour" &":"& label of btn "onminutes") then
      send mouseUp to btn "next" in 62 seconds
   end if
end doItAtTime
What do I have to correct to get the specific time setting working?
the stack is attached

keram

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 2:02 pm
by Klaus
Hi keram,
keram wrote:But setting the specific time is not working.
what and where in the script is meant to "set the specific time"?


Best

Klaus

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 2:42 pm
by keram
Hi Klaus,
Klaus wrote:what and where in the script is meant to "set the specific time"?
The script is in the "Save & Start"button and it is this:

....
else
doItAtTime
...

and

on doItAtTime
if the short time = (label of btn "onhour" &":"& label of btn "onminutes") then
send mouseUp to btn "next" in 62 seconds
end if
end doItAtTime

This is what I thought would work...

keram

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 2:57 pm
by Klaus
Hi Keram,

aha! :D

I think that this condition will only apply ONCE a day, if at all:

Code: Select all

...
if the short time = (label of btn "onhour" &":"& label of btn "onminutes")
...
Is this really what/how you want to check?


Best

Klaus

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 2:59 pm
by keram
Yes, just once a day.

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 4:48 pm
by Mark
Hi,

The following handler executes a handler almost exactly on the time you want it to execute (it might be half a second off).

Code: Select all

// theHandler: name of the command to be executed (no functions)
// theTime: the time when to execute the command
// assuming that useSystemDate is false
on sendCommandInTime theHandler,theTime
  convert theTime from time to seconds
  put theTime - the seconds into theSecondsToLapse
  if theSecondsToLapse > 0 then
    send theHandler to the target in theSecondsToLapse seconds
  end if
end sendCommandInTime
Call this handler as

Code: Select all

sendCommandInTime "yourHandler","4:00 PM"
Kind regards,

Mark

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 5:16 pm
by keram
Hi Mark,

Thanks for your reply.

It's not completely clear for me how to apply your solution so I'm guessing that this maybe how it should be(?):

Code: Select all

global gIncrement
local theTime
on mouseUp
  set the twelveHourTime to false
   if the hilite of btn "Radio1" is "true" then
      --      put (label of btn "everyhours" * 3600 + label of btn "everyminutes" * 60) into gIncrement
      put (label of btn "everyhours" + label of btn "everyminutes") into gIncrement --used for development
      
      if timerIncrement is not in the pendingMessages then -- don't pile up timerIncrement
         send "timerIncrement" to me in gIncrement seconds
      end if
   else
     put (label of btn "onhour" &":"& label of btn "onminutes") into theTime
      sendCommandInTime "nextLine",theTime
   end if
end mouseUp

on timerIncrement
   send "timerIncrement" to me in gIncrement seconds
   send mouseUp to btn "next"
end timerIncrement


    // theHandler: name of the command to be executed (no functions)
    // theTime: the time when to execute the command
    // assuming that useSystemDate is false
    on sendCommandInTime theHandler,theTime
      convert theTime from time to seconds
      put theTime - the seconds into theSecondsToLapse
      if theSecondsToLapse > 0 then
        send theHandler to the target in theSecondsToLapse seconds
      end if
    end sendCommandInTime

on nextLine
   send mouseUp to btn "next"
end nextLine

I guess it's correct since it works :)

keram

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 6:23 pm
by keram
Hi Mark,

I just discovered that you have replied on my last questions under wrong thread
http://ftp.runrev.com/forums/viewtopic. ... ff8#p99518

btn "Next" has this handler:

Code: Select all

global gAllLines,gCurrentLine

on mouseUp 
   if gCurrentLine >= the num of lines of gAllLines then
      exit mouseup
   end if
   
   add 1 to gCurrentLine
   put line gCurrentLine of gAllLines into fld "oneline"
   put gCurrentLine into fld "a"
    put gCurrentLine into gCurrentLine
   
end mouseUp
and handler "nextLine"

Code: Select all

on nextLine
   send mouseUp to btn "next"
end nextLine
Do I still need another button AMPM??
See my post just above.

keram

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 6:32 pm
by Mark
Hi Keram,

Somehow, your posts come from a subdomain ftp.runrev.com instead of forums.runrev.com. It seems this mixes up things completely. I'll post the post that was supposed to be posted here first and will answer to your next post in another post :-)

Mark


Hi,

You'll need another button AMPM and this line:

put (label of btn "onhour" &":"& label of btn "onminutes" && the label of btn "AMPM") into theTime

Before I post a new script, I think I should ask you what does button "Next" do and what does handler "nextLine" do exactly? If they're not too long, perhaps you should also post the handlers of the button and the nextLine handler.

Kind regards,

Mark

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 6:51 pm
by keram
Hi Mark,

Yes, there is something strange with these 2 domains...
But anyway you can find my reply here above.

keram

Re: triggering a handler at a specific time

Posted: Wed Mar 19, 2014 7:37 pm
by Mark
Hi Keram,

Try this:

Code: Select all

global gIncrement
on mouseUp
   set the twelveHourTime to true
   if the hilite of btn "Radio1" is "true" then
      // assuming that labels of buttons contain integers 0-12 resp. 1-59.
      put (label of btn "everyhours" * 3600 + label of btn "everyminutes" * 60) into gIncrement
      if timerIncrement is not in the pendingMessages then -- don't pile up timerIncrement
         send "timerIncrement" to me in gIncrement seconds
      end if
   else
      // I assume the onhour and onminutes buttons to be the same as the every* buttons
      // and you need a button "AMPM" unless you make a 24-hours version
      put (the label of btn "onhour" &":"& the label of btn "onminutes" && the label of btn "AMPM") into theTime
      sendCommandInTime "nextLine",theTime
   end if
end mouseUp

on timerIncrement
   send "timerIncrement" to me in gIncrement seconds
   send mouseUp to btn "next"
end timerIncrement

on nextLine
   send mouseUp to btn "next"
end nextLine

// theHandler: name of the command to be executed (no functions)
// theTime: the time when to execute the command
// assuming that useSystemDate is false
on sendCommandInTime theHandler,theTime
   convert theTime from time to seconds
   put theTime - the seconds into theSecondsToLapse
   if theSecondsToLapse > 0 then
      send theHandler to the target in theSecondsToLapse seconds
   end if
end sendCommandInTime
Kind regards,

Mark

Re: triggering a handler at a specific time

Posted: Thu Mar 20, 2014 1:58 am
by keram
Hi Mark,
Mark wrote: // assuming that labels of buttons contain integers 0-12 resp. 1-59.
They have integers 0-24 resp 0-59 and 'set the twelveHourTime to false' is there.
Mark wrote:// and you need a button "AMPM" unless you make a 24-hours version
Yes, that's what I have - 24-hours version, so just this part '&& the label of btn "AMPM"' of the next line goes out.

It works great!
Thanks a lot for your help! :)

keram