回调函数声明错误,应该如Sub TimerProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
给个正确的吧 'Form1 Option ExplicitDim dtTime As DatePublic Sub CountDown() dtTime = DateAdd("s", -1, dtTime) Text1.Text = dtTime
If DateDiff("s", 0, dtTime) <= 0 Then timeKillEvent hMMTimer Command1.Caption = "Start" MsgBox "时间到" End If End SubPrivate Sub Command1_Click() If Command1.Caption = "Start" Then dtTime = CDate(Text1.Text) hMMTimer = timeSetEvent(1000, 0, AddressOf TimerProc, 0, TIME_PERIODIC Or TIME_CALLBACK_FUNCTION) Command1.Caption = "Stop" Else timeKillEvent hMMTimer Command1.Caption = "Start" End If End SubPrivate Sub Form_Load() Command1.Caption = "Start" Text1.Text = "00:00:05" Timer1.Enabled = False End Sub 'Module1 Option ExplicitPublic Const TIME_ONESHOT = 0 'Event occurs once, after uDelay milliseconds. Public Const TIME_PERIODIC = 1 'Event occurs every uDelay milliseconds. Public Const TIME_CALLBACK_EVENT_PULSE = &H20 'When the timer expires, Windows calls thePulseEvent function to pulse the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored. Public Const TIME_CALLBACK_EVENT_SET = &H10 'When the timer expires, Windows calls theSetEvent function to set the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored. Public Const TIME_CALLBACK_FUNCTION = &H0 'When the timer expires, Windows calls the function pointed to by the lpTimeProc parameter. This is the default.Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long Public hMMTimer As LongSub TimerProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long) Form1.CountDown End Sub
'Form1
Option ExplicitDim dtTime As DatePublic Sub CountDown()
dtTime = DateAdd("s", -1, dtTime)
Text1.Text = dtTime
If DateDiff("s", 0, dtTime) <= 0 Then
timeKillEvent hMMTimer
Command1.Caption = "Start"
MsgBox "时间到"
End If
End SubPrivate Sub Command1_Click()
If Command1.Caption = "Start" Then
dtTime = CDate(Text1.Text)
hMMTimer = timeSetEvent(1000, 0, AddressOf TimerProc, 0, TIME_PERIODIC Or TIME_CALLBACK_FUNCTION)
Command1.Caption = "Stop"
Else
timeKillEvent hMMTimer
Command1.Caption = "Start"
End If
End SubPrivate Sub Form_Load()
Command1.Caption = "Start"
Text1.Text = "00:00:05"
Timer1.Enabled = False
End Sub
'Module1
Option ExplicitPublic Const TIME_ONESHOT = 0 'Event occurs once, after uDelay milliseconds.
Public Const TIME_PERIODIC = 1 'Event occurs every uDelay milliseconds.
Public Const TIME_CALLBACK_EVENT_PULSE = &H20 'When the timer expires, Windows calls thePulseEvent function to pulse the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.
Public Const TIME_CALLBACK_EVENT_SET = &H10 'When the timer expires, Windows calls theSetEvent function to set the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.
Public Const TIME_CALLBACK_FUNCTION = &H0 'When the timer expires, Windows calls the function pointed to by the lpTimeProc parameter. This is the default.Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Public hMMTimer As LongSub TimerProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
Form1.CountDown
End Sub