Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to make a Schedule/Agenda (Trigger events)?

Status
Not open for further replies.

Roland1980

Programmer
Nov 7, 2003
6
NL
Hi,

At the moment I am designing an Personal Assistant API. (Borland Builder 6)

Now I want to implement a Schedule/Agenda in it.


Of course there are several ways to trigger an event like a Birthday or a
Appointment etc.

Now I want to know what will be the best way to do this?

-Read everything from 1 large ('Database') file every minute?
-Make a 'trigger-file' (or array)(that is checked every min.) and only read
from the 'Database' when triggered?
-..?

And how should you handle recurring events? (adding en deleting)

Does anybody have/know an example/a tutorial or maybe some useful code(with
explanation)/links?


Thx in advance, very appreciated!

Best regards, Roland(BE).
 
I would use a function that checked the agenda at every event. If you has a lot of events the check every minute would mean unnessesary load on the PC.

This check should also be done for every entry that's added or deleted.

The trigger time i use to calculate by multiplying Year, Month, Date, Hour, Minute with suitable factors and adding it all together, making an "almost" linear timeline. This help me sort the tabel esily. The "almost" is that some months has less than 31 days.

So:
TimeTrig = (Year * 12 * 31 * 24 * 60) + (Month * 31 * 24 * 60) + (Date * 24 * 60) + (Hour * 60) + Minute;
or the simple way:
LONG TimeTrig = (Year * 535680L) + (Month * 44640L) + (Date * 1440L) + (Hour * 60L) + (LONG)Minute;

Totte
 
Hi Totte,

Thanks for your reaction.

I've been thinking and reading a lot and my idea is to set a timer that runs a function every minute;

That function checks the 1st upcomming Event (compares the current time (day/month/year/hour/minute) to the 1e upcomming Event's time.

When that Event is now(), the function reads the entire Event-list for the next upcomming Event.

Do you, or other people of course, think this is a good idea?

Roland.
 
I would say yes, there might be a event waiting for a certain TOD (Time Of Day) but to check if the time is up and only WHEN it's so check for NEXT is good, gives the least CPU-load.

Of course, the TOD-event would decrease it further but wouldn't it be just a trifel?.....i think so.

I actually uses that approach (once-a-minute) on some products we manufactures and it work like a charm.

Totte
Hardware level is my game.
 
Ok Totte,

Thanks again for your Reply now.

I'm going to work that idea out and maybe work to a TOD-event instead of once-every-minute, but if the load is of the function that doesn't seems to be make that much of a difference.

Now working on the problem of notifications a few days before the event plus recurring events.

Regards, Roland.
 
I have an idea about that, I don't know what you think

You can put a mark on the (year, month, day or hour) that has an event, this way it will works like a filter, and you will avoid reading all the array or file every minute, just the (year, month, day or hour) that has the mark

--- LastCyborg ---
 
My 2c:

You have a Scheduler... Then, at a certain TOD (Say 12:00 am) and the program startup, you read all the events for *that* day into an array. Then if the DB changes you redo this part. Then on your timer you just check today's events.

If it is like outlook, where you can put a 'reminder', you just have to read 'reminder' times and 'task' times into the array, and check every minute (or now with only a small array to check, you can decrease the timer's interval)

Remember to check if the day is still the same on every timer, because some ppl change the date to test etc. Then reread the whole array again if the date/time changed.

o__
,_.>/ _
(_)_\(_)_______
..speed is good
 
Thanks Canderel & lastcyborg for your reactions!

It was a good idea to check the Events in 1 day Canderel. That can't be thát big.


What I now have done;
1.Program starts and reads Today-Events-List.
(Every time something changes, it reads Today-List again.)

2.Timer that runs a function every minute;

That function checks the 1st upcomming Event (compares the current time (day/month/year/hour/minute) to the 1e upcomming Event's time.

(It also checks for Date-changes and ifso, reads Today-List again etc.)

3.When that Event is now(), the function reads the Today-list for the next upcomming Event.


But now another thing with this:

1.I have for example 4 Events in 1 Today-List;
(in this EU Date-state)
[green]12-04-2004 00:00:00
12-04-2004 10:10:10
12-04-2004 21:00:00
12-04-2004 23:59:59[/green]

2.Notification before an event is 1 hour.

3.What is the easiest/best way to check which is 1st?

This is what I've got;
[green][tt]TDateTime EventTime,SubTractTime,ResultTime;
EventTime = TDateTime("12-04-04 21:00");

SubTractTime = TDateTime(1,0,0,0);
// 7 days like this? : SubTractTime = TDate(7);

ResultTime = EventTime - SubTractTime;[/tt][/green]


Roland.
 
HI,
if i hope i got what you tring to do.
i did an Schedule application.
insted of reading the an event file every time i read it once on start up and setup system timers (not a TTimer) for each of them. it doesn't load the system to much.
there is a callback function for the timers.
each of the timer have a uniqe ID when created so when the callback jump you just check who did it and react with the proper response.

:( --> this application was lost but i if you need more help i try and find something....

Tid
 
Code:
12-04-2004 23:00:00   // event 1
12-04-2004 23:59:59   // event 2

If I understand correctly, you want to know how to make sure that event 2 shows it's reminder before event 1 starts?

What I'd do is in my 'eventsfortoday' list, I'd have my reminders as events too (just hidden).

The user sees
Code:
12-04-2004 23:00:00   // with 15m reminder
12-04-2004 23:59:59   // with 1h reminder

The program sees
Code:
12-04-2004 22:45:00   // Do Reminder for event 1
12-04-2004 22:59:00   // Do Reminder for event 2 (truncing seconds because timer is 1m)
12-04-2004 23:00:00   // Do event 1
12-04-2004 23:59:59   // Do event 2

All you have to do is:

TDateTime EventTime, ReminderTime, ReminderEvent;
ReminderEvent = EventTime - ReminderTime;

Although you'd probably have a Class TEvent (or something) So it would look more like
Code:
TEvent Reminder;
Reminder->Time = Events[CurrentEvent]->Time - Events[CurrentEvent]->ReminderTime;
Reminder->ReminderTime = 0;
Reminder->IsReminder = true;  // Doesn't get displayed
Events->Add(Reminder);

So in theory you can have a reminder to show a reminder ad infinitum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top