Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hourly Query

Status
Not open for further replies.

Skinsella

Programmer
Feb 20, 2001
23
GB
Is there some simple code I could use to run a piece of code every hour? As far as I can see the timer function only goes up to 1 minute. If the code ran every minute it would slow my application down. Any help would be appeciated.

Regards,
Simon.
 
For a 1-hour interval, I would use a System Timer, which can be accessed by using the SetTimer API. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The SetTimer API sounds like my best option, do you know of any links that can give me some details on how to use it?
 
Sure...(tappety tappety)...you'll find examples of both the static counter and the SetTimer solutions in the following thread: thread222-356731
 
Thanks for that strongm. I did try a word search, but didn't try hard enough by the looks of it. Thank you all for your time.

Regrads,
Simon.
 
I have learned, as many have you have witnessed, a lot about the pitfalls of timers. A more reliable way than 60 iterations of a one minute timer is to query the system clock every minute. Then you don't have to worry about the fact that VB timers are far from exact because of execution time, event queue delays, system clock precision, etc.. All these little things could add up over 60 iterations.

This might be easier for you than using the API. Just call the function Time. On the other hand strongm's solution will use fewer system resources, if those are in short supply.
 
>VB timers are far from exact because of execution time, event queue delays, system clock precision, etc..

Well, as we've tried to explain in this forum before, this is not an accurate summary. The Timer control is predominantly limited by the granularity of the system timer (which differs on different the different MS OSs) combined with the fact that the WM_TIMER message that it sends is a low-priority message. Execution time, event queue delays, etc. are merely artifacts of this issue, and only become particularly important if you are trying to receive and respond to events close to the system clock granularity.

Under those circumstances, using a counter to count every minute (an interval of 60000, compared to a granularity of approx 54 on W95/98/Me or 10 under NT4/2000/XP) will not lead to any noticeable innaccuracy - unless you are really concerned with a few hundreths of a second.

It should also be noted that the Time function (and the timers that hide beneath SetSytem timer) suffer more-or-less the same limitations as the Timer control.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top