麻辣家族討論版版's Archiver

laigs218 發表於 2021-7-18 14:11

更精確的計時 VB

一般使用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

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供