你可以从http://www.mvps.org/ccrp/controls/ccrptimer6.htm下载免费的CCRP High Performance Timer Objects控件。VB的Timer控件实际精度大约55ms,这个控件大约1ms(基本是目前Windows能够达到的极限了)。如果你要进行延时,可以使用API函数timeSetEvent,它可以实现1ms的精度。我在网上看的,希望对你有帮助.
'Performance Counter
Private Type LARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim T As Long, liFrequency As LARGE_INTEGER, liStart As LARGE_INTEGER, liStop As LARGE_INTEGER
Dim cuFrequency As Currency, cuStart As Currency, cuStop As Currency
'Retrieve the frequency of the performance counter
If QueryPerformanceFrequency(liFrequency) = 0 Then
MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
Else
'convert the large integer to currency
cuFrequency = LargeIntToCurrency(liFrequency)
'retrieve tick count
QueryPerformanceCounter liStart
'do something
For T = 0 To 100000
DoEvents
Next T
'retrieve tick count
QueryPerformanceCounter liStop
'convert large integers to currency's
cuStart = LargeIntToCurrency(liStart)
cuStop = LargeIntToCurrency(liStop)
'calculate how many seconds passed, and show the result
MsgBox "Time: " + CStr((cuStop - cuStart) / cuFrequency) + " seconds"
End If
End Sub
Private Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency
'copy 8 bytes from the large integer to an ampty currency
CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
'adjust it
LargeIntToCurrency = LargeIntToCurrency * 10000
End Function
Parameters
hProcess
[in] Handle to the process whose timing information is sought. This handle must be created with the PROCESS_QUERY_INFORMATION access right. For more information, see Process Security and Access Rights.
lpCreationTime
[out] Pointer to a FILETIME structure that receives the creation time of the process.
lpExitTime
[out] Pointer to a FILETIME structure that receives the exit time of the process. If the process has not exited, the content of this structure is undefined.
lpKernelTime
[out] Pointer to a FILETIME structure that receives the amount of time that the process has executed in kernel mode. The time that each of the threads of the process has executed in kernel mode is determined, and then all of those times are summed together to obtain this value.
lpUserTime
[out] Pointer to a FILETIME structure that receives the amount of time that the process has executed in user mode. The time that each of the threads of the process has executed in user mode is determined, and then all of those times are summed together to obtain this value.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
All times are expressed using FILETIME data structures. Such a structure contains two 32-bit values that combine to form a 64-bit count of 100-nanosecond time units.
Process creation and exit times are points in time expressed as the amount of time that has elapsed since midnight on January 1, 1601 at Greenwich, England. There are several functions that an application can use to convert such values to more generally useful forms.
Process kernel mode and user mode times are amounts of time. For example, if a process has spent one second in kernel mode, this function will fill the FILETIME structure specified by lpKernelTime with a 64-bit value of ten million. That is the number of 100-nanosecond units in one second.
Requirements
Client Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 3.5 and later.
Server Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 3.5 and later.
Header Declared in Winbase.h; include Windows.h.
我也遇到同样的问题,不过发现,用TIMER控件可以解决.具体操作如下:
在窗体中,加入TIMER控件,在程序的开头,设置一个字符变量,记录开始时的系统时间,在程序的结尾,设置一个字符变量,记录结束时间,再设置一个 Double变量,计算结束时间与开始时间的差即可.举例:
dim begin_time as string
begin_time=timer
......(此部分为程序主体部分)
dim end_time as string
end_time=timer
dim operator_time as Double
operator_time=cdbl(end_time)-cdbl(begin_time)
小数点前表示秒.
希望能给你帮助