# Ticks is Integer ? Why not Uinteger ?

In the Xojo doc, Ticks is an integer, then -2,147,483,648 to 2,147,483,647 (32-bit apps).
2,147,483,647 / 60 / 60 = 596523 minutes -> / 60 = 9942 hours -> / 24 = 414 days , then more than an year.
But what happens if my app runs during 2 years ? Does Ticks = -2,147,483,648 ?

It is not important as it’s very long and we won’t run an application during 1 year, I just ask myself.
I look into that because I run a loop which can be long. Before entering to this loop I do : MyEndTicks = Ticks + 30 (which is my delay = half of a second).
In my loop I check if it’s too long : If Ticks > MyEndTicks then Exit Loop . In this case I enable a button so the user can launch the loop in a Thread.

Ticks is very old and was there long before we had unsigned integers in Xojo.

https://documentation.xojo.com/index.php/Ticks

Don’t forget its the time since the computer was started so its possible (thought highly unlikely) that someone might start your app on a computer that has been on for two years or more.

Also, if your app is 64bit, it’ll be a LOT longer than 1.13 years, more like approximately 4874520144 years.

I use ticks to test whether to time out, so I use ABS() to allow for crazy long running times:

```Dim tempTicks As Integer = ticks while something = True  if ABS(ticks - tempTicks) > 3600 then Exit wend```

Julian, effectively I didn’t notice it was from the computer start and not my application start. In the Xojo help, it’s written “you may encounter a case where it appears that the stop time is prior to the start time” but they don’t say if it come back to 0 or -2,147,483,648 (in 32 bits).
The Abs() is a good solution. If I set MyEndTicks to the same property as Ticks (then Integer ?) I do not need to use Abs() as MyEndTicks will do the same as Ticks, then come back to -2,147,483,648 or 0 .

a rollover results in -2,147,483,648 which is why David specified using ABS

just doing an absolute value does not work in the situation where the rollover happens during your wait period. It will be fine otherwise.

To support it in all situations you need to cast the result of the test as a signed integer and the output from ticks as an unsigned integer, and then the math of the one time being before or after the other will still work even if the rollover has happened in the meantime. Something like:

dim timeoutTicks as uint32 = uint32( ticks) + 3600

if int32( uint32( ticks) - timeoutTicks) >= 0 then
end if

The same code can be used for microsecond rollovers also. I use something similar to that all the time in PIC projects where the milliseconds are an 8 or 16 bit unsigned integer. I have not used it in Xojo though, so Im not entirely sure about its casting of integer types like that. Initial testing seems to say that will work, but youll want to test yourself before relying upon it not to do something weird at the rollover point.

The code above also protects you from the rollover of the unsigned32 integer which is unlikely to happen I think, but perhaps if you were using it with microseconds it might? It might be enough to simply cast the ticks as uint32( ticks) and use that as it will then be able to go up to 4,294,967,295 which is about 2 and a third years. If you want to guard against that then you also need the other casting and checking.

sure it does… I was not sure that ABS would work at all during a rollover… but I tested it, and it does

Ive already wasted too much time thinking about this now Youre right, it does work! And it works because they are signed integers. If they were unsigned integers, like in the little PIC devices Ive been working with lately, then you need further protections as they roll over just to zero and not to a negative number Sorry for the confusion

Time to use microseconds with a little calculus instead.

microseconds is Double and I think it should be Uint64 as Ticks.

The rollover resolve itself if we use the same property as Ticks.
If Ticks is Int8 (easiest to explain) then if I do MyEndTicks = Ticks + 10 with MyEndTicks Int8 too. If I begin with Ticks = 125, then MyEndTicks = -121 . Ticks will roll over the same way.
If both are Unit8 and Ticks = 250 then MyEndTicks = (250 + 10) mod 256 = 4 and it works too.
The problem occur if I set MyEndTicks different property than Ticks.
That’s why I wanted to be sure Ticks is Integer and not Uinteger.

Thomas, would it not be time to file a feature request ? This thread will soon be forgotten…