VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 更精确的计时
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:11582, 日期:2001-09-17
 更精确的计时


 

  一般使用Timer物件,没有办法精确的算到微秒,(每秒目更新18.2次),若要算到
微秒,则使用GetTickCount ,它传回Windows启动後到目前为止所经过的时间,
传回值以微秒为单位。

Private Declare Function GetTickCount Lib "kernel32" Alias _
       "GetTickCount" () As Long

Private CanContinue as Boolean

Private Sub Command1_click()
Dim i as Long
Dim j as Long
i = GetTickCount()
CanContinue = True
Do While CanContinue
   j = GetTickCount()
   if j - i > 50 Then
      Debug.Print "已过50微秒"
      i = j
   End If
   DoEvents
Loop
End Sub

Private Sub Command2_Click()
  CanContinue =  False
End Sub