如何让定时器设成N分钟?要支持10分钟左右的,不能用TIMER控件,用什么?

解决方案 »

  1.   

    '模块中代码
    Dim lTimerId As Long
    Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As LongPrivate Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As LongPrivate Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerId As Long, ByVal lTime As Long)Dim lResult As Long
    lResult = StopTimer(lTimerId)
    Call InsertYourProcessNameHere
    'code to be executed after interval
    End SubPublic Sub StartTimer(lMinute As Long) 'convert interval to milliseconds prior to passing
    lTimerId = SetTimer(0, 0, lMinute * 60000, AddressOf TimerProc)
    End SubPublic Function StopTimer(lTimerId As Long) As Long
    'must pass the TimerId returned by SetTimer
    StopTimer = KillTimer(0, lTimerId)
    End Function'调用方式
    Call StartTimer(10) '10 minutes
      

  2.   

    要注意TIMER设定时间有最大值限制,这就是为什么不能用它的原因。
      

  3.   

    Timer时间设置成60000,就是一分钟一次再用个变量min as long每次TImer事件都min=min+1if min=10 then'10分钟了min=0
    end if
      

  4.   

    Private Sub Timer1_Timer()
        If Len(Timer1.Tag) = 0 Then Timer1.Tag = Now
        If DateDiff("s", Timer1.Tag, Now) >= 10 Then '10分钟
            MsgBox "时间到"
            Timer1.Tag = Now
        End If
    End Sub