Novice question about time functions 
Author Message
 Novice question about time functions

Are there any functions in VB that deal with units of time less than a
second? I want to write a program that tests the reaction times of people
against each other and I thought, with the amount of computing power that is
on a machine, that to just count empty loops the value of the counter would
grow to big for the variable to quickly. If you know what I mean. Does
anyone know how I can mesure the time it takes for a person to hit a button?
I don't actually need a value in microseconds, a value that can be compared
with the values of others would do.

Thanks in advance
Alan



Sun, 15 Aug 2004 21:13:28 GMT  
 Novice question about time functions
In general PCs can measure time units down to something like 18.9
'ticks' per second.

This is historical

- you can test this by printing the variable Timer in a Timer set a
1milisecond interval (I get 13 hits per second in the IDE)

Private Sub Timer1_Timer()
    Me.Print Timer
End Sub

There are such things as 'high resolution timers'
also this :

Option Explicit

Private Declare Function timeGetTime _
        Lib "winmm.dll" () As Long

Private Sub Command1_Click()
    Dim HTime&, L9%
    For L9 = 1 To 10
        HTime = timeGetTime
        Print HTime
        While HTime = timeGetTime
        Wend
    Next

End Sub

This looks as if it is good for Milliseconds

On Wed, 27 Feb 2002 13:13:28 -0000, "Alan Sinclair"

Quote:

>Are there any functions in VB that deal with units of time less than a
>second? I want to write a program that tests the reaction times of people
>against each other and I thought, with the amount of computing power that is
>on a machine, that to just count empty loops the value of the counter would
>grow to big for the variable to quickly. If you know what I mean. Does
>anyone know how I can mesure the time it takes for a person to hit a button?
>I don't actually need a value in microseconds, a value that can be compared
>with the values of others would do.

>Thanks in advance
>Alan



Mon, 16 Aug 2004 01:24:42 GMT  
 Novice question about time functions

Quote:
> Private Sub Command1_Click()
>     Dim HTime&, L9%
>     For L9 = 1 To 10
>         HTime = timeGetTime
>         Print HTime
>         While HTime = timeGetTime
>         Wend
>     Next
> End Sub

> This looks as if it is good for Milliseconds

It is. The only problem is that button click events are not! So, if the OP
wants to time the user's response by using timeGetTime in a button click
event then he will still have to put up with Windows limited timing
resolution :-(

Mike



Mon, 16 Aug 2004 03:31:01 GMT  
 Novice question about time functions
Maybe dispense with the Button ?

(BTW thanks for the FillRect tip)

On Wed, 27 Feb 2002 19:31:01 -0000, "Maureen"

Quote:



>> Private Sub Command1_Click()
>>     Dim HTime&, L9%
>>     For L9 = 1 To 10
>>         HTime = timeGetTime
>>         Print HTime
>>         While HTime = timeGetTime
>>         Wend
>>     Next
>> End Sub

>> This looks as if it is good for Milliseconds

>It is. The only problem is that button click events are not! So, if the OP
>wants to time the user's response by using timeGetTime in a button click
>event then he will still have to put up with Windows limited timing
>resolution :-(

>Mike



Mon, 16 Aug 2004 04:10:56 GMT  
 Novice question about time functions

Quote:

> Maybe dispense with the Button ?

Yes. He could do that, Jerry. But the problem is that just about every
"event" that the user can cause to occur suffers from the same limited
resolution (because of the way that Windows generates and executes these
things). So, if the OP wants to time the user's response by looking at when
he "clicks" something, or maybe takes some other action (as he said in his
original message) then I am afraid he is stuck with the limited resolution.
Actually, the timing resolution might be good enough for him anyway, since
he originally wanted "something better than one second". In a button click
event he can get a resolution of about 25 milliseconds (under Win 98), which
will probably be good enough for him. Try the following:

Option Explicit
Private Declare Function timeGetTime _
  Lib "winmm.dll" () As Long
Private t1 As Long, t2 As Long

Private Sub command1_MouseDown(Button As Integer, _
  Shift As Integer, X As Single, Y As Single)
t1 = timeGetTime
End Sub

Private Sub Command1_MouseUp(Button As Integer, _
  Shift As Integer, X As Single, Y As Single)
t2 = timeGetTime
List1.AddItem Format(t2 - t1)
End Sub

It doesn't matter how fast you click the button (or how long you hold it
down for), you get results that are obviously "tied to" a very approximate
25 millisecond "clock" (at least on my system). Things are even worse if you
use other events (for example, the MouseDown and MouseUp events of a Form).

Mike



Mon, 16 Aug 2004 05:10:45 GMT  
 Novice question about time functions


Quote:
> Maybe dispense with the Button ?

> (BTW thanks for the FillRect tip)

> On Wed, 27 Feb 2002 19:31:01 -0000, "Maureen"


Mike ... you swing both ways ? I know you're still with Maureen (as
evidenced by the email address), but what's with Jerry asking you to
dispense with the button as you fill rect...      ;-)


Mon, 16 Aug 2004 06:18:00 GMT  
 Novice question about time functions

Quote:

> Mike ... you swing both ways ? I know you're still with Maureen (as
> evidenced by the email address), but what's with Jerry asking you to
> dispense with the button as you fill rect...      ;-)

I don't know why Jerry is mentioning the FillRect stuff, Hugh. Actually, I
don't remember filling his rectangle at all, but I suppose I must have done!

Maybe I was drunk ;-)

Mike



Mon, 16 Aug 2004 06:34:16 GMT  
 Novice question about time functions
On Wed, 27 Feb 2002 22:34:16 -0000, "Maureen"

Quote:



>> Mike ... you swing both ways ? I know you're still with Maureen (as
>> evidenced by the email address), but what's with Jerry asking you to
>> dispense with the button as you fill rect...      ;-)

>I don't know why Jerry is mentioning the FillRect stuff, Hugh. Actually, I
>don't remember filling his rectangle at all, but I suppose I must have done!

<just passing by looking the other way>
;-)

Regards, Frank



Mon, 16 Aug 2004 06:57:06 GMT  
 Novice question about time functions

Quote:

> Are there any functions in VB that deal with units of time less than a
> second? I want to write a program that tests the reaction times of people
> against each other and I thought, with the amount of computing power that is
> on a machine, that to just count empty loops the value of the counter would
> grow to big for the variable to quickly. If you know what I mean. Does
> anyone know how I can mesure the time it takes for a person to hit a button?
> I don't actually need a value in microseconds, a value that can be compared
> with the values of others would do.

Methinks there's a reason these things are usually written for
plain old DOS.  However, if you insist on Winblows, check out,

timeBeginPeriod
timeEndPeriod
timeGetTime

QueryPerformanceCounter
QueryPerformanceFrequency

Although by the time the GUI processes the events and tells you
about them, you may as well have been using Timer.  Anyway, you
hardly need 2.2Ghz Xeon-4s to get accurate timings if you don't
have a huge greedy bloated OS getting in the way. (Remember the
BASIC Stamp?) To squeeze decent accuracy from Winblows turnips,
be prepared to ben dover for Lose NT Embedded and un-lubed RTX:

 URL:http://www.vci.com/products/windows_embedded/rtx_features.asp

--
Joe Foster <mailto:jlfoster%40znet.com>  "Regged" again? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Tue, 17 Aug 2004 00:35:16 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Run-time creation of controls - novice question

2. Novice user MSComm run time error

3. NOVICE - LEFT PADDING FUNCTION

4. Time Function question???

5. Newbie Question on Date and time functions

6. Novice Ref Question

7. question from an Access novice

8. Creating User Forms - Novice question

9. Question from VBA novice re True and False values in VBA code for Word97

10. Unable to return ouput parameters to VB.net component - novice question

11. Return values from VB.net component - Novice Question

12. VB Interface Implementation - Novice Question

 

 
Powered by phpBB® Forum Software