Overcome timer limitations
Saurabh Kumar
We have received a lot of feedback about the tip of hacking down to seconds. We plan to publish some of that feedback in the near future. But now, undeterred by the fact that some readers have taken us to task, we present this tip, submitted by reader Saurabh Kumar, that deals with timing large intervals.
A common complaint of VB programmers is the limitation of the built-in Timer control, which allows intervals only about as big as a minute. Here is a technique that I use very effectively to have intervals ranging from 1 second to as big as you wish. You can now make your software run scheduled code every 15 minutes, every 10 hours, every 2 months, whatever!
I have provided the code, which must be placed into the 'General' 'Declarations' procedure, below. You should set the interval of the Timer to 1000, so this code is executed every second.
Now just place all the code you wish to be executed repeatedly, in a procedure named 'DoIt'.
You are ready. Notice that at the end of the Timer event, this
To continue reading for free, register below or login
To read more you must become a member of SearchWinDevelopment.com
');
// -->

code will execute the 'DoIt' procedure every 5 minutes. You can change it easily to suit your requirement. In this line, you can use 'timeSeconds' for interval in seconds (<60), 'timeHours' for interval in hours (<24) etc.
I have also made a sample application to demonstrate how to use this code easily in your program. Use it to do automated tasks on your server, send mails, do unattended database maintenance jobs etc.
Did you like this tip? Do you have one of your own? Drop us a line.
Related Book
Advanced Visual Basic 6: Power Techniques for Everyday Programs
Author : Matthew Curland
Publisher : Addison Wesley
Published : Jul 2000
Summary :
In Advanced Visual Basic 6, leading Visual Basic expert Matthew Curland demonstrates powerhouse techniques programmers can use to write high-performance, robust, and reusable VB code. Readers learn how to leverage the close relationships between VB, COM, and OLE Automation, extending the envelope of VB's capabilities and building high-quality, object-based systems.