Design an Analog clock in vb

when run this code in vb, i can't get perfect result

Page 1 of 1

11 Replies - 12101 Views - Last Post: 04 December 2009 - 09:53 AM Rate Topic: -----

#1 Estherobed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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 :code: ***

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

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 Estherobed  Icon User is offline

  • New D.I.C Head

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

Re: Design an Analog clock in vb

Posted 01 December 2009 - 02:31 PM

View PostJackOfAllTrades, 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

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,469
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 bytelogik  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • 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"
Was This Post Helpful? 0
  • +
  • -

#6 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#7 bytelogik  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#8 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#9 bytelogik  Icon User is offline

  • D.I.C Head

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

Re: Design an Analog clock in vb

Posted 02 December 2009 - 11:38 PM

:)
Was This Post Helpful? 0
  • +
  • -

#10 Estherobed  Icon User is offline

  • New D.I.C Head

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

Re: Design an Analog clock in vb

Posted 03 December 2009 - 04:25 AM

View PostAdamSpeight2008, 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.
Was This Post Helpful? 0
  • +
  • -

#11 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#12 bytelogik  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1