Use Function 'DoneRecently' to Schedule Tasks - October 2001

A common news group question goes something like:

The VB timer's interval is limited to about one second (65,535 milliseconds). How do I run an application that wakes up twice a day to perform a scheduled function?

Last year I wrote a function I call 'DoneRecently' which uses a duration and a last done time. It returns True only when the last done date/time plus the duration is greater than the current time. You could use this function to write a routine that 'wakes-up' every so often and performs some scheduled task. So the function 'DoneRecently' becomes the tip-of-the-month.

The Demo

I wrote a demo program to demonstrate the use of 'DoneRecently'. A screen shot of the VB6 demo:

'DoneRecently' Returns 'True'

The demo's progress bar moves until 'full' then restarts. The restart is caused when the number of 'seconds' elapses, in this case 180 seconds [3 minutes - about 2 minutes longer than possible with a VB timer]. A timer with a one second interval is used to increment the progress bar. A call is made to 'DoneRecently' in the timer event. If not done recently then the process is started again. You can click the 'Pause' button to disable the timer. When you 'Continue' the progress bar will jump because some significant time has elapsed even thought the timer was disabled. When the process has not been done recently the form's back color is changed to 'green', for example:

'DoneRecently' Returns 'False'. Perform the 'scheduled' task.
In this case turn the back color to 'green'.

Calling Function DoneRecently

Private mfDuration As Double
Private mdLastDone As Date

 mfDuration = 3 * 60 'some seconds

If DoneRecently(mfDuration, mdLastDone) Then
    Me.BackColor = vb3DFace
Else 'not done recently, do scheduled task
    Me.BackColor = RGB(0, 255 * 0.75, 0) 'green
End If

The Demo Program Uses These Modules

Module - Click for More Info Description Used in the Demo To
modDoneRecently.bas The 'DoneRecently' function.
Include this module in your application.
Run the demo.
modConnectToWebSite.bas Connect to a web site Show this info when Help/Info is
selected from the demo.

Download VB 6 Source Code

Click here to download the VB 6 source code [6k]

Previous Tip   Tip Index   Next Tip    First Tip


Updated 2001/10/30