469,338 Members | 8,430 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,338 developers. It's quick & easy.

Require long interval

I have a Reminder feature that I am building into a VB 6.0 program that will
(when enabled) remind the user to perform some action. I have a slider
where the person can select for the reminder to come up anywhere from 1
minute to 60 minutes.

I wanted to use a Timer but found that it allows 64K milliseconds (just over
a minute) as the maximum interval. Am I going to have to come up with a
complicated math routine just to handle adding X number of minutes to Now.
I have never used the MOD function - would that help me out?

I was thinking of using a one minute timer with the following train of
logic:

m = Minutes(Now)
r = frequency of reminder (in minutes)
n = m + r
every minute increment m by 1
if m = n then popup reminder notice

In my mind, this is not the prettiest way to accomplish the task, but I
would not have to worry about the minute value rolling (59 rolling over to
00). Is there a routine that is "more logical" to do this?

BTW, I am using the 24hr clock (not am/pm).

Tom
Jul 17 '05 #1
14 5949

"Kiteman (Canada)" <NO************@shaw.ca> wrote in message
news:Fhyvb.454214$9l5.180694@pd7tw2no...
I have a Reminder feature that I am building into a VB 6.0 program that will (when enabled) remind the user to perform some action. I have a slider where the person can select for the reminder to come up anywhere from 1 minute to 60 minutes.

I wanted to use a Timer but found that it allows 64K milliseconds (just over a minute) as the maximum interval. Am I going to have to come up with a complicated math routine just to handle adding X number of minutes to Now. I have never used the MOD function - would that help me out?

I was thinking of using a one minute timer with the following train of
logic:

m = Minutes(Now)
r = frequency of reminder (in minutes)
n = m + r
every minute increment m by 1
if m = n then popup reminder notice

In my mind, this is not the prettiest way to accomplish the task, but I would not have to worry about the minute value rolling (59 rolling over to 00). Is there a routine that is "more logical" to do this?

BTW, I am using the 24hr clock (not am/pm).

Tom


That would work, I think. However, since timers are only guaranteed to
fire after at least the interval has elapsed, but may be late if Windows
is busy with other stuff, the "classic" way to handle this sort of task
would be more like this:

'a module level variable
Dim dtAlarmTime as Date

'in the procedure that sets the alarm:
dtAlarmTime = DateAdd("n",60, Now())

'in the timer event:
If Now() > dtAlarmTime Then
Msgbox "Reminder"
'set next interval, if desired
dtAlarmTime = DateAdd("n",60, Now())
End If

This approach eliminates drift from delayed timer events, etc. You can
then set the timer interval to any amount, depending on how close you
want to come to the correct time.
Jul 17 '05 #2
Tom said:
I have a Reminder feature that I am building into a VB 6.0 program that will (when enabled) remind the user to perform some action. I have a slider where the person can select for the reminder to come up anywhere from
1 minute to 60 minutes.

Steve said: That would work, I think. However, since timers are only guaranteed to
fire after at least the interval has elapsed, but may be late if Windows
is busy with other stuff, the "classic" way to handle this sort of task
would be more like this:

'a module level variable
Dim dtAlarmTime as Date

'in the procedure that sets the alarm:
dtAlarmTime = DateAdd("n",60, Now())

'in the timer event:
If Now() > dtAlarmTime Then
Msgbox "Reminder"
'set next interval, if desired
dtAlarmTime = DateAdd("n",60, Now())
End If

This approach eliminates drift from delayed timer events, etc. You can
then set the timer interval to any amount, depending on how close you
want to come to the correct time.


Thanks very much for this quick reply Steve. I had looked at the DateAdd
function, but got stuck on the example given in the help file which shows a
Month added and I somehow convinced myself that this would not work for
minutes :-) I had a concern with a Reminder interval being added that
would roll the time over to the next day and immediately the Now() time
would be greater than the dtAlarmtime. Obviously I have to keep track of
the date as well.

Tom

Jul 17 '05 #3

"Kiteman (Canada)" <NO************@shaw.ca> wrote in message
news:VVCvb.454269$pl3.238477@pd7tw3no...
Tom said:
I have a Reminder feature that I am building into a VB 6.0 program that
will
(when enabled) remind the user to perform some action. I have a slider where the person can select for the reminder to come up anywhere
from 1 minute to 60 minutes.

Steve said:
That would work, I think. However, since timers are only guaranteed

to fire after at least the interval has elapsed, but may be late if Windows is busy with other stuff, the "classic" way to handle this sort of task would be more like this:

'a module level variable
Dim dtAlarmTime as Date

'in the procedure that sets the alarm:
dtAlarmTime = DateAdd("n",60, Now())

'in the timer event:
If Now() > dtAlarmTime Then
Msgbox "Reminder"
'set next interval, if desired
dtAlarmTime = DateAdd("n",60, Now())
End If

This approach eliminates drift from delayed timer events, etc. You can then set the timer interval to any amount, depending on how close you want to come to the correct time.


Thanks very much for this quick reply Steve. I had looked at the

DateAdd function, but got stuck on the example given in the help file which shows a Month added and I somehow convinced myself that this would not work for minutes :-) I had a concern with a Reminder interval being added that would roll the time over to the next day and immediately the Now() time would be greater than the dtAlarmtime. Obviously I have to keep track of the date as well.

Tom


You are welcome. One thing to note well with DateAdd: to add minutes,
you use the "n", since the "m" means months. So many times have I
forgotten that and gotten puzzling results...

Steve
Jul 17 '05 #4
On Fri, 21 Nov 2003 23:37:43 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:

<snip>


You are welcome. One thing to note well with DateAdd: to add minutes,
you use the "n", since the "m" means months. So many times have I
forgotten that and gotten puzzling results...

Steve


While I would use Steve's method

You could look at the API SetTimer

The interval is a Long containing milliseconds

2,000,000 seconds is quite a long time

You can find an example in the downloadable API Guide from:
www.AllAPI.net
Jul 17 '05 #5

"J French" <er*****@nowhere.com> wrote in message
news:3f***************@news.btclick.com...
On Fri, 21 Nov 2003 23:37:43 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:

<snip>


You are welcome. One thing to note well with DateAdd: to add minutes,
you use the "n", since the "m" means months. So many times have I
forgotten that and gotten puzzling results...

Steve


While I would use Steve's method

You could look at the API SetTimer

The interval is a Long containing milliseconds

2,000,000 seconds is quite a long time

You can find an example in the downloadable API Guide from:
www.AllAPI.net

That's only 33.33... minutes. Not long enough if it is restricted to 2M
seconds. Thanks anyway.

Tom

Jul 17 '05 #6

"Kiteman (Canada)" <NO************@shaw.ca> wrote in message
news:c8Kvb.459862$pl3.264655@pd7tw3no...
The interval is a Long containing milliseconds

2,000,000 seconds is quite a long time

You can find an example in the downloadable API Guide from:
www.AllAPI.net

That's only 33.33... minutes. Not long enough if it is restricted to 2M
seconds. Thanks anyway.

Tom

Better try that math again Tom... I got over 500 hours..
Jul 17 '05 #7
On Sat, 22 Nov 2003 14:11:20 GMT, "Kiteman \(Canada\)"
<NO************@shaw.ca> wrote:
<snip>
2,000,000 seconds is quite a long time

You can find an example in the downloadable API Guide from:
www.AllAPI.net

That's only 33.33... minutes. Not long enough if it is restricted to 2M
seconds. Thanks anyway.


I would not use it
- but I would check your arithmetic
33,333 minutes
555.6 hours
23 days

I think you misunderstood, it is 2 million seconds
- or 2 billion milliseconds

Personally what I would do is take a UserControl and 'roll my own'
mega-timer - from a standard Timer and a bit of internal logic.

Jul 17 '05 #8
<snip>
2,000,000 seconds is quite a long time

You can find an example in the downloadable API Guide from:
www.AllAPI.net

That's only 33.33... minutes. Not long enough if it is restricted to 2M
seconds. Thanks anyway.


I would not use it
- but I would check your arithmetic
33,333 minutes
555.6 hours
23 days

I think you misunderstood, it is 2 million seconds
- or 2 billion milliseconds

Personally what I would do is take a UserControl and 'roll my own'
mega-timer - from a standard Timer and a bit of internal logic.


Sorry I thought that it was 2,000,000 milliseconds - not seconds.

I read through the API guide and could not see a limit specified to the
interval.

I only found the following:
uElapse
Specifies the time-out value, in milliseconds.

I ended up using:
ReminderTime = DateAdd("n", ReminderScroll.Value, Now())

If ReminderTime <= Now() Then
ReminderTime = DateAdd("n", ReminderScroll.Value, Now())
' Beep
End If

and it works like a charm.

I always try looking through the VB help files first to see if there is
something built into the language that can do what I want. I am not
comfortable yet with API (outside) calls and delving through .dll and .ocx
(etc.) files. It is hard to come up with a command you need, when you
don't even know what it is called! LOL. They are not always logically
named and the VB help file sometimes doesn't always steer you in the
direction you are looking for. Maybe the paper manual is better.....gotta
open that someday :-)

Tom

Jul 17 '05 #9

"Kiteman (Canada)" <NO************@shaw.ca> wrote in message
news:IxRvb.464284$pl3.107843@pd7tw3no...
<snip>
> 2,000,000 seconds is quite a long time
>
> You can find an example in the downloadable API Guide from:
> www.AllAPI.net
>
That's only 33.33... minutes. Not long enough if it is restricted to 2Mseconds. Thanks anyway.
I would not use it
- but I would check your arithmetic
33,333 minutes
555.6 hours
23 days

I think you misunderstood, it is 2 million seconds
- or 2 billion milliseconds

Personally what I would do is take a UserControl and 'roll my own'
mega-timer - from a standard Timer and a bit of internal logic.


Sorry I thought that it was 2,000,000 milliseconds - not seconds.

I read through the API guide and could not see a limit specified to

the interval.

I only found the following:
uElapse
Specifies the time-out value, in milliseconds.

I ended up using:
ReminderTime = DateAdd("n", ReminderScroll.Value, Now())

If ReminderTime <= Now() Then
ReminderTime = DateAdd("n", ReminderScroll.Value, Now())
' Beep
End If

and it works like a charm.

I always try looking through the VB help files first to see if there is something built into the language that can do what I want. I am not
comfortable yet with API (outside) calls and delving through .dll and ..ocx (etc.) files. It is hard to come up with a command you need, when you don't even know what it is called! LOL. They are not always logically named and the VB help file sometimes doesn't always steer you in the
direction you are looking for. Maybe the paper manual is better.....gotta
open that someday :-)

Tom

The trouble with the API timers is that they either use a callback or
post a message to your app. You have to to do sub classing to catch the
message, and if you use a callback, it is on a seperate thread, and your
app will die if you do much of anything except make note of the callback
(no GUI or OS related activity allowed).

The uElapsed parameter is an unsigned long. If you could pass an
unsigned long in VB, you could in fact set a timer for 46 days. I don't
know of anyone who has, since the debugging takes a while!
Jul 17 '05 #10
On Sat, 22 Nov 2003 15:33:06 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:
<snip>

The trouble with the API timers is that they either use a callback or
post a message to your app. You have to to do sub classing to catch the
message, and if you use a callback, it is on a seperate thread, and your
app will die if you do much of anything except make note of the callback
(no GUI or OS related activity allowed).

You want to check that VERY carefully
- that information is profoundly misleading
- I'm sure it is not on another thread
Check out DispatchMessage
The uElapsed parameter is an unsigned long. If you could pass an
unsigned long in VB, you could in fact set a timer for 46 days. I don't
know of anyone who has, since the debugging takes a while!


And a machine is unlikely to be up that long ....
Jul 17 '05 #11

"J French" <er*****@nowhere.com> wrote in message
news:3f****************@news.btclick.com...
On Sat, 22 Nov 2003 15:33:06 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:
<snip>

The trouble with the API timers is that they either use a callback or
post a message to your app. You have to to do sub classing to catch themessage, and if you use a callback, it is on a seperate thread, and yourapp will die if you do much of anything except make note of the callback(no GUI or OS related activity allowed).

You want to check that VERY carefully
- that information is profoundly misleading
- I'm sure it is not on another thread
Check out DispatchMessage


I know that the callback is on another thread if the timer is the
multimedia timer. Quote from AllAPI.Net:
"The timeSetEvent function starts a specified timer event. The
multimedia timer runs in its own thread. After the event is activated,
it calls the specified callback function or sets or pulses the specified
event object."

I'm not sure about the threading if you use SetTimer instead of
TimeSetEvent. If I am ready MSDN correctly, the callback function is
called by the main app's message procedure in response to a WM_TIMER
message, which would mean it was on the main app thread. It would then
also have the same accuracy limitations of the timer control.

I have never seen an example in which the callback function does
anything except update module variables. The MSDN documentation is quite
explicit about the callback limitations for timeSetEvent, but the
SetTimer callback probably does not have these limitations.

Sorry for not being more careful in my post, but I have this lingering
impression that the timers are more trouble than they are worth.
Jul 17 '05 #12
On Sun, 23 Nov 2003 11:38:28 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:

<snip>

I know that the callback is on another thread if the timer is the
multimedia timer. Quote from AllAPI.Net:
"The timeSetEvent function starts a specified timer event. The
multimedia timer runs in its own thread. After the event is activated,
it calls the specified callback function or sets or pulses the specified
event object." I must check this out

Yes it says this in the MultiMedia Timer stuff
<quote>
Applications should not call any system-defined functions from inside
a callback function, except for PostMessage, timeGetSystemTime,
timeGetTime, timeSetEvent, timeKillEvent, midiOutShortMsg,
midiOutLongMsg, and OutputDebugString.
</quote>

Typically it is pretty opaque
- do they mean *any* Callback proc ?

On SetTimer and TimerProc Win32 Programmer's Reference says
<quote>
The TimerProc function is an application-defined callback function
that processes WM_TIMER messages.
</quote>
I'm not sure about the threading if you use SetTimer instead of
TimeSetEvent. If I am ready MSDN correctly, the callback function is
called by the main app's message procedure in response to a WM_TIMER
message, which would mean it was on the main app thread. It would then
also have the same accuracy limitations of the timer control. I also think that is the case
I have never seen an example in which the callback function does
anything except update module variables. The MSDN documentation is quite
explicit about the callback limitations for timeSetEvent, but the
SetTimer callback probably does not have these limitations. Hopefully not - otherwise I'm in for problems
Sorry for not being more careful in my post, but I have this lingering
impression that the timers are more trouble than they are worth.

No problem
- it forced me to look into the MM Timer in more detail
- very interesting - and potentially dangerous ....

To be honest, I would make a 'long delay' timer out of a normal timer
embedded in a UserControl
Jul 17 '05 #13

"J French" <er*****@nowhere.com> wrote in message
news:3f****************@news.btclick.com...
On Sun, 23 Nov 2003 11:38:28 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:

<snips>

Typically it is pretty opaque
- do they mean *any* Callback proc ?
From your answer below, I am guessing not.
but the
SetTimer callback probably does not have these limitations.

Hopefully not - otherwise I'm in for problems


Actually, I was wondering about that, and am glad to hear that you have
used it and presumably not had problems. I think I over-reacted to the
MM Timer warnings (and the crashes when I tried to use it).
To be honest, I would make a 'long delay' timer out of a normal timer
embedded in a UserControl


Much better approach to my mind as well. A 15 - 60 second interval
internal timer is not a drain on processing time, and provides
opportunities for control you just don't have with a 60 minute (or 10
day!) timer.
Jul 17 '05 #14
On Mon, 24 Nov 2003 18:55:13 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:

"J French" <er*****@nowhere.com> wrote in message
news:3f****************@news.btclick.com...
On Sun, 23 Nov 2003 11:38:28 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:

<snips>

Typically it is pretty opaque
- do they mean *any* Callback proc ?


From your answer below, I am guessing not.
but the
>SetTimer callback probably does not have these limitations.

Hopefully not - otherwise I'm in for problems


Actually, I was wondering about that, and am glad to hear that you have
used it and presumably not had problems. I think I over-reacted to the
MM Timer warnings (and the crashes when I tried to use it).
To be honest, I would make a 'long delay' timer out of a normal timer
embedded in a UserControl


Much better approach to my mind as well. A 15 - 60 second interval
internal timer is not a drain on processing time, and provides
opportunities for control you just don't have with a 60 minute (or 10
day!) timer.


I could not agree more
- one also has the oportunity to have a 'Countdown' Event as well as
an 'Elapsed' Event
Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark P | last post: by
2 posts views Thread by silly | last post: by
1 post views Thread by Ed Smith | last post: by
5 posts views Thread by luanhoxung | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.