2010/5/30 Bernard Marcelly <marce...@club-internet.fr>: > Message de Konstantin Tokarev date 2010-05-29 19:10 : >> >>> On MS-Windows the result is in milliseconds, with a precision of 16 ms >>> due to IBM PC hardware design. >> >> Does it mean that results of OOo Basic scripts may be platform-dependent? >> > > Help says it depends on OS. I have not tested on other OS than MS-Windows, > nor on other HW platform, e.g. Mac. > Help shows how to count the ticks for a given delay. > > This code shows on PC/MS-Windows that GetSystemTicks does not increment by > 1. > > Dim t1 As Long, t2 As Long, n As Long > n = 0 > t1 = GetSystemTicks > Do > t2 = GetSystemTicks -t1 > n = n+1 > Loop Until t2 <> 0 > MsgBox("t2 = " & t2 & " n = " & n) > > Regards > Bernard
Maybe I was wrong about the getSystemTicks() function. It seems like it actually measures time in ms, not just CPU time. At least my experiments point in that direction: REM ***** BASIC ***** Option Explicit Sub Main Dim t1 As Double, t2 As Double, n As Long, st as Long n=0 t1=now() st=GetSystemTicks() Do t2=now() n=n+1 Loop Until (t2-t1)*86400>=100 ' Approximately 100 seconds MsgBox("Ticks/s: " & GetSystemTicks()-st & chr(13) & _ "Loop: " & n & chr(13) & "t1= " & t1 & chr(13) & _ "t2= " & t2 & chr(13) & "t2-t1= " & t2-t1 & _ chr(13) & "In s: " & (t2-t1)*86400) End Sub Maybe something is wrong with my code, because sometimes it runs for an extra second. Run it in just one second instead of 100: REM ***** BASIC ***** Option Explicit Sub Main Dim t1 As Double, t2 As Double, n As Long, st as Long n=0 t1=now() st=GetSystemTicks() Do t2=now() n=n+1 Loop Until (t2-t1)*86400>=1 ' One second only MsgBox("Ticks/s: " & GetSystemTicks()-st & chr(13) & _ "Loop: " & n & chr(13) & "t1= " & t1 & chr(13) & _ "t2= " & t2 & chr(13) & "t2-t1= " & t2-t1 & _ chr(13) & "In s: " & (t2-t1)*86400) End Sub Now the ticks result should be somewhere between 0 and 999, right? It usually is, but now and then it's almost 2000. The n variable tells us how many times it looped, like in your example above, and it runs quite a few times for one tick, so why doesn't it realize that it's time to stop until (t2-t1)*86400 almost reaches 2? Yes, a bit out of topic, I know, but still interesting to know… For example one of the outputs is like this: Ticks/s: 1605 Loop: 43638 t1= 40328,4520717593 t2= 40328,4520949074 t2-t1= 2,31481462833472E-05 In s: 1,99999983888119 Why didn't it stop until (t2-t1)*86400≈2? It should have been ⩾1 thousands of times before that, shouldn't it? Johnny Rosenberg --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org