我用了一个Timer,想要60分钟发生一次事件,所以就需要设置Interval=60*60*1000,但是Timer的属性Interval的值不能超过5,但我要设置一个较大的数值怎么办啊?

解决方案 »

  1.   

    设置一个变量,Timer的属性Interval的值为1000,然后每次事件变量+1,这样累计下去,一小时3600秒,判断变量为3600的时候,就做你要做的事情。
      

  2.   

    新建一个标准工程,将下面的代码拷贝到代码区Option ExplicitDim intTimerCount As IntegerPrivate Sub Form_Load()
        Timer1.Interval = 1000 '定时一秒
        Timer1.Enabled = True
        intTimerCount = 5 '5秒后提示消息,这个值改成3600就是一个小时了
    End SubPrivate Sub Timer1_Timer()
        Static intSelfCount As Integer
        intSelfCount = intSelfCount + 1
        If intSelfCount = intTimerCount Then
            MsgBox intTimerCount & "秒"
            intSelfCount = 0
        End If
    End Sub
      

  3.   

    把Timer的Interval设置成1000,然后记录Timer.Enable=True的时间tim_now
    在Timer加上比较代码DateDiff("s", tim_now, Now) = 1000 * 60
      

  4.   

    API 
    gettickcount()private sub timer1_timer ()
       static tcount as long 
       if tcount=0 then 
           tcount=gettickcount()
       else
           if gettickcount-tcount=3600000 then
                ---------处理事件
                tcount=0
           endif
       end if
       
    end sub 
      

  5.   

    如果用Timer我记得最大值是65535还是多少,..呵呵
    也没必要设成1000吧(当然楼上的一些只是举例)可以设60000这样每分钟一次,如果不要执行其它代码就这样比较好喽.
      

  6.   


    我举一个简单的例子,不知道对你是否有用……function nexttime(Tc as integer) as date
            Dim hTemp As Integer, mTemp As Integer,timeTemp 
            hTemp = Tc  / 60
            mTemp = Tc  Mod 60
            timeTemp = TimeValue(CStr(hTemp) & ":" & CStr(mTemp) & ":00")
            NextTime = firstTime + timeTemp
    end fucction
    Private Sub Timer1_Timer()
            If nexttime(60)>now Then
               MsgBox "执行你需要的动作……"        End If
    End Sub
      

  7.   

    同意 chewinggum(口香糖) 的方法。
    其实利用静态变量很容易实现的