I am brand new to programming, I've worked with computers for several years but decided to learn a new skill. I'd consider myself a hobbyist when it comes to programming. In any case, I've been working with the timer function and I want to make a simple clock that displays milliseconds, or tenths of a second, etc. There is nothing practical about this other than the educational factor. I may be trying to do something too advanced for my skill level and if so, then perhaps somebody could point me in the right direction for a newbie. I have made a simple desktop digital clock with no trouble, but I have scoured many websites and blogs, and have had no luck in figuring this out.

I'm using VB6.0 and have simply used a label and a timer to create the clock using a format of HH:MM:SS.

I appreciate any help or advice.


9 Years
Discussion Span
Last Post by Mach.80

Yes, I already have a digital clock that I completed. A fairly straight forward digital clock that just sits on the desktop. What I've been trying to do for about three days now is figure out how to make it display 10ths of a second or milliseconds. There is no real practical reason, other than for the pure fun of it and just learning more about the timer and so on.

Here is the code:

Private Sub Label1_Change()
Label1.Caption = Format(Time, "h:mm:ss AM/PM")
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Format(Time, "h:mm:ss AM/PM")
End Sub

Again, I'm brand new to this so my knowledge base is pretty much nil. I've been researching all over the internet and have not been able to find a way to display fractions of a second.

Thanks for any help.


Hey Folks,

I'm not trying to have someone give me the easy answer here, just a bit of help.

1: Can my original problem be solved VB6 (a clock displaying milliseconds, not a stopwatch)? 2: Can it be done with simple formatting or do I need more elaborate code to do this?
3: I am not taking a class or trying to take the easy road by stealing someones code here to build this clock for an assignment or anything like that.

I just need someone to point me in the right direction. I have a VB6 Complete reference book by Sibex and I scoured several sections in there but had no luck. Spent three days searching the internet and found some stuff for timers and stopwatches, but no clock. Again, this may be a task too advanced for my skill level. I'm just looking for a little bit of advice or a hint as to the type of code that needs to be used to do this, then I'll experiment and figure it out.

Thanks again,



Thanks Jx_Man. That's very similar to what I've come up with (just no calendar). Now my questions is how do I make that clock display 10th of a second or milliseconds since the Now() function or the Time() functions don't display that anything less than one second. I know that CPU clocks are accurate to about 12 - 15 milliseconds. So my questions is this: Can a clock be made to display the computer clock in real time, including the milliseconds? I'm sure it can, I just need to know where to start, what commands would be used, etc. Or is there a way to just use formatting? Then I'll experiment from there.



I've never tried this, so I don't know if or how well it would work. but ...

How about using a timer ??


I have a timer set to a 1 millisecond interval. The clock works fine, with hrs, minutes, seconds and the ampm. However, my question is how to get the clock to display tenths of a second. Is there a format setting I can use for this or would it have to be coded somehow.

I'm sure this can be done, I'm just trying to figure out how to get the time to display HHMMSS.miliseconds, or something similar.

Thanks to anyone with any advice.


Thanks to bushman_222 for the hint. Here is what I came up with. I couldn't get the the thousandth place on the milliseconds to display anything other than a zero, so settled for hundredths.

The code I used in its entirety:

Private Sub Timer1_Timer()
Label1.Caption = Format(Time, "hh:mm:ss.") & Right(Format(Timer, ".00"), 2)
End Sub

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.