Not a Member Yet,
Click here to Register
How do you like the new design?
It's cool, great job
[tally: 70%] 70%
It's okay
[tally: 20%] 20%
Its OK but I liked the old layout better
[tally: 0%] 0%
Please bring the old one back
[tally: 10%] 10%

votes: 10

ID: 289
Viewed: 2584
Added: Jul 26, 2002
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo

User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

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 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.

Highlight all by clicking in box

Highlight All
Private Sub Timer1_Timer()
Dim BigInterval As Byte
Static timeSeconds As Byte
Static timeMinutes As Byte
Static timeHours As Byte
Static timeDays As Byte
timeSeconds = timeSeconds + 1
If timeSeconds >= 60 Then
timeSeconds = 0
timeMinutes = timeMinutes + 1
End If
If timeMinutes >= 60 Then
timeMinutes = 0
timeHours = timeHours + 1
End If
If timeHours >= 24 Then
timeHours = 0
timeDays = timeDays + 1
End If
If timeDays >= 30 Then
timeDays = 0
End If

'use the variable below to change it to your required interval.
'NOTE: seconds<60, minutes<60, hours<24, days<30

'remove comment from the line below to suit your unit of interval
' If timeSeconds Mod BigInterval = 0 And timeSeconds <> 0 Then
If timeMinutes Mod BigInterval = 0 And timeMinutes <> 0 And
timeSeconds = 0 Then DoIt
' If timeHours Mod BigInterval = 0 And timeHours <> 0 And
timeSeconds = 0 And timeMinutes=0 Then DoIt
' If timeDays Mod BigInterval = 0 And timeDays <> 0 And
timeSeconds = 0 And timeMinutes=0 And timeHours=0 Then DoIt

End Sub

Private Sub DoIt
'Add all recurring events here
msgbox "Job Executed at " & Time
End Sub

No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.

Replying to a Comment...

Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 All Rights Reserved. Conditions