Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Counting milliseconds in VB6 ?

738 views
Skip to first unread message

Jean-Marc

unread,
May 17, 2002, 5:14:50 PM5/17/02
to
Hello all
Is there anyone who knows how to count milliseconds in VB6 ?
That would be most appreciated. Thanks.

Jean-Marc


Moin Ul Haque

unread,
May 18, 2002, 4:35:56 AM5/18/02
to
There is an API call GetTickCount that returns the total number of ticks
elapsed since the system's last boot.
What usually is done is that u get tickcount at the first instance and save
it somewhere. This serves as the initial pointer of time or u can call it
the start of the Stopwatch. Whenever u want to stop the stopwatch get
another tickcount and subtract the first one from it to get the number of
milliseconds elapsed since the last tickcount get.

Here is the sample code

==============================================
' This goes in the general declarations bas module
'
Public Declare Function GetTickCount Lib "kernel32" () As Long
==============================================

' Now this is the form code
==============================================
Option Explicit

Private Sub Form_Click()
Static LastCnt As Long
Static ThisCnt As Long
Dim TimeElapsed As Long

If LastCnt = 0 Then
LastCnt = GetTickCount()
End If
ThisCnt = GetTickCount

TimeElapsed = ThisCnt - LastCnt
MsgBox TimeElapsed & " seconds have elapsed since last click", vbOKOnly
+ vbInformation
End Sub

--

Regards,
Moin Ul Haque
moin_u...@hotmail.com
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
"Jean-Marc" <jean...@nospam.com> wrote in message
news:uJ0Qcce$BHA.1880@tkmsftngp02...

Moin Ul Haque

unread,
May 18, 2002, 4:53:53 AM5/18/02
to
I am not sure if the tickcount is maped exactly in milliseconds or not. I
remember there was some formula for mapping it to milliseconds.
Please double check that on MSDN.
--

Regards,
Moin Ul Haque
moin_u...@hotmail.com

03008...@mobilinkgsm.com


This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.

"Moin Ul Haque" <moin_u...@hotmail.com> wrote in message
news:u7YPQ7j$BHA.2044@tkmsftngp04...

Moin Ul Haque

unread,
May 18, 2002, 5:44:16 AM5/18/02
to
I checked the docs and the tickcount is exactly the number of milliseconds
elapsed since the system was started. Sorry for the last post.

--

Regards,
Moin Ul Haque
moin_u...@hotmail.com
03008...@mobilinkgsm.com
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.

"Jean-Marc" <jean...@nospam.com> wrote in message
news:uJ0Qcce$BHA.1880@tkmsftngp02...

Dick Grier

unread,
May 18, 2002, 11:49:58 AM5/18/02
to
Hi,

You should use the timeGetTime API. GetTickCount does not provide mS
resolution (claims aside). While GetTickCount returns the number of mS in a
granular fashion, its resolution varies from 10 to 55 mS.

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

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.

Egbert Nierop (MVP for IIS)

unread,
May 18, 2002, 4:56:32 PM5/18/02
to
performance counters are able to have that resolution.
Eduardo Morcillo had a VB class that was able to do the trick.
http://www.domaindlx.com/e_morcillo

--
The scalable ASP Session replacement for webfarms
http://www.nieropwebconsult.nl/asp_session_manager.htm

"Dick Grier" <dick_gri...@msn.com> wrote in message
news:Oc7E1Qo$BHA.1836@tkmsftngp05...

Joe "Nuke Me Xemu" Foster

unread,
May 19, 2002, 12:18:50 PM5/19/02
to
"Jean-Marc" <jean...@nospam.com> wrote in message <news:uJ0Qcce$BHA.1880@tkmsftngp02>...

> Is there anyone who knows how to count milliseconds in VB6 ?

And I suppose you're going to want the answer RightNow, huh?

URL:http://groups.google.com/groups?selm=%23kmFSP1tBHA.2676%40tkmsftngp04

URL:http://groups.google.com/groups?selm=eIFcts0qBHA.2080%40tkmsftngp03

However, you might get millisecond precision, but not millisecond accuracy!

URL:http://groups.google.com/groups?selm=3CB4D43B.23B3%40cluestick.org

(For anyone who might be a bit fuzzy about the difference between precision
and accuracy, contemplate this: 2 + 2 = 3.141590008675309000090210000666 )

--
Joe Foster <mailto:jlfoster%40znet.com> Space Cooties! <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!


Dick Grier

unread,
May 20, 2002, 1:19:28 PM5/20/02
to
Hi,

The problem with the Performance Counters is that they advertize much better
resolution than they provide. Their accuracy varies a LOT with system
loading, and is not even close to the advertized resolution.

0 new messages