Ah well, it had to happen.
Create a new form, minimum size 14cm by 14cm.
Anywhere on the form, place 3 lines of any length called scrLineSecond,
scrLineMinute and scrLineHour.
Set the form's TimerInterval to 1000.
In the OnTimer event, past the following:
Private Sub Form_Timer()
Call calcClockHands("Second", Second(Now()))
Call calcClockHands("Minute", Minute(Now()))
Call calcClockHands("Hour", Hour(Now()))
End Sub
Then paste in the following sub:
NOTE: The calculation (7 * 567) is 7cm * 567 twips per centimetre and
marks the centre of the form. If you work in other units you will have
to change them accordingly. 3750 is the length of the secondhand in
twips, 3500 the length of the minute hand, and 2750 the length of the
hour hand. Again, change these to suit yourself.
Private Sub calcClockHands(parHand As String, x As Integer)
Const pi = 3.142857
Const nCentreLeft = (7 * 567), nCentreUp = (7 * 567)
' This code copyright Ray Corbin 2006
' Blue Bridge Pty Ltd, Sydney Australia ra*@aic.net.au
' Use wherever provided you include this accreditation.
Dim nWidth As Single, nHeight As Single
On Error GoTo CH_Err
Select Case parHand
Case "Second"
nWidth = 3750 * Sin(84 * pi * x)
nHeight = 3750 * Cos(84 * pi * x)
Case "Minute"
nWidth = 3500 * Sin(84 * pi * x)
nHeight = 3500 * Cos(84 * pi * x)
Case "Hour"
nWidth = 2750 * Sin(412 * pi * x)
nHeight = 2750 * Cos(412 * pi * x)
End Select
Me("scrLine" & parHand).LineSlant = (Abs(nWidth * nHeight) =
(nWidth * nHeight))
Me("scrLine" & parHand).Width = Abs(nWidth)
Me("scrLine" & parHand).Height = Abs(nHeight)
If nWidth > 0 Then
Me("scrLine" & parHand).Left = nCentreLeft
Else
Me("scrLine" & parHand).Left = nCentreLeft + nWidth
End If
If nHeight > 0 Then
Me("scrLine" & parHand).Top = nCentreUp - nHeight
Else
Me("scrLine" & parHand).Top = nCentreUp
End If
CH_Exit:
Exit Sub
CH_Err:
MsgBox Err.Description
Resume CH_Exit
End Sub
Tick Tock folks,
Ray