From: fniles on 14 Dec 2009 15:36 In our VB6 programs, we use the function Timer to calculate how long a process takes, like so: VB6 MyTime = Format(Now, "dd-MMM-yyyy HH:nn:ss") & "." & Right(Timer), 2) The timer function returns something like: 38624.73 Somebody on the forum explained that the 2 digit number after decimal point is actually centiseconds, or ten milliseconds. So on the example above .73 means 730 milliseconds. That means that smallest millisecond returns from the above Timer function is 10 milliseconds, any number between 1 - 9 milliseconds will not be returned. In VB6, is there a way to get up to 1 milliseconds ? Thank you.
From: Jeff Johnson on 14 Dec 2009 17:01 "fniles" <fniles(a)pfmail.com> wrote in message news:OGO9h0PfKHA.1824(a)TK2MSFTNGP04.phx.gbl... > In VB6, is there a way to get up to 1 milliseconds ? Karl has a library called High Performance Multimedia Timers, or something like that. What's his address, http://vb.mpvs.org?
From: Mike Williams on 14 Dec 2009 17:08 "fniles" <fniles(a)pfmail.com> wrote in message news:OGO9h0PfKHA.1824(a)TK2MSFTNGP04.phx.gbl... > In our VB6 programs, we use the function Timer to calculate > how long a process takes, like so: > The timer function returns something like: 38624.73 > Somebody on the forum explained that the 2 digit number > after decimal point is actually centiseconds, In VB6, is > there a way to get up to 1 milliseconds ? If you're timing how long a process takes then you don't really need the actual time, just the elapsed period, so you can use the multimedia API TimeGetTime function, using a suitable call to timeBeginPeriod to set the resolution to one millisecond. The timeGetTime function returns a Long containing the number of milliseconds that have elapsed since Windows was last started, so you don't need to add extra code to deal with wrap unless the system is left on continuously for more than a few weeks at a time. Alternatively, for resolutions better than one millisecond you can use the API QueryPeformanceCounter function. You need to take all actual timings with a pinch of salt of course in a multitasking system like Windoze. As far as the actual time is concerned (the system date and time) and various other associated timing functions (such as getTickCount) I think they have in the past been limited to a best resolution of about 15 milliseconds (or 55 milliseconds on some older version of Windows), but it appears that in Vista you can actually get a one millisecond resolution out of the system time. Check out the GetLocalTime and GetSystemTime functions. Here is an example (I've deliberately sent the results to a ListBox inside the test loop rather than outside it in order to slow down the loop so that you can more easily see the changing values when examining the ListBox output). On the machine I am currently using (Vista Home Premium) it is giving me timings to a resolution of one millisecond. Paste the example into a Form with a ListBox and a Command Button: Mike Option Explicit Private Declare Function timeBeginPeriod Lib "winmm.dll" _ (ByVal uPeriod As Long) As Long Private Declare Function timeEndPeriod Lib "winmm.dll" _ (ByVal uPeriod As Long) As Long Private Declare Sub GetLocalTime Lib "kernel32" _ (lpSystemTime As SYSTEMTIME) Private Type SYSTEMTIME wYear As Integer wMonth As Integer wDayOfWeek As Integer wDay As Integer wHour As Integer wMinute As Integer wSecond As Integer wMilliseconds As Integer End Type Private Sub Form_Load() timeBeginPeriod 1 End Sub Private Sub Form_Unload(Cancel As Integer) timeEndPeriod 1 End Sub Private Sub Command1_Click() Dim t As SYSTEMTIME, n As Long For n = 1 To 1000 GetLocalTime t List1.AddItem Format(n) & vbTab _ & t.wHour & ":" _ & t.wMinute & ":" _ & t.wSecond & ":" _ & t.wMilliseconds Next n End Sub
From: Karl E. Peterson on 14 Dec 2009 18:19 on 12/14/2009, fniles supposed : > In VB6, is there a way to get up to 1 milliseconds ? For a wrapper around what Mike suggests, see: http://vb.mvps.org/samples/StopWatch -- [.NET: It's About Trust!]
From: Dee Earley on 15 Dec 2009 04:25
On 14/12/2009 20:36, fniles wrote: > In our VB6 programs, we use the function Timer to calculate how long a > process takes, like so: > VB6 > MyTime = Format(Now, "dd-MMM-yyyy HH:nn:ss")& "."& Right(Timer), 2) > > The timer function returns something like: > 38624.73 > > Somebody on the forum explained that the 2 digit number after decimal point > is actually centiseconds, or ten milliseconds. > So on the example above .73 means 730 milliseconds. > That means that smallest millisecond returns from the above Timer function > is 10 milliseconds, any number between 1 - 9 milliseconds will not be > returned. > > In VB6, is there a way to get up to 1 milliseconds ? Again, try using the real code, what you "copied" blatantly does not compile. http://hashvb.earlsoft.co.uk/User:Dee/I_changed_the_code Further more, you are getting the right most two characters of an arbitrary precision decimal value converted to a string. This means the value you get could be any of these sets of chars: 12.3456 ^^ 12.345 ^^ 12.34 ^^ 12.3 ^^ ! 12 ^^ !!! Reiterating the other answers you've had, Timer() does not give the current time, it is seconds since boot up. If you want the real millisecond value, use GetLocalTime() and the wMilliseconds member. Remember this is real milliseconds so you need to format it with "000" if you want to append to a date/time string. Of course, from your original post, you're using .NET as well in which case, this code is almost entirely useless. it has native support for retrieving the milliseconds value iirc. -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems |