RSS

Create Analog Clock

To make Analog clock, please you make design Form As the following figure:

Please set the properties for the object Timer1 interval filled with a value of 1000.

Once you have set, please type the code as follows:

Public Const PI = 3.14159265358979

Enter the code above into the Object Module.

Here is a complete program code making Analog Clock.

Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim g As Integer
Dim s As Integer
Dim d As Integer
Dim i As Integer

Private Sub Command1_Click()
MsgBox Format(Now, "h am")
End Sub

Private Sub Form_Activate()
hora
pinta
End Sub

Private Sub Timer1_Timer()
hora
End Sub

Sub hora()
y = Val(Format(Now, "h"))
g = Val(Format(Now, "n"))
d = Val(Format(Now, "s"))

If y > 12 Then
    x = y - 12
Else
    x = y
End If

If g > 60 Then
    z = g - 59
Else
    z = g + 1
End If

If d > 60 Then
    s = d - 59
Else
    s = d
End If

pinta
End Sub

Sub pinta()
Cls

For i = 1 To 60
    Line (200 + Cos(0.10471 * i) * 100, 200 + Sin(0.10471 * i) * 100)-(200 + Cos(0.10471 * i) * 95, 200 + Sin(0.10471 * i) * 95), RGB(0, 255, 0)
Next i

For i = 1 To 12
    Line (200 + Cos(0.5235 * i) * 100, 200 + Sin(0.5235 * i) * 100)-(200 + Cos(0.5235 * i) * 90, 200 + Sin(0.5235 * i) * 90)
Next i

Circle (200, 200), 10, RGB(255, 0, 0)
Line (200 + Cos((x + 9) * 0.5235) * 60, 200 + Sin((x + 9) * 0.5235) * 60)-(200 + Cos(0.5235 * x) * 10, 200 + Sin(0.5235 * x) * 10), RGB(255, 0, 0)
Line (200 + Cos((x + 9) * 0.5235) * 60, 200 + Sin((x + 9) * 0.5235) * 60)-(200 + Cos(0.5235 * (x + 6)) * 10, 200 + Sin(0.5235 * (x + 6)) * 10), RGB(255, 0, 0)
Line (200 + Cos(0.10471 * (z + 45)) * 100, 200 + Sin(0.10471 * (z + 45)) * 80)-(200 + Cos(0.10471 * (z)) * 10, 200 + Sin(0.10471 * (z)) * 10), RGB(255, 0, 0)
Line (200 + Cos(0.10471 * (z + 45)) * 100, 200 + Sin(0.10471 * (z + 45)) * 80)-(200 + Cos(0.10471 * (z + 30)) * 10, 200 + Sin(0.10471 * (z + 30)) * 10), RGB(255, 0, 0)
Line (200 + Cos(0.10471 * (s + 45)) * 100, 200 + Sin(0.10471 * (s + 45)) * 80)-(200 + Cos(0.10471 * (s + 43)) * 10, 200 + Sin(0.10471 * (s + 43)) * 10)
Line (200 + Cos(0.10471 * (s + 45)) * 100, 200 + Sin(0.10471 * (s + 45)) * 80)-(200 + Cos(0.10471 * (s + 48)) * 10, 200 + Sin(0.10471 * (s + 48)) * 10)

End Sub

 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Posting Komentar