VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

Visual Basic Source Code


Welcome to Dream.In.Code
Become a VB Expert!

Join 340,154 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 3,980 people online right now. Registration is fast and FREE... Join Now!




Analog Clock

Nice, easy analog clock code.

Submitted By: tel0r
Actions:
Rating:
Views: 28,818

Language: Visual Basic

Last Modified: June 19, 2005
Instructions: c&p code, add timer control (Timer1) to the form with an Interval of 1000, and Enabled set to True

Snippet


  1. Option Explicit
  2. Const T As Double = 57.29577951
  3.  
  4. Private Sub Form_Load()
  5. Me.Height = 2048
  6. Me.Width = 2048
  7. End Sub
  8.  
  9. Private Sub Form_Resize()
  10. Me.ScaleHeight = 100
  11. Me.ScaleWidth = 100
  12. End Sub
  13.  
  14. Private Sub Timer1_Timer()
  15. Dim H As Long, M As Long, S As Long                     'time units
  16. Dim Hd As Double, Md As Double, Sd As Double            'Degrees
  17. Dim Hr As Double, Mr As Double, Sr As Double            'Radians
  18.  
  19. Me.Cls
  20. H = Hour(Time): M = Minute(Time): S = Second(Time)
  21.  
  22. If H >= 12 Then H = H - 12
  23.  
  24. Hd = H * 30
  25. Hd = Hd + M / 2
  26. Md = M * 6
  27. Sd = S * 6
  28.  
  29. Hd = Hd - 90: Md = Md - 90: Sd = Sd - 90
  30.  
  31. If Hd < 0 Then Hd = Hd + 360
  32. If Md < 0 Then Md = Md + 360
  33. If Sd < 0 Then Sd = Sd + 360
  34.  
  35. Hr = Hd / T: Mr = Md / T: Sr = Sd / T
  36.  
  37. Line (50, 50)-(Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.5 * Cos(Hr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.5 * Sin(Hr))), vbBlack
  38. Line (50, 50)-(Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.6 * Cos(Mr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.6 * Sin(Mr))), vbBlue
  39. Line (50, 50)-(Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.7 * Cos(Sr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.7 * Sin(Sr))), vbRed
  40.  
  41. End Sub
  42.  

Copy & Paste


Comments

bonzo0 2008-07-09 08:06:36

there are no digits to represent 1 to 12. only the hands are moving.

jakerman999 2008-08-08 15:15:50

disable the max button and min button, then add the following code. Dim strTime As String Dim strH As String, strM As String, strS As String strH = H strM = M strS = S If H < 10 Then strH = "0" & H If M < 10 Then strM = "0" & M If S < 10 Then strS = "0" & S strTime = strH & ":" & strM & ":" & strS Form1.Caption = strTime also, try placing your dim statements in the general section instead of the timer control, otherwise you use to much ram.

OMI 2008-10-10 17:56:43

Thank u for lending me this code

arjay_cabingas 2008-11-25 05:31:51

ohhh...this site are so very helpful because you can get more of codes as you like...... thank......guysss.....dont worry friends i would help you if i knew.......

Vineeth k 2009-10-26 00:54:14

Thanks for the code really i am looking for this code.Thanks for sharing this..


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month