Gustav Brock
Gustav at cactus.dk
Mon Feb 14 09:49:41 CST 2005
Hi Stuart
Thanks. Are you sure about those 10 ms?
If I run a small test function:
Public Function TimerSequence() As Single
Dim sngLast As Single
Dim sngNext As Single
Dim lngTimer As Long
Dim lngCount As Long
Dim lngItems As Long
While Timer * 100 Mod 100 > 0
lngTimer = Timer
Wend
For lngCount = 1 To 3000000
sngLast = sngNext
sngNext = Timer
If lngTimer < Int(sngNext) Then
Exit For
ElseIf sngLast < sngNext Then
lngItems = lngItems + 1
Debug.Print lngItems, sngNext * 100 Mod 100
End If
Next
TimerSequence = 1000 / lngItems
End Function
I always get this sequence:
1 0
2 2
3 3
4 5
5 6
6 8
7 9
8 11
9 12
10 14
11 16
12 17
13 19
14 20
15 22
16 23
17 25
18 27
19 28
20 30
21 31
22 33
23 34
24 36
25 38
26 39
27 41
28 42
29 44
30 45
31 47
32 48
33 50
34 52
35 53
36 55
37 56
38 58
39 59
40 61
41 62
42 64
43 66
44 67
45 69
46 70
47 72
48 73
49 75
50 77
51 78
52 80
53 81
54 83
55 84
56 86
57 88
58 89
59 91
60 92
61 94
62 95
63 97
64 98
which returns 15.625 ms per count.
Looks to me like an even distribution of five bits per second rather
than based on ticks ...
/gustav
>>> stuart at lexacorp.com.pg 14-02-2005 14:54:35 >>>
On 14 Feb 2005 at 14:23, Gustav Brock wrote:
> Hi all
>
> Has anyone used this?
> It is a classic in the callback function example but I don't recall
any
> reference to it.
>
> It seems to return seconds from midnight as well as a fraction of a
> second with a resolution of about 1/60 second. Thus it could be used
> where you need a resolution of less than one second.
>
I've been using the Timer function in various flavours of Basic for may
years. TheTimer finctions (and the .Net DateTime.Now) use the
getTickCount
API function. In W9X, the default resolution is approx 50ms (actually
55
ms or 18.2 times per second), in NT/2K/XP it's approx 10 ms. It also
has a
very low priority in the task queue so can be postponed/cancelled.
There are two more accurate timers available. timeGetTime (
Environment.TickCount in.Net) which is good for 1/1000 sec but has a
fairly
high overhead and QueryPerformanceCounter/PerformanceFrequency which is
very accurate for *short* times.
--
Stuart