Option Explicit Declare Function SetTimer Lib " user32 " ( ByVal hwnd As Long , nIDEvent uElapse lpTimerFunc ) KillTimer Public Sub TimerProc( uMsg idEvent dwTime MsgBox Now() End Sub
Dim lngTimerID BlnTimer Boolean Private Form_Load() BlnTimer = False Command1.Caption 定时开始 End Sub Form_Unload(Cancel Integer ) KillTimer 0 Command1_Click() If Then ' 每5秒钟调用一次函数 SetTimer( 5000 AddressOf TimerProc) BlnTimer True 定时结束 Else KillTimer End End Sub