Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleFormat dates and draw an analog clock
DescriptionThis example shows how to format dates and draw an analog clock in Visual Basic 6. It uses the Format command to display the current year, month, date, and day of the week. When a Timer fires, it draws a simple analog clock.
Keywordsformat date, clock, analog clock
CategoriesGraphics, Strings
 
Thanks to Gamal Azim.

When the form loads, it dsplays the month, day of week, year, and date in Label controls.

 
Private Sub Form_Load()
    Label1.Caption = Format(Date, "mmmm")
    Label2.Caption = Format(Date, "dddd")
    Label3.Caption = Format(Date, "yyyy")
    Label4.Caption = Format(Date, "dd")
    '=============================
    y = P1.Height / 2
    x = P1.Width / 2
    w = P1.Width
End Sub
 
When a Timer fires, the program clears its P1 PictureBox and draws the current time. The point (x, y) is at the center of the PictureBox. It uses the Sin and Cos functions to see where the end points of the hour, minute, and second hands should be.
 
Private Sub Timer1_Timer()
    P1.Cls
    P1.DrawWidth = 4
    P1.Circle (x, y), w

    P1.DrawWidth = 4
    P1.Line (x, y)-(x + (900 * Sin(Hour(Now) * 3.1415 / _
        6)), y - (900 * Cos(Hour(Now) * 3.1415 / 6))), _
        vbBlack

    P1.DrawWidth = 3
    P1.Line (x, y)-(x + (1200 * Sin(Minute(Now) * 3.1415 / _
        30)), y - (1200 * Cos(Minute(Now) * 3.1415 / 30))), _
        vbBlue

    P1.DrawWidth = 1
    P1.Line (x, y)-(x + (1500 * Sin(Second(Now) * 3.1415 / _
        30)), y - (1500 * Cos(Second(Now) * 3.1415 / 30))), _
        vbRed
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated