TimerAllarm




'Add the following code to the form:

Option Explicit
' 'This holds the amount of time (in milliseconds)

' 'the Timer will wait before the command button being

' 'held down is considered an "alarm" call

Dim WaitForPeriod As Integer

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Start the timer, using the WaitForPeriod chosen

Timer1.Interval = WaitForPeriod
Timer1.Enabled = True
End Sub
'_________________________________________________________


Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'The event, as far as you are concerned,

'is over, so turn off the timer

Timer1.Interval = 0
Timer1.Enabled = False
End Sub
'_________________________________________________________


Private Sub Command2_Click()
End
End Sub
'_________________________________________________________


Private Sub Form_Load()
'Position the form on the screen just above centre, in 1 call


Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2.5
End Sub
'_________________________________________________________


Private Sub Option1_Click(Index As Integer)

' 'use the Index of the control array as the value.

' '1000 is equal to 1 second

WaitForPeriod = Index * 1000
End Sub
'_________________________________________________________


Private Sub Timer1_Timer()
'The Timer event fires ***only after*** the interval has expired.

'If the interval is 2000 (2 seconds), then 2 seconds

'AFTER the command button is pressed, the following

'MsgBox will be displayed.

'If the command button is released BEFORE the interval

'fires this timer, then the MouseUp will turn off the

'timer and the message box won't display.


MsgBox "The alarm interval of" & Str$(WaitForPeriod% \ 1000) & " _
second(s) has expired...alarm sent.", 48, "Alarm In Progress"
'If it DOES fire, then the msgbox displays, and the

'Timer = False code assures it won't pop back on screen.

'(Comment out the next 2 lines and test the code to seewhat I mean..)

Timer1.Interval = 0
Timer1.Enabled = False
End Sub











( timerallarm.html )- by Paolo Puglisi - Modifica del 17/12/2023