I should have mentioned that CCRP has an outstanding Timer Control that facilitates calculating elapsed time. The control is written by Karl E. Peterson
Credit where credit is due!
But as my son would say, No credit. Cash only.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Elapsed Time Function – Update
[indent]
Edit : The information in this post regarding an undocumented feature (the :ms Format() function expression) is incorrect. Please see post by Timbo below for a solution that works. Kevin regrets any harm that may have come to your children due to his error
[/indent]
I discovered what appears to be an undocumented item that solved (I think it solved) my problem: how to calculate an elapsed time and display the results with milliseconds.
TimeStart = Time
.
.
.Do the loop, etc.
.
.
TimeLapsed = Time – TimeStart
txtTimer.Text = Format(TimeLapsed, “ss.ms“)
The “undocumented” item is the ‘ms’ in the format statement. I could find nothing about this in VBA help, MSDN or any number of sites. But while looking at the CCRP Timer Control, I noticed they used the VB Format statement with ms for milliseconds. I tried it and it works in VBA.
Just thought you might like to know…
OK. You’re the public TIMER expert. I grabbed a copy of your efforts, for which thanks.
Is this the most precise time I can expect to capture in Word97SR2/VBA or are you aware of an even finer time.
I suspect that milliseconds will do me for now, but if there were a Micro-second or chunks-of, I’d as well use that.
Nothing urgent. Just get back to me by 5pm.
On mille-second thoughts, make that 17:00:00.000
Hey, man cut me some slack. I was at the dentist this am. They don’t have IP terminals there. Not a bad idea, though, for a new company: Put doctor, dentist, etc offices on the net for patrons to use in the waiting room. The money saved on magazine subscriptions would help pay for the service. You heard it first right here on Woody’s Lounge.
Are you sure? I used format(time, “ss.ms”) and all it gave me was the number of seconds follows by a dot followed by the month number followed by the number of seconds again.
Sort of like 33.1133.
I put together the following which gives me hh:mm:ss.milliseconds and seems to work ok.
Dim lrTimer As Double Dim lrCurrTime As Double Dim lrMilliseconds As Double lrTimer = Timer lrMilliseconds = lrTimer - Int(lrTimer) lrCurrTime = int(lrTimer) / (24& * 60& * 60&) msgbox Format(lrCurrTime, "hh:mm:ss") & _ Format(lrMilliseconds, ".00 - ") & _ Message
I haven’t tried your code, but it does not look like it will give you what you are looking for. The first thing that I see is that you are getting a two digit milliseconds, and that does not make sense. There are 1,000 milliseconds in a second. What you are actually displaying is hundredths of a second, not milliseconds.
You don’t say what Timer contains. If it contains seconds, the the rest of your code makes sense. However, if it contains a DateTime value, the rest of the code does not give you what you say it does.
Yes, you are quite correct, it should be deciseconds, not milliseconds. With regards to timer, its a VB / VBA function that comes with the language. Do I have to describe it. Oh ok, here is what I lifted out of the help …
Returns a Single representing the number of seconds elapsed since midnight.
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications