millisec() concern

BlitzMax Forums/BlitzMax Programming/millisec() concern

I noticed many have troubles calculating the elapsed time when timer jumps back to a negative number.

I wanted to share this code with ya all :

Strict

Global newtime:Int = MilliSecs()
Global oldtime:Int = MilliSecs()
Global elapsedtime:Int = 0

Repeat

oldtime = newtime
newtime = MilliSecs()

If oldtime < newtime Then 
'using 2147483648 to make sure newtime and oldtime are positive all the time.
elapsedtime = (2147483648 + newtime) - (2147483648 + oldtime)
Else
'In case if the newtime is smaller than the oldtime (after reset) this calculation is done to make sure you get the correct elapsed time.
elapsedtime = (2147483648 + newtime) - (oldtime - 2147483648)
EndIf

Delay 5000
Print elapsedtime + " MilliSecs elapsed after last print command!"

Until KeyHit(Key_ESCAPE)


I never tested this code for 24 days to be sure it works, and is just something I came up with. Could anyone test this or leave some comments.