Now since a few PB releases ago ElapsedMilliseconds was changed from using GetTickCount on Windows to using QPC so wraparound or the signed changing to a negative will take yeas I believe.
But that is no excuse for not doing it the right way, and if you ever use any other time stuff (that is not ElapsedMilliseconds) then you need to use a variant of this code anyway to handle wraparounds.
This is a handy (and easy to use) procedure:
Code: Select all
Threaded start_time.q
Procedure.q Check_Time(reset.i = #False)
If reset
start_time = ElapsedMilliseconds()
ProcedureReturn 0
EndIf
ProcedureReturn (ElapsedMilliseconds() - start_time)
EndProcedure
;Example
Check_Time(#True) ;Reset the start time of our variable.
Delay(10)
Debug Check_Time()
Delay(10)
Debug Check_Time()
Delay(10)
Debug Check_Time()
If Check_Time() > 30
Debug "it has been over 30ms"
Else
Debug "it has been less than 30ms"
EndIf
Code: Select all
Threaded start_time.q
Macro Start_Time()
start_time = ElapsedMilliseconds()
EndMacro
Macro Check_Time()
(ElapsedMilliseconds() - start_time)
EndMacro
;Example
Start_Time() ;Reset the start time of our variable.
Delay(10)
Debug Check_Time()
Delay(10)
Debug Check_Time()
Delay(10)
Debug Check_Time()
If Check_Time() > 30
Debug "it has been over 30ms"
Else
Debug "it has been less than 30ms"
EndIf
If you need to check often (like in a main program loop somewhere, like maybe once a second) then I'd suggest the macro version.