推荐几种vb中创建超长时间计时器
我们知道VB系统中提供了固有计时器Timer控件,最大值只能设置为65535,也就约一分钟多一点,在需要长时间计时时,该控件就无能为力了。
下面推荐几种vb中创建超长时间计时器的方法:
1。==============
dim start as variant,xx as variant
dim totaltime as long
start=now
while true
xx=now
totaltime=datediff("s",start,xx)
if totaltime > 你需要的时间 then
exit sub
endif
wend
===============
2.
=============
sub timer1_timer()
static min as long
static second as long
static hour as long
static day as long
second = second+1
if second = 60 then
second = 0
min = min + 1
'这里写1分钟做一次的事
if min = 60 then
min = 0
hour = hour+1
'这里写1小时做一次的事
if hour = 24 then
hour = 0
day = day+1
'这里写一天做一次的事
endif
endif
endif
sub
============
3
=============
Dim totalTime As Long
Private Sub Timer1_Timer()
totalTime = totalTime + 1
If totalTime = 60 * 60 * 12 Then '例如每12小时调用一次
totalTime = 0
Call yourProcess
End
End Sub
Private Sub Form_Load()
Timer1.Interval = 60000 '间隔为1分钟
Timer1.Enabled = True
totalTime = 0
End Sub
=============
4。调用模块
================
'模块中代码
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 Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private 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 Sub
Public Sub StartTimer(lInterval As Long) 'convert interval to milliseconds prior to passing
lTimerId = SetTimer(0, 0, lInterval, AddressOf TimerProc)
End Sub
Public Function StopTimer(lTimerId As Long) As Long
'must pass the TimerId returned by SetTimer
StopTimer = KillTimer(0, lTimerId)
End Function
'调用方式
Call StartTimer(50000000) '50000 seconds
- 上一篇:认识VB的扩展名
- 下一篇:用VB编写键盘拦截程序