高精度计时,精确到0.001秒。'在Project中加入一个Module,然后在其中加入以下代码:
Option ExplicitType LARGE_INTEGER
    lowpart As Long
    highpart As Long
End TypePublic Declare Function QueryPerformanceCounter Lib "kernel32" _
        (lpPerformanceCount As LARGE_INTEGER) As Long
Public Declare Function QueryPerformanceFrequency Lib "kernel32" _
        (lpFrequency As LARGE_INTEGER) As Long
Public 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
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Public Declare Function GetTickCount Lib "kernel32" () As LongPublic lMSFreq As Long
Public TimerCount As Single
Public lmmCount As Single
Public lTimeID As Long
Public actTime1 As Long
Public actTime2 As Long
Public iCountStart As SingleDim iCount As Single'注释: timeSetEvent的回调函数
Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, _
    ByVal dw1 As Long, ByVal dw2 As Long)
    
    Form1.Text2.Text = Format$(lmmCount, "00.00")
    lmmCount = lmmCount - 0.01
    If lmmCount <= 0 Then
        iCountStart = 60
        lmmCount = 60
        TimerCount = 60
        EndCount
    End If
End Sub
Sub EndCount()
    iCount = iCountStart
    iCountStart = 0
    timeKillEvent lTimeID
    actTime2 = GetTickCount - actTime1
    With Form1
        .Command1.Enabled = True
        .Command2.Enabled = False
        .Timer1.Enabled = False
        
        .Text1 = "计数器记时" + Format$((60 - iCount), "00.00") + "  " _
                + "实际经过时间" + Format$((actTime2 / 1000), "00.00")
        .Text2 = "计数器记时" + Format$((60 - lmmCount), "00.00") + "  " _
                + "实际经过时间" + Format$((actTime2 / 1000), "00.00")
        .Text3 = "计数器记时" + Format$((60 - TimerCount), "00.00") + "  " _
                + "实际经过时间" + Format$((actTime2 / 1000), "00.00")
    End With
End Sub

解决方案 »

  1.   

    http://www.csdn.net/expert/topic/604/604732.xml?temp=.7168238
    http://www.csdn.net/Expert/forum.asp?typenum=8&searchKeys=%BE%AB%C8%B7&roomid=2&author=&tabletype=now
      

  2.   

    更精确的计时一般使用Timer物件,没有办法精确的算到微秒,(每秒目更新18.2次),若要算到
    微秒,则使用GetTickCount ,它传回Windows启动後到目前为止所经过的时间,
    传回值以微秒为单位。Private Declare Function GetTickCount Lib "kernel32" Alias _
           "GetTickCount" () As LongPrivate CanContinue as BooleanPrivate 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 SubPrivate Sub Command2_Click()
      CanContinue =  False
    End Sub
      

  3.   

    不可能是我错了还是他错了
    gettickcount传回的是毫秒还是微秒?
    我查MSDN说是毫秒啊
      

  4.   

    QueryPerformanceFrequency 可以,它是根据 high-resolution performance counter (不知道如何翻译),理论上可以达到微秒(不是毫秒)级别,你可以参考一下这篇文章:
    http://www.applevb.com/art/timing.htm
      

  5.   

    另外你可以参考一下IBM站点的一篇开发文章:
    http://www-900.ibm.com/developerWorks/linux/sdk/rt/part1/index.shtml
    这篇文章本来是比较Linux以及Windows 2000的,里面的QueryPerformanceFrequency 编程应用你可以看一下