推荐几种vb中创建超长时间计时器_VB.net_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

推荐几种vb中创建超长时间计时器

作者:黑客防线网安VB教程基地 来源:黑客防线网安VB教程基地 浏览次数:0

本篇关键词:时间创建推荐Long
黑客防线网安网讯:我们知道VB系统中提供了固有计时器Timer控件,最大值只能设置为65535,也就约一分钟多一点,在需要长时间计时时,该控件就无能为力了。下面推荐几种vb中创建超长时间计时器的方法:1。=====...

我们知道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

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14660-1.html
网站维护教程更新时间:2012-04-03 01:12:04  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer