Chapter 25. Time

Occasions will probably arise when your application needs to concern itself with time. Sometimes you want to know how much time has elapsed between two moments. Sometimes you want to let a certain amount of time elapse before proceeding. This chapter delves into the mysteries of time in REALbasic.

For the current time on the system clock, see Section 5.6.

Ticks and Microseconds

Two functions let you measure the passage of time:

Ticks

Returns an integer that is the number of ticks (roughly, sixtieths of a second) that have elapsed since the computer was turned on. A tick is rather a gross measure, and may also be slightly inaccurate.

Microseconds

Returns a double that is the number of millionths of a second that have elapsed since the computer was turned on.

These functions are useful not so much for the actual values they return (since they don’t tell you what time it is, in any important sense), but rather for their ability to measure time intervals as they elapse. You can use them, for example, to pause for a certain interval. You may recall that in Chapter 5 these lines were used to pause a racing ProgressBar for some random amount of time:

max = rnd*15 + 1
i = ticks
while ticks-i < max
wend

That’s quite a standard approach for pausing. We define how many ticks we want to pause for. Then we learn the current Ticks value, but we don’t really care what it is; we only want to keep checking the Ticks value, as the time goes by, until it has increased by the ...

Get REALBasic: TDG, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.