首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB高精度定时器 误差比较解决方法

2012-01-09 
VB高精度定时器 误差比较由于本人工作上需要,现在做一个精确到10毫秒以内的定时器。我花时间找了几个在网上

VB高精度定时器 误差比较
由于本人工作上需要,现在做一个精确到10毫秒以内的定时器。

我花时间找了几个在网上很常见的几种定时器,发现他们多多少少都会有误差,而且不定。

有时误差25,10,-20,5 毫秒等。。。

各位高手谁有做过类似精度的定时器,控制误差在10毫秒以内的定时器

下面是的整理的代码,已经分别做了测试,希望大家多多参与升级

http://u.115.com/file/dn9gjgps

如果有满意的结果,可以发到我的邮箱 atfeel#163.com

谢谢各位

[解决办法]
今天刚做的高精度定时器,送给你吧
Form1窗体代码
Option Explicit

Private Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Private Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long

Public hTimer As Long
Dim i As Long

Private Sub Command1_Click()
timeKillEvent hTimer
mMSec = 10
hTimer = timeSetEvent(mMSec, 1, AddressOf TimeProc, 0, 1&)

End Sub

Private Sub Form_Unload(Cancel As Integer)
If hTimer <> 0 Then
timeKillEvent hTimer
End If
End Sub

Bas模块代码
Option Explicit

Public i As Long
Public mMSec As Long

Public Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
i = i + 1
If i = 100 Then
i = 0
Form1.Label1 = CStr(Val(Form1.Label1) + 1)
End If
End Sub

实际测试,定时精度很高,观测5分钟,数字跳和系统时钟秒针跳完全同步!

热点排行