By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

Get time event at a specific time

P: n/a
Hi!

Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

If not, is there a smooth way to accomplish this in a different way?

Best regards,
Andreas Lundgren
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Hi!

Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

If not, is there a smooth way to accomplish this in a different way?

Best regards,
Andreas Lundgren


Just put a timer control on the form and set it to fire every second.

Somewhere in the code you set your target:

Dim Target As Date
Target = "10/4/2003 8:00 PM"

And in the timer code you check for this target:

Private Sub Timer1_Timer()
If Now => Target Then
' fire the event that you need to happen at the target time
End If
End Sub
Jul 17 '05 #2

P: n/a
On Fri, 03 Oct 2003 08:57:08 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google. com...
Hi!

Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

If not, is there a smooth way to accomplish this in a different way?

Best regards,
Andreas Lundgren
Just put a timer control on the form and set it to fire every second.

Somewhere in the code you set your target:

Dim Target As Date
Target = "10/4/2003 8:00 PM"

Hmm, that could have rather different results in the UK to the same
code in the USA

Personally I would use DateSerial() and TimeSerial() to avoid such
ambiguity
And in the timer code you check for this target:

Private Sub Timer1_Timer()
If Now => Target Then
' fire the event that you need to happen at the target time
End If
End Sub


Jul 17 '05 #3

P: n/a
Probably the simplest way is to set a timer event (interval=1000) that
checks the value of Time$

' Timer object: Name="tmrTimeTrap" Interval=1000
'
Private Sub tmrTimeTrap_Timer()
If (Time$="08:00" or Time$="20:00") Then
Print "Do this thing at 8 o'clock"
End If
End Sub
Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

Jul 17 '05 #4

P: n/a
"J French" <er*****@nowhere.com> wrote in message
news:3f**************@news.btclick.com...
On Fri, 03 Oct 2003 08:57:08 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google. com...
Hi!

Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

If not, is there a smooth way to accomplish this in a different way?

Best regards,
Andreas Lundgren


Just put a timer control on the form and set it to fire every second.

Somewhere in the code you set your target:

Dim Target As Date
Target = "10/4/2003 8:00 PM"

Hmm, that could have rather different results in the UK to the same
code in the USA

Personally I would use DateSerial() and TimeSerial() to avoid such
ambiguity

And in the timer code you check for this target:

Private Sub Timer1_Timer()
If Now => Target Then
' fire the event that you need to happen at the target time
End If
End Sub


You're absolutely right.
I was merely saying you set a target to give a quick example of the timer
code which is what the poster was looking for.
Jul 17 '05 #5

P: n/a
On Fri, 03 Oct 2003 23:45:45 GMT, "Raoul Watson"
<Wa*****@IntelligenCIA.com> wrote:

<snip>

You're absolutely right.
I was merely saying you set a target to give a quick example of the timer
code which is what the poster was looking for.


Sorry, I get nervous of Dates

- the 'real' answer - compare with a target is exactly how I would do
it
Jul 17 '05 #6

P: n/a
Another possibility is to set the timer interval to the difference between
8:00 and "now". In VB.NET, you could implement a function like this:

Private Function IntervalTill(ByVal d As DateTime) As Integer

Dim TodayTickTime As DateTime = Today.Add(d.Subtract(#12:00:00 AM#))
Dim TomorrowTickTime As DateTime = TodayTickTime.AddHours(24)
Dim Difference As TimeSpan

If DateTime.op_LessThan(Now, TodayTickTime) Then
Difference = TodayTickTime.Subtract(Now)
Else
Difference = TomorrowTickTime.Subtract(Now)
End If

Return Difference.TotalMilliseconds

End Function

Then you could set your timer interval like this:

Timer1.Interval = IntervalTill(#8:00:00 PM#)

This will avoid the overhead of timer code executing once a second (and
potentially 86,399 times without doing anything). Also, if the event needs
to happen every day at the same time, the code in the timer's Tick event
could do its thing and then reset its own interval as above.

Hope this helps. =c)
CajunCoiler wrote:

Probably the simplest way is to set a timer event (interval=1000) that
checks the value of Time$

' Timer object: Name="tmrTimeTrap" Interval=1000
'
Private Sub tmrTimeTrap_Timer()
If (Time$="08:00" or Time$="20:00") Then
Print "Do this thing at 8 o'clock"
End If
End Sub
Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

Jul 17 '05 #7

P: n/a
Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
value with a mamimum value of 65535 ms, about one minute...

I was thinking and hoping that there might be an API call or upgraded
timer that could give me an event after a longer time, and by that,
let me use a function like the one that Coiler described below.

"1 to 65,535 Sets an interval (in milliseconds) that takes effect
when a Timer control's Enabled property is set to True. For example, a
value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535
milliseconds, is equivalent to just over 1 minute."

"Tony Vitonis" <no***@nowhere.com> wrote in message news:<Mv********************@comcast.com>...
Another possibility is to set the timer interval to the difference between
8:00 and "now". In VB.NET, you could implement a function like this:

Private Function IntervalTill(ByVal d As DateTime) As Integer

Dim TodayTickTime As DateTime = Today.Add(d.Subtract(#12:00:00 AM#))
Dim TomorrowTickTime As DateTime = TodayTickTime.AddHours(24)
Dim Difference As TimeSpan

If DateTime.op_LessThan(Now, TodayTickTime) Then
Difference = TodayTickTime.Subtract(Now)
Else
Difference = TomorrowTickTime.Subtract(Now)
End If

Return Difference.TotalMilliseconds

End Function

Then you could set your timer interval like this:

Timer1.Interval = IntervalTill(#8:00:00 PM#)

This will avoid the overhead of timer code executing once a second (and
potentially 86,399 times without doing anything). Also, if the event needs
to happen every day at the same time, the code in the timer's Tick event
could do its thing and then reset its own interval as above.

Hope this helps. =c)
CajunCoiler wrote:

Probably the simplest way is to set a timer event (interval=1000) that
checks the value of Time$

' Timer object: Name="tmrTimeTrap" Interval=1000
'
Private Sub tmrTimeTrap_Timer()
If (Time$="08:00" or Time$="20:00") Then
Print "Do this thing at 8 o'clock"
End If
End Sub
Is it possible to get a time event at a specific time, for instance
eight a'clock? My program is running in the background and is
minimized to the tray bar.

Jul 17 '05 #8

P: n/a
On 14 Oct 2003 02:32:09 -0700, d9****@efd.lth.se (Andreas) wrote:
Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
value with a mamimum value of 65535 ms, about one minute...

I was thinking and hoping that there might be an API call or upgraded
timer that could give me an event after a longer time, and by that,
let me use a function like the one that Coiler described below.


I think you misunderstand what he was saying

As everyone suggested, set up a Timer that fires every second, and
checks whether the system time has reached a specified forward date.
Jul 17 '05 #9

P: n/a
This link is to an MSDN library article on using timers through the API. You can
set a timer up to 4 billion milliseconds ahead, which is about 49.7 days. Not
suprisingly, I haven't tested one set that long.

http://support.microsoft.com/default...b;en-us;180736

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
value with a mamimum value of 65535 ms, about one minute...

I was thinking and hoping that there might be an API call or upgraded
timer that could give me an event after a longer time, and by that,
let me use a function like the one that Coiler described below.

"1 to 65,535 Sets an interval (in milliseconds) that takes effect
when a Timer control's Enabled property is set to True. For example, a
value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535
milliseconds, is equivalent to just over 1 minute."

"Tony Vitonis" <no***@nowhere.com> wrote in message

news:<Mv********************@comcast.com>...
Another possibility is to set the timer interval to the difference between
8:00 and "now". In VB.NET, you could implement a function like this:

Private Function IntervalTill(ByVal d As DateTime) As Integer

Dim TodayTickTime As DateTime = Today.Add(d.Subtract(#12:00:00 AM#))
Dim TomorrowTickTime As DateTime = TodayTickTime.AddHours(24)
Dim Difference As TimeSpan

If DateTime.op_LessThan(Now, TodayTickTime) Then
Difference = TodayTickTime.Subtract(Now)
Else
Difference = TomorrowTickTime.Subtract(Now)
End If

Return Difference.TotalMilliseconds

End Function

Then you could set your timer interval like this:

Timer1.Interval = IntervalTill(#8:00:00 PM#)

This will avoid the overhead of timer code executing once a second (and
potentially 86,399 times without doing anything). Also, if the event needs
to happen every day at the same time, the code in the timer's Tick event
could do its thing and then reset its own interval as above.

Hope this helps. =c)
CajunCoiler wrote:

Probably the simplest way is to set a timer event (interval=1000) that
checks the value of Time$

' Timer object: Name="tmrTimeTrap" Interval=1000
'
Private Sub tmrTimeTrap_Timer()
If (Time$="08:00" or Time$="20:00") Then
Print "Do this thing at 8 o'clock"
End If
End Sub

> Is it possible to get a time event at a specific time, for instance
> eight a'clock? My program is running in the background and is
> minimized to the tray bar.

Jul 17 '05 #10

P: n/a
Thanks!

This was what I wanted! As you can see, I'm don't like to following
standard MS coding standard, "Make the timer go of every second, and
if the computer gets slower, why not upgrade to a faster processor?".

"Steve Gerrard" <no*************@comcast.net> wrote in message news:<nY********************@comcast.com>...
This link is to an MSDN library article on using timers through the API. You can
set a timer up to 4 billion milliseconds ahead, which is about 49.7 days. Not
suprisingly, I haven't tested one set that long.

http://support.microsoft.com/default...b;en-us;180736

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Problem in VB6 (no idea about .NET) is that the Interval is a 16 byte
value with a mamimum value of 65535 ms, about one minute...

I was thinking and hoping that there might be an API call or upgraded
timer that could give me an event after a longer time, and by that,
let me use a function like the one that Coiler described below.

"1 to 65,535 Sets an interval (in milliseconds) that takes effect
when a Timer control's Enabled property is set to True. For example, a
value of 10,000 milliseconds equals 10 seconds. The maximum, 65,535
milliseconds, is equivalent to just over 1 minute."

Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.