I am programming some winsocket-applications with vba and there is the possibity of time outs.
I have experimented with API-Timer Settimer and Killtimer, but there you have to be careful to start and stop the timer parallel to the normal vba program.
The included timer() function in vba is not very precise, so i decided to program the timer with GetTickCount on a 32 bit office system.
But here is the problem that after 24.9 days the Counter restarts. On newer systems you could use longptr and GetTickCount64 i now, but it should run on an old Windows 32 Bit System as well.
So i coded something like a ring counter for about 1 sec, but i am not sure
- if you can code it better or
- even if it works after 24.9 days
So could you give some response to my test program (coded in excel vba):
Option Explicit
Declare Function GetTickCount Lib "kernel32" () As Long
Sub sTest()
Dim intStart As Integer
Dim intDelta As Integer
Do
intStart = fxTimer1024
intDelta = fxTimerDelta(intStart)
Do While intDelta < 200
DoEvents 'endless loop, use ctrl+pause/break to end
intDelta = fxTimerDelta(intStart)
Loop
Debug.Print intStart, intDelta
Loop
End Sub
Function fxTimer1024()
fxTimer1024 = GetTickCount() Mod 1024
End Function
Function fxTimerDelta(intStart)
Dim x As Long
x = fxTimer1024
If intStart > x Then
fxTimerDelta = x + 1024 - intStart
Else
fxTimerDelta = x - intStart
End If
End Function