- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0 |
我们知道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
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |