Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scheduled event help needed
I want to run a scheduled event on the third Tuesday of every month

How can I do this?

That's more specific than the scheduled event stuff can handle itself. You'd have to schedule it for every tuesday and somehow use a CML macro to determine if it's the third one of the money. You can easily enough get the current date info, get the current month from that. Then just start on 1 and run up through the current date, setting each of them into the time object and converting back to details, watching for tuesdays and count them.

If it is the third tuesday, return non-zero from the Start() method and that'll show up as a positive value in an If MacroEng::RunMacro() command, and you'll fall into the body of the event action.

At worst it'll take 31 rounds to count the tuesdays of that month, so you'll know in microseconds if it's to run or not, and it would only run one day a week anyway to even if see if it really needs to be invoked.
Dean Roddey
Explorans limites defectum
It would probably be easier to just add 6 to the current day and divide by 7 and see if that was equal to 3. If it is then it is the 3rd Tuesday of the month. The first Tuesday has to fall somewhere between 1 and 7. If it is on 1st the third Tuesday will be the 15 and (15+6)/7=3. If it is on the 7th than the third tuesday is the 21st and (21+6)/7=3. That isn't right you say? Well inside the action system you only get the integer of the result when dividing.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...
The last one works like an option.

After I posted I tried an event for every tuesday and then did a nested if statement
if daynumber > 14
if daynumber< 22
the do something

Much the same with no maths involved.

I will probably move towards the divide by three using the math macro that exists


Mick...I realized after posting that it probably would be easier to just use the dates outright. My brain was stuck in algorithm mode. One thing you can do to simplify it a little more is use the IsInNumericRange method under System. No fuss no muss and no need for nested If's.
It's the early bird that catches the worm, but it's the second mouse that gets the cheese...

Possibly Related Threads…
Thread Author Replies Views Last Post
  Status of Scheduled and Triggered Events gReatAutomation 4 1,466 04-21-2020, 12:58 PM
Last Post: gReatAutomation
  Scheduled Events & Variables gReatAutomation 2 1,340 06-20-2019, 01:31 PM
Last Post: gReatAutomation
  event and subsequent countdown timer question dogman 9 5,003 05-03-2018, 06:36 PM
Last Post: dogman
  Idea for a different kind of event processing mechanism Dean Roddey 0 1,573 03-20-2017, 09:29 AM
Last Post: Dean Roddey
  Best Way to Handle Wait Times within a Triggered Event kblagron 9 4,855 06-25-2016, 06:03 PM
Last Post: Dean Roddey
  Thingspeak event monitor potts.mike 5 3,520 05-09-2015, 06:11 PM
Last Post: wuench
  event scheduler ellisr63 8 4,089 04-11-2014, 02:43 PM
Last Post: ellisr63
  CQC & Event Ghost Read current state jdmevo123 3 2,783 12-05-2013, 06:49 PM
Last Post: wuench
  Request for Event Filter George M 1 1,471 01-17-2013, 01:31 PM
Last Post: Dean Roddey
  new widget, scheduled event modifier willplaice 2 2,184 01-14-2013, 01:33 PM
Last Post: willplaice

Forum Jump:

Users browsing this thread: 1 Guest(s)