473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 6115

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark P | last post by:
I've written a class IntervalSet which is meant to contain intervals (a,b) on the x-axis and which supports insertion, deletion, and various types of range queries. Now I'd like to templatize this...
2
by: silly | last post by:
/*Thanks again to thos who helped with my 'more hand written integer pow() functions (LONG POST)' query. I needed to write a function to write out integers and after looking at some stuff on...
18
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep...
1
by: Ed Smith | last post by:
The Postgres INTERVAL literal is not compliant with the ANSI 2003 SQL Spec. Here's the Postgres way: # select INTERVAL '45 DAY'; interval ---------- 45 days (1 row) The spec. says
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the...
10
by: hazz | last post by:
Is it possible to have the timer interval in a window's service be derived from an app.config setting? When I implemented one a while back I was forced to hard code the value because it wasn't...
5
by: luanhoxung | last post by:
hi all!! i face to a new trouble. in my form, i have a textbox(unbound) that informs details of product when i choose the value of combo box(IDPro). it is ok when i choose the first value of...
0
by: rsine | last post by:
I have created my first windows service and have found that it fails when I initially start it but when I immediately try to restart the service it starts. What could be causing this behavior? I...
4
by: parag_paul | last post by:
hi All I understand the need for long long , but what is the purpose of long as a data type separately. Just makes the language intimidating to start with, when you have to deal with so many data...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.