Do
If Timer > Starttime + interval \ 1000 Then
RaiseEvent Jishi
Starttime = Timer
End If
If Qidong = False Then Exit Do
DoEvents
Loop
问题出在你的这个循环上,我暂时没有好的建议。
Private Qidong As Boolean
Public interval As Single
Public Event Jishi()
Private Starttime As Single
Public Function Enable()
Qidong = True
Starttime = Timer
If Qidong = True And interval > 0 Then
Do
If Timer > Starttime + interval \ 1000 Then
RaiseEvent Jishi
Starttime = Timer
End If
If Qidong = False Then Exit Do
DoEvents
Loop
End If
'interval\1000是因为VB的Timer函数单位是秒,而我们要做的计时器单位是毫秒
End Function
Public Function Disable()
Qidong = False
End Function
Form1:
Option Explicit
'2009-6-26
Public WithEvents Jishiqi As Timerlei
Private Sub Command1_Click()
Set Jishiqi = New Timerlei
Jishiqi.interval = 1000
Jishiqi.Enable