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.
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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.