The Click

T

The Flash

How I I check to see if a button has been pressed in the middle of a procedure?

For instance if I want Button A to start a countdown ticker from 100 to 1
and I want Button B to be able to pause the ticker how would I check to see
if Button B has been pressed while the Ticker Procedure is running?
 
D

Dirk Goldgar

The Flash said:
How I I check to see if a button has been pressed in the middle of a
procedure?

For instance if I want Button A to start a countdown ticker from 100
to 1
and I want Button B to be able to pause the ticker how would I check
to see
if Button B has been pressed while the Ticker Procedure is running?

If your countdown ticker is driven by a Timer event procedure, you can
just use the Click event procedure for button B to set the form's
TimerInterval to 0, keeping the Timer event from firing. To restart the
timer, set the TimerInterval back to its original setting. For example:

'----- start of example code -----
Private Sub ButtonA_Click()

' Start or restart the timer.

If Me!Countdown <= 0 Then
Me!Countdown = 100
End If

Me.TimerInterval = 1000 ' tick every second

End Sub

Private Sub ButtonB_Click()

' Pause the timer.

Me.TimerInterval = 0

End Sub

Private Sub Form_Timer()

With Me!Countdown

.Value = .Value - 1

If .Value <= 0 Then
Me.TimerInterval = 0 ' turn off the timer
Msgbox "Time's up!"
End If

End With

End Sub
'----- end of example code -----

You could actually use just one button for this, if you wanted -- if the
timer's stopped, you start it; if it's started, you stop it. You'd
change the button's caption or image to reflect the current status.
 
T

The Flash

Ahhhh, I see. Thanks!

Dirk Goldgar said:
If your countdown ticker is driven by a Timer event procedure, you can
just use the Click event procedure for button B to set the form's
TimerInterval to 0, keeping the Timer event from firing. To restart the
timer, set the TimerInterval back to its original setting. For example:

'----- start of example code -----
Private Sub ButtonA_Click()

' Start or restart the timer.

If Me!Countdown <= 0 Then
Me!Countdown = 100
End If

Me.TimerInterval = 1000 ' tick every second

End Sub

Private Sub ButtonB_Click()

' Pause the timer.

Me.TimerInterval = 0

End Sub

Private Sub Form_Timer()

With Me!Countdown

.Value = .Value - 1

If .Value <= 0 Then
Me.TimerInterval = 0 ' turn off the timer
Msgbox "Time's up!"
End If

End With

End Sub
'----- end of example code -----

You could actually use just one button for this, if you wanted -- if the
timer's stopped, you start it; if it's started, you stop it. You'd
change the button's caption or image to reflect the current status.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Top