Click to See Complete Forum and Search --> : Pausing the Timer
sid2030
May 21st, 2001, 03:22 PM
Hello All,
I need some serious help. I have an application in which I need to pause the timer for sometime and again resume it from where it left.While the timer is paused ,I need to activate another timer ,which would be paused after some interval so that the original timer can be unpaused.This process goes should go on for some time.
Please let me know if its possible,and if possible please provide a code.I'd be really grateful.
Thanks,
sid
yellowTIGER
May 21st, 2001, 03:48 PM
Well to pause a timer all you have to do is:
Timer.enabled = False
your code could look something like this:
Dim X as integer
X = X + 1
If x = 20 then
Timer.Enabled = false
Timer2.Enabled = true
End if
I hope this is what you needed to know...
--yellowTIGER--
Kdev
May 21st, 2001, 04:11 PM
I'm not sure if I understand you correctly or not but are you saying that if you have a timer set to go off every 5 minutes and it happens to be at 2 minutes into its cycle you want to be able to pause it until some later time and then resume it so that the current cycle has only 3 minutes left?
Or are you saying that you would like to have one timer inactive while the other is active and vice versa?
If the former than you could set up a global time variable that you set at the moment you would like to pause such a timer. Then when the timer event fires you first check if this variable is set to something if so then you get the current time take the difference and store this as your pause time. Then when you unpause the timer you set the timer interval to this stored time to finish the current cycle then reset the interval to the regular time after that cycle.
private tTimePause as time
private fTimeDiff as single
private bResetTime as boolean
private Sub Form_Load()
tTimePause = "january 1, 1900"
End Sub
private Sub Timer1_Timer()
If tTimePause = "january 1, 1900" then
If bResetTime then
bResetTime = false
Timer1.Interval = 15000
End If
MsgBox "Timer 1 Fired"
else
fTimeDiff = Now - tTimePause
Timer1.Enabled = false
End If
End Sub
private Sub Timer2_Timer()
MsgBox "Timer 2 Fired"
End Sub
private Sub Command1_Click()
If Timer2.Enabled = false then
tTimePause = Now
Timer2.Enabled = true
else
Timer1.Interval = fTimeDiff * 86400000
tTimePause = "january 1, 1900"
bResetTime = true
Timer1.Enabled = true
Timer2.Enabled = false
End If
End Sub
This is a crude example but it works though I'm not too certain on the accuracy considering that timers are in milliseconds but this may only be accurate to the nearest second.
If the latter is what you want then you can just disable one timer and enable the other one like this:
private Sub Command1_Click()
Timer1.enabled = false
Timer2.enabled = true
End Sub
private Sub Timer2_Timer()
if hour(now) > 10 then
Timer2.enabled = false
Timer1.enabled = true
end if
End Sub
-K
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.