Design an Analog clock in vb

Page 1 of 1

11 Replies - 14198 Views - Last Post: 04 December 2009 - 09:53 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=142642&amp;s=4c11bdf1a218c554fcf0740d29377abe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Estherobed

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 01-December 09

Design an Analog clock in vb

Posted 01 December 2009 - 11:36 AM

```Private Sub Form_Load()
linesec.X1 = Cos((Second(Now) * 3.14 / 30) - 3.14 / 2) * 1400 + linesec.X2
linesec.Y1 = Sin((Second(Now) * 3.14 / 30) - 3.14 / 2) * 1400 + linesec.Y2
Linemin.X1 = Cos((Minute(Now) * 3.14 / 30) - 3.14 / 2) * 1100 + Linemin.X2
Linemin.Y1 = Sin((Minute(Now) * 3.14 / 30) - 3.14 / 2) * 1100 + Linemin.Y2
Linehour.X1 = Cos(((Hour(Now) * 30) + Minute(Now) / 2) * 3.14 / 180 - 3.14 / 2) * 700 + Linehour.X2
Linehour.Y1 = Sin(((Hour(Now) * 30) + Minute(Now) / 2) * 3.14 / 180 - 3.14 / 2) * 700 + Linehour.Y2
Label5.Caption = Time
End Sub

Private Sub Timer1_Timer()
linesec.X1 = Cos((Second(Now) * 3.14 / 30) - 3.14 / 2) * 1400 + linesec.X2
linesec.Y1 = Sin((Second(Now) * 3.14 / 30) - 3.14 / 2) * 1400 + linesec.Y2
Linemin.X1 = Cos((Minute(Now) * 3.14 / 30) - 3.14 / 2) * 1100 + Linemin.X2
Linemin.Y1 = Sin((Minute(Now) * 3.14 / 30) - 3.14 / 2) * 1100 + Linemin.Y2
Linehour.X1 = Cos(((Hour(Now) * 30) + Minute(Now) / 2) * 3.14 / 180 - 3.14 / 2) * 700 + Linehour.X2
Linehour.Y1 = Sin(((Hour(Now) * 30) + Minute(Now) / 2) * 3.14 / 180 - 3.14 / 2) * 700 + Linehour.Y2
Label5.Caption = Time

End Sub
```

*** MOD EDIT: Added code tags. Please ***

This post has been edited by JackOfAllTrades: 01 December 2009 - 11:40 AM

Is This A Good Question/Topic? 0

Replies To: Design an Analog clock in vb

• Saucy!

Reputation: 6180
• Posts: 23,882
• Joined: 23-August 08

Re: Design an Analog clock in vb

Posted 01 December 2009 - 11:42 AM

Please tell us what your errors are, and/or how the program is behaving differently from what you expect.

#3 Estherobed

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 01-December 09

Re: Design an Analog clock in vb

Posted 01 December 2009 - 02:31 PM

JackOfAllTrades, on 1 Dec, 2009 - 10:42 AM, said:

Please tell us what your errors are, and/or how the program is behaving differently from what you expect.

1. When running this program , the hands of clock was located in different location. (ie) hands are broken. hour hand is in one side & sec hand is in another side, min hand is another location.
2. i need analog clock with circle shape, denoting the time

This post has been edited by Estherobed: 01 December 2009 - 02:33 PM

• MrCupOfT

Reputation: 2290
• Posts: 9,528
• Joined: 29-May 08

Re: Design an Analog clock in vb

Posted 01 December 2009 - 02:37 PM

Have also tried setting the position of the other point in the line. eg Line1.X2 & Line2.Y2.

#5 bytelogik

Reputation: 22
• Posts: 212
• Joined: 06-October 09

Re: Design an Analog clock in vb

Posted 02 December 2009 - 12:05 PM

1) Set X1 and Y1 of all the three lines to one location in the Form_Load()
Calculate only the X2 and Y2 locations based on the time.

2) Use the Shape control for circle. Set the Shape property to "Circle"

#6 thava

• D.I.C Lover

Reputation: 180
• Posts: 1,606
• Joined: 17-April 07

Re: Design an Analog clock in vb

Posted 02 December 2009 - 12:17 PM

set all your lines x2 and y2 at the same point because the points x1 and y1 are varied not the point x2 and y2 this means x2 and y2 is the center of the
clock
based on this center you can draw a circle also

still unable to understand go to the tutorial section search for this

#7 bytelogik

Reputation: 22
• Posts: 212
• Joined: 06-October 09

Re: Design an Analog clock in vb

Posted 02 December 2009 - 12:49 PM

@thava : He has set all the lines in design time. It's obvious that it is appropriate to use a 2D variable to store the center of rotation for the lines so that, if the clock has to be displaced, it will be easier.
Generally, we use the end point to be varied, and not the start point of the line. But, it may differ with the programmers wish.

#8 thava

• D.I.C Lover

Reputation: 180
• Posts: 1,606
• Joined: 17-April 07

Re: Design an Analog clock in vb

Posted 02 December 2009 - 06:48 PM

@byte:
yes i know that , he just ask that his lines where broken some where else
in the run time, that's why i suggest that solution

#9 bytelogik

Reputation: 22
• Posts: 212
• Joined: 06-October 09

Re: Design an Analog clock in vb

Posted 02 December 2009 - 11:38 PM

#10 Estherobed

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 01-December 09

Re: Design an Analog clock in vb

Posted 03 December 2009 - 04:25 AM

AdamSpeight2008, on 1 Dec, 2009 - 01:37 PM, said:

Have also tried setting the position of the other point in the line. eg Line1.X2 & Line2.Y2.

Thanks for everbody's reply to me. i can understand all of their concepts. but i don;t know to implement it. pls guide me.

#11 thava

• D.I.C Lover

Reputation: 180
• Posts: 1,606
• Joined: 17-April 07

Re: Design an Analog clock in vb

Posted 04 December 2009 - 02:17 AM

just read my previous post

i don't think there is a simple way than this

#12 bytelogik

Reputation: 22
• Posts: 212
• Joined: 06-October 09

Re: Design an Analog clock in vb

Posted 04 December 2009 - 09:53 AM

Study the following examples:

http://www.planet-so...p...94&lngWId=1

http://www.planet-so...p...38&lngWId=1

http://www.planet-so...p...15&lngWId=1