Repeat Timer
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 130
- Joined: Fri Apr 13, 2018 1:53 pm
Repeat Timer
Dear all,
I need a simple counter to send every 30 Sec. emails (dosendmail) from a database query (dostartreading).
The think is: After 30 Sec. the counter is over and it will not repeat .
Any ideas how to repeat the counter, if currentTimerValue = 0 ?
Thanks
Stef
on declare_timer
global pTime
put 30 into pTime
put pTime into fld "fldCount"
countDownTimer pTime
end declare_timer
on countDownTimer currentTimerValue
subtract 1 from currentTimerValue
put currentTimerValue into fld "fldCount"
if currentTimerValue > 0 then
send "countDownTimer" && currentTimerValue to me in 1 sec
end if
if currentTimerValue = 0 then
dostartreading
global tRecords, tRecords2
put tRecords into field "Data"
dosendmail
end if
end countDownTimer
I need a simple counter to send every 30 Sec. emails (dosendmail) from a database query (dostartreading).
The think is: After 30 Sec. the counter is over and it will not repeat .
Any ideas how to repeat the counter, if currentTimerValue = 0 ?
Thanks
Stef
on declare_timer
global pTime
put 30 into pTime
put pTime into fld "fldCount"
countDownTimer pTime
end declare_timer
on countDownTimer currentTimerValue
subtract 1 from currentTimerValue
put currentTimerValue into fld "fldCount"
if currentTimerValue > 0 then
send "countDownTimer" && currentTimerValue to me in 1 sec
end if
if currentTimerValue = 0 then
dostartreading
global tRecords, tRecords2
put tRecords into field "Data"
dosendmail
end if
end countDownTimer
-
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Repeat Timer
Hi.
I guess you want a repeating timer? Put this in a button script:
I made the timing 1 second just so you can hear it work. I made the optionKey a way to escape, but this can be any other condition that is tested each iteration.
Because we are using "send in time", this process will run in the "background" as long as the current session is open, and whether or not LC is in front.
Craig Newman
I guess you want a repeating timer? Put this in a button script:
Code: Select all
on mouseup
startTimer
end mouseup
on startTimer
if the optionKey is down then exit to top
beep 2 --here is where you do your own stuff
send "startTimer" to me in 1 second
end startTimer
Because we are using "send in time", this process will run in the "background" as long as the current session is open, and whether or not LC is in front.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Repeat Timer
Is this what you want?
Code: Select all
if currentTimerValue = 0 then
sendEmail
send "declare_timer" to me in 0
else
send "countDownTimer" && currentTimerValue to me in 1 sec
end if
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 130
- Joined: Fri Apr 13, 2018 1:53 pm
Re: Repeat Timer
Ok... Lets explain what I need.
I need to send Emails every X Minutes. To activate this setting I have a Button (Button Start). But sometimes I need to stop this Job, for this I have another Button (Button Stop).
Here is the code for Button Start:
Here is the code for Button Stop:
So timer is working every 4 Seconds, fine. But I can not stop it with the Stop Button... And the question is... Why?
Stef
I need to send Emails every X Minutes. To activate this setting I have a Button (Button Start). But sometimes I need to stop this Job, for this I have another Button (Button Stop).
Here is the code for Button Start:
Code: Select all
on mouseUp pButtonNumber
global stopcountdown
put 0 into stopcountdown -- This is the that the if Condition is working
startTimer
end mouseUp
Code: Select all
on startTimer
beep 2 --Or sending Email
send "startTimer" to me in 4 second --Do this every 4 seconds
if stopcountdown is 1 then exit to top -- AND THIS is not working -> It comes from the other Button
end startTimer
Here is the code for Button Stop:
Code: Select all
on mouseUp pMouseButton
global stopcountdown
put 1 into stopcountdown -- THIS is to Stop the if condition, but it does not work. Why?
end mouseUp
Stef
-
- VIP Livecode Opensource Backer
- Posts: 9856
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Repeat Timer
The global is not declared in the startTimer handler.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 130
- Joined: Fri Apr 13, 2018 1:53 pm
Re: Repeat Timer
Declared, but the same issue. Stop Button is not working
Code: Select all
on startTimer
global stopcountdown
beep 2 --here is where you do your own stuff
send "startTimer" to me in 4 second
if stopcountdown is 1 then exit to top
end startTimer
Re: Repeat Timer
Hi ace,
the order of commands in not correct, check this:
Best
Klaus
the order of commands in not correct, check this:
Code: Select all
on startTimer
global stopcountdown
## !! Here! :-)
if stopcountdown = 1 then exit to top
## !!
beep 2 --here is where you do your own stuff
send "startTimer" to me in 4 second
end startTimer
Klaus
-
- Posts: 130
- Joined: Fri Apr 13, 2018 1:53 pm
Re: Repeat Timer
aaaah you are right!
Thank you Klaus, it is working now
Thank you Klaus, it is working now
-
- Posts: 130
- Joined: Fri Apr 13, 2018 1:53 pm
Re: Repeat Timer
But now it is funny. I am trying so send every 216000 my email. This is working. But I receive this email 5 times, sometimes 1 minute later.
But why? It seems that
does not stop the loop.
Code: Select all
on startTimer
global stopcountdown
if stopcountdown = 1 then exit startTimer -- to top
beep 2 --here is where you do your own stuff
send "startTimer" to me in 216000 seconds
dosendmail
end startTimer
But why? It seems that
Code: Select all
on mouseUp pMouseButton
global stopcountdown
put 1 into stopcountdown
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Repeat Timer
Hi.
Without seeing the code in handler "doSendMail", it is hard to tell.
One generic solution is to change:
This often catches situations where the "1" is skipped, ignored or irrelevant.
Craig
Without seeing the code in handler "doSendMail", it is hard to tell.
One generic solution is to change:
Code: Select all
if stopcountdown <= 1 then exit startTimer -- to top
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7258
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Repeat Timer
Sometimes the code runs so fast that you will get a backup of pending messages in the queue. To avoid that you should check if the message is already in the queue before sending another one. (This showed up in another thread here recently.)
Code: Select all
on startTimer
global stopcountdown
if stopcountdown = 1 then exit startTimer -- to top
beep 2 --here is where you do your own stuff
if "startTimer" is not in the pendingMessages then send "startTimer" to me in 216000 seconds -- CHANGED
dosendmail
end startTimer
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com