Tuesday, 14 February 2017

Code of Digital and Analog Clock

  1. Option Explicit
  2. Const T As Double = 57.29577951
  3.  
  4. Private Sub Form_Load()
  5. Me.Height = 7000
  6. Me.Width = 7000
  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
  16. Dim Hd As Double, Md As Double, Sd As Double
  17. Dim Hr As Double, Mr As Double, Sr As Double
  18. Dim x As Double, y As Double
  19. Dim p As Double, i As Double, a As Double, b As Double
  20. Dim x1 As Double, y1 As Double
  21. Me.Cls
  22. Me.Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), 49, vbBlack
  23. Me.Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), 48, vbBlack
  24. Me.FillStyle = 0
  25. Me.Circle (Me.ScaleWidth / 2, Me.ScaleHeight / 2), 1, vbBlack
  26. Me.FillStyle = 1
  27. x = Me.ScaleWidth - 4
  28. y = Me.ScaleHeight - 4
  29.  
  30. a = Me.ScaleWidth
  31. b = Me.ScaleHeight
  32. For i = 1 To 12
  33.     p = i * 30 - 90
  34.     If p < 0 Then p = p + 360
  35.     x1 = y / 2 + (y / 2 * 0.9 * Cos(p / T))
  36.     y1 = x / 2 + (y / 2 * 0.9 * Sin(p / T))
  37.     Me.CurrentX = x1 + 0.2
  38.     Me.CurrentY = y1 + 0.2
  39.     Me.Print i
  40. Next
  41. H = Hour(Time): M = Minute(Time): S = Second(Time)
  42. lblTime.Caption = "Current Time - " & H & ":" & M & ":" & S
  43. If H >= 12 Then H = H - 12
  44. Hd = H * 30
  45. Hd = Hd + M / 2
  46. Md = M * 6
  47. Sd = S * 6
  48.  
  49. Hd = Hd - 90: Md = Md - 90: Sd = Sd - 90
  50.  
  51. If Hd < 0 Then Hd = Hd + 360
  52. If Md < 0 Then Md = Md + 360
  53. If Sd < 0 Then Sd = Sd + 360
  54.  
  55. Hr = Hd / T: Mr = Md / T: Sr = Sd / T
  56.  
  57. Line (Me.ScaleWidth / 2, Me.ScaleHeight / 2)-(Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.75 * Cos(Hr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.75 * Sin(Hr))), vbBlack
  58. Line (Me.ScaleWidth / 2, Me.ScaleHeight / 2)-(Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.85 * Cos(Mr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.85 * Sin(Mr))), vbBlue
  59. Line (Me.ScaleWidth / 2, Me.ScaleHeight / 2)-(Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.8 * Cos(Sr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.8 * Sin(Sr))), vbRed
  60. Me.FillStyle = 0
  61. Me.Circle (Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.75 * Cos(Hr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.75 * Sin(Hr))), 1, vbBlack
  62. Me.Circle (Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.85 * Cos(Mr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.85 * Sin(Mr))), 1, vbBlue
  63. Me.Circle (Me.ScaleHeight / 2 + ((Me.ScaleHeight / 2) * 0.8 * Cos(Sr)), Me.ScaleWidth / 2 + ((Me.ScaleHeight / 2) * 0.8 * Sin(Sr))), 1, vbRed
  64. Me.FillStyle = 1
  65. End Sub
  66.  

No comments:
Write comments