Jump to content
xisto Community
BubbaBeans

Vb6 Reminder Alarm

Recommended Posts

I've looked through lots of "alarm clock" code, and I'm still having some difficulty with what I'm attempting to do. I'm hoping someone can help!I am writing a small notification program that sits in the system tray. Using a timer, once a minute I need it to check an array of dates and times. So far so easy... But I need one notification to show up an hour before the date and time, one to show up 12 hours prior to the date and time, and one notification to show up 24 hours prior. I can't seem to get it to work.For the three notifications I have an array that holds the number of minutes before the date and time that I want each notification to show. (For example, the array holds 60, 720, 1440 for 1 hour, 6 hours, and 24 hours respectively.) So the clunky code I'm trying to use to test is this: (btw, TstDatTim is a DATE that holds the Date and Time for the alarm)For n = 0 to 2 'For the 3 notices, held in array Notice()If (FormatDateTime(DateAdd("n", Notices(n), Now())) = FormatDateTime(TstDatTim)) Then ** on with the code that raises the alarmI hope you can understand my weird code. I'm sure there must be an easier and better way using DateDiff, but I'm not sure. That's why I'm here!!!

Share this post


Link to post
Share on other sites

I've looked through lots of "alarm clock" code, and I'm still having some difficulty with what I'm attempting to do. I'm hoping someone can help!
I am writing a small notification program that sits in the system tray. Using a timer, once a minute I need it to check an array of dates and times. So far so easy... But I need one notification to show up an hour before the date and time, one to show up 12 hours prior to the date and time, and one notification to show up 24 hours prior. I can't seem to get it to work.

For the three notifications I have an array that holds the number of minutes before the date and time that I want each notification to show. (For example, the array holds 60, 720, 1440 for 1 hour, 6 hours, and 24 hours respectively.) So the clunky code I'm trying to use to test is this: (btw, TstDatTim is a DATE that holds the Date and Time for the alarm)

For n = 0 to 2 'For the 3 notices, held in array Notice()
If (FormatDateTime(DateAdd("n", Notices(n), Now())) = FormatDateTime(TstDatTim)) Then ** on with the code that raises the alarm

I hope you can understand my weird code. I'm sure there must be an easier and better way using DateDiff, but I'm not sure. That's why I'm here!!!



Well... I'm moving my program to VB2008. I got tired of messing with the code to show/hide the system tray icon, bringing a form up to show alerts, etc. All of that is much easier with VB2008.

Share this post


Link to post
Share on other sites

Looking at your code, you probably don't want to do a direct comparison between your alarm datetime and your current datetime. This is because if for some reason you dont check on the exact second or minute that it is designed to trigger on then it won't be raised. It is best to check if the current time has passed the alarm time and then check the alarm off as having been triggered (to avoid repeat alerts). It depends if you are working in minutes or seconds, or even milliseconds and how often you check.

Share this post


Link to post
Share on other sites

Looking at your code, you probably don't want to do a direct comparison between your alarm datetime and your current datetime. This is because if for some reason you dont check on the exact second or minute that it is designed to trigger on then it won't be raised. It is best to check if the current time has passed the alarm time and then check the alarm off as having been triggered (to avoid repeat alerts). It depends if you are working in minutes or seconds, or even milliseconds and how often you check.

Right after I posted my update I realized that the situation you mentioned could be a problem. I rewrite the code to create a function called CheckAlarm, which returns a simple boolean. The entire function basically says:

CheckAlarm = (CDate(TestDate & " " & TestTime) <= CDate(DateAdd(DateInterval.Hour, Notifier(Notify), Now())))

 

Where the array Notifier() holds the number of hours ahead of time that I want the alarm to be raised. (Each alarm has a boolean variable attached to it that is set to false once the alarm is displayed, so that keeps multiple versions of the exact same alarm appearing over and over. I forgot to include that the first time I ran the program. Wow, was it annoying!!!)

 

 

 

The alarm itself is a balloontip that pops up and gives various information based on the alarm itself. And I have a question about that, but I'll start another thread to keep it separate.

Share this post


Link to post
Share on other sites

Cool, I'm glad you got it working. I don't know too much about balloon tips myself, I've mainly worked only with VB6 and only very little with VB.net. Good luck.

Share this post


Link to post
Share on other sites
Code neededVb6 Reminder AlarmHi BubbaBeans,Could you send me your VB code for the Alarm reminder? I tried to code it, but some how I am stuck at the early reminder before the event start.Pls help.Thank you.-question by Steve

Share this post


Link to post
Share on other sites

Code needed

Vb6 Reminder Alarm

 

Hi BubbaBeans, Could you send me your VB code for the Alarm reminder? I tried to code it, but some how I am stuck at the early reminder before the event start. Pls help. Thank you. -question by Steve


I've recoded the alarm to use a combined datetime instead of two variables. Here is the function I use to test whether the alarm should be raised:

 

PublicFunction CheckAlarm(ByVal TestDatTim AsDate, ByVal Notify AsInteger) AsBoolean 'This returns a True of False only

 

Const ChkFmt AsString = "MM/dd/yyyy HH:mm" 'The format I will be using to compare the date and times

 

CheckAlarm = (CStr(Format(CDate(DateAdd(DateInterval.Minute, Notify, Now())), ChkFmt)) >= CStr(Format(CDate(TestDatTim), ChkFmt))) 'Add Notify minutes to current date and time, then compare to the TestDatTim, and return True or False

 

EndFunction

 

 

I'm sure there is an easier way to do this, but let me walk you through everything.

 

"TestDatTim" is a Date variable that holds the date and time of the alarm that is passed to the funtion.

"Notify" is a variable that holds the number of minutes before the event that you would like to raise the alarm. (For example: Notify=15 would raise the alarm 15 minutes early, Notify=30 would raise the alarm 30 minutes early.)

 

The only reason I have a Constant in this function is to make it easier on myself. I wanted to try out some different date/time formats to see how they would affect the function. By doing it this way I didn't have to retype the new format twice.

 

All this function does it takes the current date and time (using Now() ) and adds the "Notify" number of minutes. It takes that and converts it to a string, then does the same thing to the "TestDatTim" and compares the two. If the current time plus the "Notify" number of minutes is >= the TestDatTim, the function returns as TRUE.

 

The rest of my program then deals with sending the appropriate message, playing the appropriate alert sound, and deactivating this alarm so it won't sound again.

 

And, yes, for you vb.net purists, I am using the old vb6 CStr() instead of the newer vb.net version. Sorry, I'm an old-school programmer!

 


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.