How to pause a timer control and restart it from pause for remaining interval? 
Author Message
 How to pause a timer control and restart it from pause for remaining interval?

I'm wondering how I can set a timer control to 60 seconds. Then pause the
timer in any given moment before the 60 seconds interval is up. Run some
other code while my timer is in pause. Then come back to un-pause the timer
to finish the remaining amount of time until it reach 60 seconds.

I'm writing an program to control product line process with belt. Lets say I
expect my product to take 60 seconds to get from start to end of a belt.
When the product reachs the end of belt at 60 second I'll need to do
something like sound an alarm. If I recieve a signal that the belt stopped
at 20 seconds from product starting point, I'll need to pause the timer at
that moment and restart the timer to finish the remaining 40 seconds when my
belt start moving again. Then I'll sound an alarm when my product actually
reached end of belt.

How can I best achieve this with a single timer? or do I need multiple timer
to do so? maybe variable to hold the amount of time passed when timer is
paused?
Any comment or suggestion appricated.
Thanks
Bill



Wed, 08 Dec 2004 12:21:55 GMT  
 How to pause a timer control and restart it from pause for remaining interval?
Put a static counter inside the timer event, and a flag outside the timer which can be toggled to turn the counter on and off.  Assuming you have a Timer1 module that is Enabled and set to an arbitrary Interval (the smaller, the greater the precision), try something like:

Option Explicit
Private Const ProductControlLineDurration As Long = 60
Dim TimerRunning As Boolean

Private Sub Command1_Click()
  TimerRunning = Not TimerRunning
  Debug.Print "Timer enabled: " & TimerRunning
End Sub

Private Sub Timer1_Timer()
  Static Counts As Long

  Counts = Counts + Abs(CLng(TimerRunning))
  If Counts = (1000& \ Timer1.Interval) * ProductControlLineDurration Then
    MsgBox "Alert:  Timer expired"
    Counts = 0
  End If
End Sub

If you need more control of time tweaking and stuff, it might be recommendable to remove the Counts variable from the Timer1 scope and put it at the module level, with TimerRunning.

Howard Henry Schlunder

Quote:

> I'm wondering how I can set a timer control to 60 seconds. Then pause the
> timer in any given moment before the 60 seconds interval is up. Run some
> other code while my timer is in pause. Then come back to un-pause the timer
> to finish the remaining amount of time until it reach 60 seconds.

> I'm writing an program to control product line process with belt. Lets say I
> expect my product to take 60 seconds to get from start to end of a belt.
> When the product reachs the end of belt at 60 second I'll need to do
> something like sound an alarm. If I recieve a signal that the belt stopped
> at 20 seconds from product starting point, I'll need to pause the timer at
> that moment and restart the timer to finish the remaining 40 seconds when my
> belt start moving again. Then I'll sound an alarm when my product actually
> reached end of belt.

> How can I best achieve this with a single timer? or do I need multiple timer
> to do so? maybe variable to hold the amount of time passed when timer is
> paused?
> Any comment or suggestion appricated.
> Thanks
> Bill



Wed, 08 Dec 2004 14:04:20 GMT  
 How to pause a timer control and restart it from pause for remaining interval?

Quote:

> I'm wondering how I can set a timer control to 60 seconds. Then pause the
> timer in any given moment before the 60 seconds interval is up. Run some
> other code while my timer is in pause. Then come back to un-pause the timer
> to finish the remaining amount of time until it reach 60 seconds.

> I'm writing an program to control product line process with belt. Lets say I
> expect my product to take 60 seconds to get from start to end of a belt.
> When the product reachs the end of belt at 60 second I'll need to do
> something like sound an alarm. If I recieve a signal that the belt stopped
> at 20 seconds from product starting point, I'll need to pause the timer at
> that moment and restart the timer to finish the remaining 40 seconds when my
> belt start moving again. Then I'll sound an alarm when my product actually
> reached end of belt.

> How can I best achieve this with a single timer? or do I need multiple timer
> to do so? maybe variable to hold the amount of time passed when timer is
> paused?
> Any comment or suggestion appricated.
> Thanks
> Bill

Looks like you need a detector at the end of the belt.
(Light beam, magnetic sensor... )
Then you wouldn't need any timer.
I take it you  have someone along the belt who pushes a button to
stop it (inspect object, fix it, whatever..), then restarts the belt again.
Lateral thinking .....
have a look at using the comms control instead
Argusy


Wed, 08 Dec 2004 21:07:56 GMT  
 How to pause a timer control and restart it from pause for remaining interval?
At the same time you enable the timer for it's 60 sec countdown save the
present time in a date variable.Then when you get an interruption, save the
time it happened , subtract the two times and then subtract that result from
60 and save that value as "remainingTime" , when you are ready to reenabled
the timer just first reset the timer interval to the remainingTime value.

Ron


Quote:
> I'm wondering how I can set a timer control to 60 seconds. Then pause the
> timer in any given moment before the 60 seconds interval is up. Run some
> other code while my timer is in pause. Then come back to un-pause the
timer
> to finish the remaining amount of time until it reach 60 seconds.

> I'm writing an program to control product line process with belt. Lets say
I
> expect my product to take 60 seconds to get from start to end of a belt.
> When the product reachs the end of belt at 60 second I'll need to do
> something like sound an alarm. If I recieve a signal that the belt stopped
> at 20 seconds from product starting point, I'll need to pause the timer at
> that moment and restart the timer to finish the remaining 40 seconds when
my
> belt start moving again. Then I'll sound an alarm when my product actually
> reached end of belt.

> How can I best achieve this with a single timer? or do I need multiple
timer
> to do so? maybe variable to hold the amount of time passed when timer is
> paused?
> Any comment or suggestion appricated.
> Thanks
> Bill



Thu, 09 Dec 2004 00:16:31 GMT  
 How to pause a timer control and restart it from pause for remaining interval?
Hi,

In VB 6 and earlier,

Timer1.Enabled = False
Timer1.Enabled = 0
'then, some time later:
Timer1.Interval = 60000
Time1.Enabled = True

The VB.NET timer does not allow you to set the Interval to zero, so use some
other value (it is necessary to change the interval property to completely
"cancel" the next timer event).

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Thu, 09 Dec 2004 01:15:38 GMT  
 How to pause a timer control and restart it from pause for remaining interval?


Quote:


> > I'm wondering how I can set a timer control to 60 seconds. Then pause
the
> > timer in any given moment before the 60 seconds interval is up. Run some
> > other code while my timer is in pause. Then come back to un-pause the
timer
> > to finish the remaining amount of time until it reach 60 seconds.

> > I'm writing an program to control product line process with belt. Lets
say I
> > expect my product to take 60 seconds to get from start to end of a belt.
> > When the product reachs the end of belt at 60 second I'll need to do
> > something like sound an alarm. If I recieve a signal that the belt
stopped
> > at 20 seconds from product starting point, I'll need to pause the timer
at
> > that moment and restart the timer to finish the remaining 40 seconds
when my
> > belt start moving again. Then I'll sound an alarm when my product
actually
> > reached end of belt.

> > How can I best achieve this with a single timer? or do I need multiple
timer
> > to do so? maybe variable to hold the amount of time passed when timer is
> > paused?
> > Any comment or suggestion appricated.
> > Thanks
> > Bill

> Looks like you need a detector at the end of the belt.
> (Light beam, magnetic sensor... )
> Then you wouldn't need any timer.
> I take it you  have someone along the belt who pushes a button to
> stop it (inspect object, fix it, whatever..), then restarts the belt
again.
> Lateral thinking .....
> have a look at using the comms control instead
> Argusy

Actually I though of using some type of detector before, but it would be
hard to determin when the very last piece of part of belt get to the end
because parts laying on the belt could have maybe up to a foot length of gap
in between. So a sensor will give false signal when it encounters a gap.

Bill



Fri, 10 Dec 2004 07:55:53 GMT  
 How to pause a timer control and restart it from pause for remaining interval?
Thanks for the suggestion, I'll try this out. Since I've got about 10 belts
in a contineous fasion, I'll have to count down the required timer for each
belt and start count down one belt after the other.

Bill


Quote:
> At the same time you enable the timer for it's 60 sec countdown save the
> present time in a date variable.Then when you get an interruption, save
the
> time it happened , subtract the two times and then subtract that result
from
> 60 and save that value as "remainingTime" , when you are ready to
reenabled
> the timer just first reset the timer interval to the remainingTime value.

> Ron



> > I'm wondering how I can set a timer control to 60 seconds. Then pause
the
> > timer in any given moment before the 60 seconds interval is up. Run some
> > other code while my timer is in pause. Then come back to un-pause the
> timer
> > to finish the remaining amount of time until it reach 60 seconds.

> > I'm writing an program to control product line process with belt. Lets
say
> I
> > expect my product to take 60 seconds to get from start to end of a belt.
> > When the product reachs the end of belt at 60 second I'll need to do
> > something like sound an alarm. If I recieve a signal that the belt
stopped
> > at 20 seconds from product starting point, I'll need to pause the timer
at
> > that moment and restart the timer to finish the remaining 40 seconds
when
> my
> > belt start moving again. Then I'll sound an alarm when my product
actually
> > reached end of belt.

> > How can I best achieve this with a single timer? or do I need multiple
> timer
> > to do so? maybe variable to hold the amount of time passed when timer is
> > paused?
> > Any comment or suggestion appricated.
> > Thanks
> > Bill



Fri, 10 Dec 2004 08:21:10 GMT  
 How to pause a timer control and restart it from pause for remaining interval?



Put a static counter inside the timer event, and a flag outside the timer
which can be toggled to turn the counter on and off.  Assuming you have a
Timer1 module that is Enabled and set to an arbitrary Interval (the smaller,
the greater the precision), try something like:

Option Explicit
Private Const ProductControlLineDurration As Long = 60
Dim TimerRunning As Boolean

Private Sub Command1_Click()
  TimerRunning = Not TimerRunning
  Debug.Print "Timer enabled: " & TimerRunning
End Sub

Private Sub Timer1_Timer()
  Static Counts As Long

  Counts = Counts + Abs(CLng(TimerRunning))
  If Counts = (1000& \ Timer1.Interval) * ProductControlLineDurration Then

** Are you assuming a timer interval of 1000 ms here?

    MsgBox "Alert:  Timer expired"
    Counts = 0
  End If
End Sub

If you need more control of time tweaking and stuff, it might be
recommendable to remove the Counts variable from the Timer1 scope and put it
at the module level, with TimerRunning.

Howard Henry Schlunder


Quote:
> I'm wondering how I can set a timer control to 60 seconds. Then pause the
> timer in any given moment before the 60 seconds interval is up. Run some
> other code while my timer is in pause. Then come back to un-pause the
timer
> to finish the remaining amount of time until it reach 60 seconds.

> I'm writing an program to control product line process with belt. Lets say
I
> expect my product to take 60 seconds to get from start to end of a belt.
> When the product reachs the end of belt at 60 second I'll need to do
> something like sound an alarm. If I recieve a signal that the belt stopped
> at 20 seconds from product starting point, I'll need to pause the timer at
> that moment and restart the timer to finish the remaining 40 seconds when
my
> belt start moving again. Then I'll sound an alarm when my product actually
> reached end of belt.

> How can I best achieve this with a single timer? or do I need multiple
timer
> to do so? maybe variable to hold the amount of time passed when timer is
> paused?
> Any comment or suggestion appricated.
> Thanks
> Bill



Fri, 10 Dec 2004 08:26:12 GMT  
 How to pause a timer control and restart it from pause for remaining interval?
The timer interval could be anything, or at least that is the way it should be if I implemented the formula correctly.  While testing, I used an interval of 100 ms, but 1000 ms should work fine as well (with the exception of reduced precision).

Howard Henry Schlunder

Quote:

>   Counts = Counts + Abs(CLng(TimerRunning))
>   If Counts = (1000& \ Timer1.Interval) * ProductControlLineDurration Then

> ** Are you assuming a timer interval of 1000 ms here?



Fri, 10 Dec 2004 10:24:30 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. How to pause a timer control and restart it from pause for remaining interval?

2. How to pause a specific interval?

3. Use timer control to pause program

4. Pause/Sleep/Halting code for a time interval

5. Pause execution of VBA Code and Restarting!

6. pausing a timer

7. Timer woes - application pauses

8. Using Timer as pause

9. Timer interval is depending on code in timer event

10. Timer Controls - Time Remaining

11. Pausing during a VBA program, handing control back to windows

12. Timer control interval

 

 
Powered by phpBB® Forum Software