Questions about timers

Sam K

New member
Joined
Sep 6, 2008
Messages
3
Programming Experience
1-3
Evening, Im having a bit of trouble with a home assignment from a VB class Im taking, and I was hoping someone could give me some hints on how to solve it.

The assignment is to build a small timer application that will alert the user after a certain amount of time has passed. Most of the functions have been easy enough to implement, but the assignment specifies that the user must be able to set the alarm either after X minutes or at a specific time of the day.
The 'in X minutes part' is simple enough as I can just have the user enter the desired delay (say 30 minutes), and use a system.windows.forms.timer object to raise the event when the desired amount of time has passed by. Im doing this currently and its working fine.
The specific time of the day is proving more troublesome. Im trying to use a datetimepicker control to let the user pick the desired time for the alert to go off, but Im not sure how to progress from here. Im assuming I should create a DateTime from the time entered in the datetimepicker, but I dont think I can make my timer object work with the datetime. Should I use some other object to determine when the user selected datetime matches the system time, and display the alert? Or can I somehow make the timer object work with the datetime?

Sorry if Im confusing, Im not fully comfortable working with some of these classes so my descriptions may not be the best.
 
What you need to do is use the DateTimePicker to get the desired time from the user, then have a timer set up to go off every second (Interval = 1000) then in the Timer's Tick event check the current time against the desired time, if they match turn off the timer and notify the user (or just do whatever's supposed to happen at the desired time)
 
Thanks for the help, I've set this up and it seems to be working fine except for one thing: the comparison never evaluates to true. My method currently looks like this:

Public Shared Sub isItTimeYet()

Dim isTimeToWakeup As Boolean

isTimeToWakeup = wakeupTime.Equals(DateTime.Now)
If isTimeToWakeup = True Then
eggTimer.Stop()
MessageBox.Show(wakeupMessage)

End If
End Sub


This method is called every second using the method suggested above, and the call occurs properly (I tested by having the message window pop up if the expression evaluated to false, and it popped up every second). Using breakpoints, I've checked to verify that wakeuptime (the value the user enters) is assigned properly, and that it should match DateTime.Now eventually. The datetime.now updates properly. However, the expression seems to never evaluate to true. The calling method looks like this, in case it may matter:

Public Shared Sub countingTime()
AddHandler eggTimer.Tick, AddressOf isItTimeYet
eggTimer.Interval = 1000
eggTimer.Start()
While stopRunning = False
Application.DoEvents()
End While
End Sub

I've tried everything I can come up with, although granted its more like everything I can come up with at 5am, so I wouldn't be surprised of I missed something vital. Still, its getting me kinda frustrated.
Oh, and I tried setting the timer interval to 1 in case it was comparing them in miliseconds; still didn't evaluate to true.
 
Back
Top