Hi Pals could anyone show me how to code an active clock window
Thanks in advance

fourty

Dani AI

Generated

Quick summary and practical patterns for a running clock (digital or analog). and were right to use the system clock and a Timer; ’s OCX is an easy route for PNG-based hands. Two common pitfalls to watch for: VB6 format tokens (minutes are n, months are m) and timer accuracy/flicker when redrawing the UI. Below are small, reliable patterns you can drop into a VB6 form and adapt.

Digital — keep the display exactly in sync with the system clock
Use a short Timer (100–250 ms) but update the UI only when the second actually changes. That avoids cumulative drift if the Timer interval isn’t precise.

Private Sub Timer1_Timer()
    Static lastSecond As Integer
    Dim curSecond As Integer

    curSecond = Second(Now)
    If curSecond <> lastSecond Then
        lblClock.Caption = Format$(Now, "hh:nn:ss AM/PM")   ' nn = minutes in VB6
        lastSecond = curSecond
    End If
End Sub

Analog — draw hands into an offscreen PictureBox (AutoRedraw) to avoid flicker
Compute angles from the current time (seconds -> 6 degrees each, minutes + seconds/60, hours + minutes/60) and draw lines or bitmaps into a PictureBox with AutoRedraw = True. Refresh the visible control once per update.

' inside your update routine
Dim cx As Single, cy As Single, rSec As Single, a As Double
cx = picClock.ScaleWidth / 2
cy = picClock.ScaleHeight / 2
rSec = picClock.ScaleWidth * 0.45
a = (Second(Now) / 60#) * 2 * 3.14159265358979
picClock.Cls
picClock.Line (cx, cy)-(cx + Sin(a) * rSec, cy - Cos(a) * rSec), vbRed
picClock.Refresh

Troubleshooting notes

  • If the clock skips while your app is busy, move heavy work off the UI thread or use a multimedia timer (timeSetEvent) and post messages to the form.
  • For smooth second‑hand motion use higher update rates and interpolate minute/hour hand positions from seconds.
  • Always prefer Format$ with correct tokens (nn for minutes) to avoid locale/format surprises.

This gives a robust starting point you can extend (anti-aliasing, GDI+, pre-rotated bitmaps, or the OCX route from ).

Recommended Answers

All 7 Replies

if you mean: to show the current time of computer then please try this

text1.text = now ' show time & date
Text1.Text = Format(date, "dd/mm/yyyy") ' show date

Thanks Abu im going to try it but what i meant exactly is an active clock with the seconds tickin in real time..Let me try this first.
Thanks.


fourty

Do the following.
1. Add a Timer on the Form
2. Set the Timer Enable, Interval = 1000
3. Add this code

Private Sub Timer1_Timer()
Me.Caption = Format(Now, "s")
End Sub

This code will show you the current time seconds in the form caption or you might want to research on the GetTickCount API function.

Jhai, his looking for something similar to a analog wrist watch with a second, minute and hour arm.

This took me a while, so enjoy fourty (Some reputation points will help me as well...:$)

FIRST, copy the attached ocx to your windows system32 file.IMPORTANT, >>> remove the d from the .docx to make it ocx again. You then need to register the ocx by clicking on start, run, type in regsvr32 AlphaImageControl.ocx and click on ok.

Open the application attached and enjoy. You can use the alphaimage control royal free, I can't remember where I downloaded from, it was at a time when I had to include png images in my application. This image control can handle all of that and more. For more uses on the control, google AlphaImageControl.

If you want Analog clock follow Adrerets post if you want Digital Clock try below
Do the following.
1. Add a Timer on the Form
2. Set the Timer Interval = 1000
3. Add one Label on your form
4. Add this code

Private Sub Timer1_Timer()
      Label1.Caption = Format(Time, "HH:MM:SS AMPM")
      End Sub

Thanks

I like that Andre, see u on Monday,
By the way how did it go...?

Cool man. mmm, How did it go with?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.