使用API函数GetTickCount来计时非常方便,可惜它有一个致命的缺点,就是在计算机运行49.71天后,会自动置0,从而导致计时错误,因某些服务器应用程序需要长时间不开机运行,GetTickCount函数显然满足不了要求。为此,我使用GetSystemTime函数编写了一个替代函数叫GetTickCountEx,可以有效地避免原GetTickCount函数的问题,具体代码如下:
Private Function GetTickCountEx() As Currency
Dim stTime As SYSTEMTIME
GetSystemTime stTime
GetTickCountEx = DateDiff("d", "1900-01-01", stTime.wYear & "-" & stTime.wMonth & "-" & stTime.wDay) * 8640000@ + stTime.wHour * 360000@ + stTime.wMinute * 60000@ + stTime.wSecond * 1000@ + stTime.wMilliseconds
End Function