Schedule Timer

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
reillydavidson21060
Posts: 5
Joined: Fri Jan 30, 2015 10:44 am

Schedule Timer

Post by reillydavidson21060 »

I'm looking for something that will perform actions or subroutines at certain times. For instance the program would remain minimized, then at certain times those actions would start. This would help with daily routines that need to be taken care of at work or even home.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Schedule Timer

Post by Gaev »

reillydavidson21060:

You can start by reading up (the Help file) on the Timer object ... the Timer Interval is the code that would be invoked each time the specified time interval (in milliseconds) has elapsed.

You can wrap your functionality around this object. How you design it will depend on the specifics ... like how many events you want to manage, how often you want to manage an event, whether you want to hard code the event controls (good for a few events that might not change often) or build a generic (file based) control list (so frequent changes can be handled by changing file/database contents) ... etc.

After you understand the basic capabilities of the object, post your requirements here if you need further assistance.
reillydavidson21060
Posts: 5
Joined: Fri Jan 30, 2015 10:44 am

Re: Schedule Timer

Post by reillydavidson21060 »

That won't work, I'm sure it could ultimately but this is something that will be open at all times, 24 hours a day, and I would like it to have it start actions are certain times of the day...

Example:

8:00:00 AM would start a subroutine
8:15:00 AM would start a different subroutine
etc... etc... etc...
4:45:00 PM would start the original (1st) subroutine

Something like that.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Schedule Timer

Post by Gaev »

reillydavidson21060:

When you start your program, you build an array of events (from lines in a Text File) ... if the pub is meant to run days/weeks on end without restarting, you make one of the events (say at 12:01 AM) to reload the array.

In your Timer object's Timer Interval section, you would access the earliest array item ... and check its scheduled time against the current time ... if it has passed, you do a GoSub for that event (and remove the array item so as not to invoke it again) ... if the subroutine was going to take a long time to process, you might consider running it as another pub/exe.

Depending on the accuracy of the required start of the scheduled task, you set your Timer Interval to a few seconds or one or more minutes.

Care to elaborate on why this would NOT work ?
reillydavidson21060
Posts: 5
Joined: Fri Jan 30, 2015 10:44 am

Re: Schedule Timer

Post by reillydavidson21060 »

I'm having a hard time following, how would I make one of the events reload the array if I cannot base a command off of time.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: Schedule Timer

Post by Gaev »

reillydavidson21060:
I'm having a hard time following, how would I make one of the events reload the array if I cannot base a command off of time.
1) Let us say that the tasks are no closer than 15 minutes apart ... so set the TimerInterval to something less than 15 minutes e.g. 10 minutes or 1 minute or 10 seconds (if precision of start time is that important).

2) On Startup ... check the first line of ScheduleToday.txt for a (Today is) date ... if it is the same as the current date 9indicating that you are just restarting the pub in the middle of the day), use it as it is ... otherwise, copy the contents of ScheduleTemplate.txt to ScheduleToday.txt ... making sure that the first line of ScheduleToday.txt has today's date.

Then do ...

TimerStart "myScheduleTimer"

3) At each triggered time interval, your code would read the entries (lines of text) from ScheduleToday.txt ... for each entry whose scheduled time is less than the current time (meaning that it needs to be scheduled) ...

- invoke a GoSub ... the subroutine name would be stored as part of the entry
- remove the entry from the ScheduleToday.txt file


Note: Since Global variables [Hour] and [Minute] are conveniently available in Neobook, you might make your entries look like ..

8,0,GoodMorning
8,15,makeCoffee
11,30,mySubRoutineFor1130
...
23,0,BackupFiles
23,45,GoodnightRoutine

... then you can compare [Hour]*60 + [Minute] with [entryParam1]*60 + [entryParam2] ... if needed to be scheduled, do ...

GoSub "[entryParam3]"
reillydavidson21060
Posts: 5
Joined: Fri Jan 30, 2015 10:44 am

Re: Schedule Timer

Post by reillydavidson21060 »

Image

I think I understand, I'll tinker around following what you wrote and let you know how it goes.
Locked