interval设为1000!Private Sub Timer1_Timer() If Minute(Time)=0 Ehen MsgBox "……" End If End Sub
其实,用timer,定时保存和读取注册表,用注册表的值来控制也是个办法。
用timer,定期保存和读取注册表,也是可以实现的。
那么这么全局的Timer对象该如何设呢?
interval设为1000!Private NowMinute As LongPrivate Sub Command1_Click() NowMinute=Minute(Time)
End SubPrivate Sub Timer1_Timer() If Minute(Time)=NowMinute Ehen MsgBox "……" End If End Sub
'timer控件必须放在一个窗口容器上. Private Sub Form_Load() Timer1.Interval = 1000 End SubPrivate Sub Timer1_Timer() Static i As Long i = i + 1 If i = 60 Then i = 0 MsgBox "到一小时了." End If
End Sub
'timer控件必须放在一个窗口容器上. Private Sub Form_Load() Timer1.Interval = 1000 End SubPrivate Sub Timer1_Timer() Static i As Long i = i + 1 If i = 60 Then i = 0 MsgBox "到一小时了." End If
End Sub
可以不用窗口.Copy the following code to the Code window of Module1:
Option Explicit Declare Function SetTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" _ (ByVal hwnd As Long, _ ByVal nIDEvent As Long) As Long Global iCounter As Integer Sub TimerProc(ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal idEvent As Long, _ ByVal dwTime As Long) iCounter = iCounter + 1 Form1.Text1.Text = CStr(iCounter) End Sub
Copy the following code to the Code window of Form1: Option Explicit Dim lngTimerID As Long Dim BlnTimer As Boolean Private Sub Form_Load() BlnTimer = False Command1.Caption = "Start Timer" End Sub Private Sub Command1_Click() 'Starts and stops the timer. If BlnTimer = False Then lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc) If lngTimerID = 0 Then MsgBox "Timer not created. Ending Program" Exit Sub End If BlnTimer = True Command1.Caption = "Stop Timer" Else lngTimerID = KillTimer(0, lngTimerID) If lngTimerID = 0 Then MsgBox "couldn't kill the timer" End If BlnTimer = False Command1.Caption = "Start Timer" End If End Sub
还可以用一个Long型值来记录,每调用一次Timer事件就加一,到60的时候就一个小时了。
If Minute(Time)=0 Ehen
MsgBox "……"
End If
End Sub
NowMinute=Minute(Time)
End SubPrivate Sub Timer1_Timer()
If Minute(Time)=NowMinute Ehen
MsgBox "……"
End If
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
Static i As Long
i = i + 1
If i = 60 Then
i = 0
MsgBox "到一小时了."
End If
End Sub
'timer控件必须放在一个窗口容器上.
Private Sub Form_Load()
Timer1.Interval = 1000
End SubPrivate Sub Timer1_Timer()
Static i As Long
i = i + 1
If i = 60 Then
i = 0
MsgBox "到一小时了."
End If
End Sub
Option Explicit Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long Global iCounter As Integer Sub TimerProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long) iCounter = iCounter + 1
Form1.Text1.Text = CStr(iCounter)
End Sub
Copy the following code to the Code window of Form1: Option Explicit
Dim lngTimerID As Long
Dim BlnTimer As Boolean Private Sub Form_Load()
BlnTimer = False
Command1.Caption = "Start Timer"
End Sub Private Sub Command1_Click()
'Starts and stops the timer. If BlnTimer = False Then
lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc)
If lngTimerID = 0 Then
MsgBox "Timer not created. Ending Program"
Exit Sub
End If
BlnTimer = True
Command1.Caption = "Stop Timer"
Else
lngTimerID = KillTimer(0, lngTimerID)
If lngTimerID = 0 Then
MsgBox "couldn't kill the timer"
End If
BlnTimer = False
Command1.Caption = "Start Timer"
End If End Sub