Nov 21, 2009

Vb6 Reminder Alarm

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > VB Programming

Vb6 Reminder Alarm

BubbaBeans
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!!!

 

 

 


Comment/Reply (w/o sign-up)

BubbaBeans
QUOTE (BubbaBeans @ Apr 13 2009, 02:54 PM) *
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.

 

 

 


Comment/Reply (w/o sign-up)

rogerthecamel
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.

Comment/Reply (w/o sign-up)

BubbaBeans
QUOTE (rogerthecamel @ Apr 17 2009, 01:17 AM) *
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.

Comment/Reply (w/o sign-up)

rogerthecamel
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.

Comment/Reply (w/o sign-up)

(G)Steve
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

Comment/Reply (w/o sign-up)

BubbaBeans
QUOTE ((G)Steve @ Sep 19 2009, 02:22 AM) *
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:

[/size]Public Function CheckAlarm(ByVal TestDatTim As Date, ByVal Notify As Integer) As Boolean 'This returns a True of False only

Const ChkFmt As String = "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

[size="2"]End
Function


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!


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Vb6 Reminder Alarm


    Looking for Vb6, Reminder, Alarm

Searching Video's for Vb6, Reminder, Alarm
See Also,
advertisement


Vb6 Reminder Alarm

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com