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!

Polling at a set interval 1

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all

Any ideas on how to set an application to start at a certaion interval e.g. every 1/2 hour (and enable it to pause in this) - timer doesn't work - only for things under a minute and I am reluctant to use the sleep API as I would rather it started every 1/2 hour than consumed resources for 1/2 an hour.

Ideas, please
 
One common trick to extend the amount of time a Timer control can wait is to create a module level variable that acts as a counter, and incrementing it every time the Timer event fires. When the counter reaches a particular value, you can do whatever you need to do.
Try this:

Create a Form named Form1 with a Timer named Timer1 on it. Set the Timer's Interval to 60000 (1 minute).
Write this code on Form1:

Private TimerCounter as long

Private Sub Form_Load()
TimerCounter = 0
End Sub

Private Sub Timer1_Timer()

'1 minute has passed
TimerCounter = TimerCounter + 1

'30 1 minute intervals have passed
If TimerCounter = 30 Then
'perform functionality here

'reset the counter to wait another 30 minutes
TimerCounter = 30
End If

End Sub

Hope this helps.

Steve
 
Steve, you are a GENIUS!! This works like a dream. Only one more thing ... do you know if it will take up a lot of memory to have the timer running in the background?
 
Othervise you could use another timerlibrary, to eliminate the need for this workaround.

Suggest you try a search for one with a long counter.

-M

Ps. I think i'ts an outrage that MS haven't changed the counter to a long yet!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top