471,573 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,573 software developers and data experts.

Analogue Clock

ray
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

May 4 '06 #1
7 6306
<ra*@aic.net.au> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Ah well, it had to happen.


A truly ingenious piece of coding, but what possible use do you see this
having?

Regards,
Keith.
www.keithwilby.com
May 4 '06 #2
<ra*@aic.net.au> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Const pi = 3.142857


That's some funny pie you are feeding Access. It'll get indigestion! :)

Matt
May 4 '06 #3
ray
Keith, I appreciate the 'ingenious' label! I must confess that I
originally wanted a second hand ticking around a tiny clockface in the
bottom corner of a form, but really it was just a bit of fun. Mind you,
there may be people who require analogue displays of something other
than a clock. This could be easily adapted to show a gauge.

I adapted it yesterday by removing the code from TimerEvent. I took out
the Hour, Minute, Second functions and substituted integer values
looping through 1-12 and 1-60 that ran the clock as fast as it could. I
was quite surprised at how fast it whizzed around!

Incidentally, though, I often find that clients look on Access as a bit
of a 'toy' database, slow and small. It can be displays like this,
paradoxically enough, that stop them as they walk past (this happened a
lot over the last few days with the hands on my clockface spinning
around like a mad thing) and they say "I didn't know Access could do
stuff like that." It gives me a chance to spruik the environment up a
bit, and extend their thinking.

Matt, yes the pi value is a bit berserk!! I didn't look it up at the
time, just tossed it in from memory.

Thanks for your interest folks,

Ray

May 5 '06 #4
Rog
Great stuff, Ray. Thanks for sharing this. It looks great if you give
the three lines different colors.

BTW I think there's a typo in the line
Me("scrLine" & parHand).LineSlant = (Abs(nWidth * nHeight) =
(nWidth * nHeight))
The second = should be a +.

Rog

May 8 '06 #5
"Rog" <de********@state.gov> wrote in
news:11**********************@y43g2000cwc.googlegr oups.com:
Great stuff, Ray. Thanks for sharing this. It looks great if
you give the three lines different colors.

BTW I think there's a typo in the line
Me("scrLine" & parHand).LineSlant = (Abs(nWidth * nHeight)
=
(nWidth * nHeight))
The second = should be a +.

Rog

I think not.

The LineSlant property uses the following settings.

Setting Visual Basic Description
\ False (Default) Upper left to lower right
/ True Upper right to lower left

(Abs(nWidth * nHeight) = (nWidth * nHeight))
returns true or false. It's an absolutely brilliant bit of code.

--
Bob Quintal

PA is y I've altered my email address.
May 8 '06 #6
Rog
I see, you're right. Sorry, my mistake.

Roger

May 10 '06 #7
"Rog" <de********@state.gov> wrote in news:1147178624.065097.201350
@i39g2000cwa.googlegroups.com:
I see, you're right. Sorry, my mistake.

Roger

No need to be sorry.
--
Bob Quintal

PA is y I've altered my email address.
May 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by James Harriman | last post: by
9 posts views Thread by Gino Elloso - Philippines | last post: by
reply views Thread by Peger, Daniel H. | last post: by
33 posts views Thread by Pushkar Pradhan | last post: by
7 posts views Thread by Oleg Subachev | last post: by
54 posts views Thread by CoreyWhite | last post: by
12 posts views Thread by cenktarhancenk | last post: by
5 posts views Thread by none | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.