Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This holds the amount of time (in milliseconds)
'the Timer will wait before the command button being
'held down is considered an "alarm" call
Private 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()
Unload Me
End Sub
Private Sub Form_Load()
'position the form on the screen
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
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 see
'what I mean..)
Timer1.Interval = 0
Timer1.Enabled = False
End Sub
|