Option Explicit Dim tcount As IntegerPrivate Sub Form_Load() Timer1.Interval = 60000 tcount = 0 End SubPrivate Sub Timer1_Timer() If tcount < 60 Then tcount = tcount + 1 Exit Sub Else tcount = 0 '一小时时间到 '………… End If End Sub
'可控制任何时间间隔: option explicit const T = 3600 '改变此值即可达到控制更长时间。 dim T1 as long dim T2 as longForm_Load时 T1 = hour(now) * 3600 + minute(now) + second(now)Timer1_Timer()时: T2 = hour(now) * 3600 + minute(now) + second(now) if abs(T2-T1)>=T then T1 = T2 msgbox "时间到!" end if
'修改如下:'可控制任何时间间隔: option explicit const T = 3600 '改变此值即可达到控制更长时间。 dim T1 as long dim T2 as longForm_Load时 T1 = hour(now) * 3600 + minute(now) * 60 + second(now)Timer1_Timer()时: T2 = hour(now) * 3600 + minute(now) * 60 + second(now) if abs(T2-T1)>=T then T1 = T2 msgbox "时间到!" end if
有一个更好的控件 BNTimer Interval property Get or set the timer interval. The value ranges from 1ms to 2147483.647s and if the value is 0,the timer will be stopped.
Timer不准确
Dim tcount As IntegerPrivate Sub Form_Load()
Timer1.Interval = 60000
tcount = 0
End SubPrivate Sub Timer1_Timer()
If tcount < 60 Then
tcount = tcount + 1
Exit Sub
Else
tcount = 0
'一小时时间到
'…………
End If
End Sub
option explicit
const T = 3600 '改变此值即可达到控制更长时间。
dim T1 as long
dim T2 as longForm_Load时
T1 = hour(now) * 3600 + minute(now) + second(now)Timer1_Timer()时:
T2 = hour(now) * 3600 + minute(now) + second(now)
if abs(T2-T1)>=T then
T1 = T2
msgbox "时间到!"
end if
option explicit
const T = 3600 '改变此值即可达到控制更长时间。
dim T1 as long
dim T2 as longForm_Load时
T1 = hour(now) * 3600 + minute(now) * 60 + second(now)Timer1_Timer()时:
T2 = hour(now) * 3600 + minute(now) * 60 + second(now)
if abs(T2-T1)>=T then
T1 = T2
msgbox "时间到!"
end if
Interval property
Get or set the timer interval. The value ranges from 1ms to 2147483.647s and if the value is 0,the timer will be stopped.