Clock making

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    #1

    Clock making

    Hi
    How to make clocks
    Analog and digital
    Can somebody help me
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    It depends on which version of VB you are using.

    In VB6 you can put a timer and set the interval to 1 second and show the time in a label with something like

    label1.caption = time

    Check the VB help file to see how to change the format.

    In VBA you don't have timers, so you'll have to work with DoEvents and an endless DO, something like

    Do
    label1.Caption = Time
    DoEvents
    Loop

    And for the analog clock just create some lines and change the coordinates of their ends (use some trigonometric functions to increase 6° the angle each time)

    Good Luck

    Comment

    • Ali Rizwan
      Banned
      Contributor
      • Aug 2007
      • 931

      #3
      Originally posted by kadghar
      it depends on wich version of VB ...
      Thanks but I want the digital clock made by dots means some dots will make numbers for the clock not displaying it in label.
      Last edited by Killer42; Aug 28 '07, 08:09 AM. Reason: Shortened excessive quote block

      Comment

      • Ali Rizwan
        Banned
        Contributor
        • Aug 2007
        • 931

        #4
        Originally posted by kadghar
        ... And for the analog clock just create some lines and change the coordinates of their ends (use some trigonometric functions to increase 6° the angle each time)
        Hi
        Can you give me a short example for analog clock
        I'll very thankful to you.
        May God bless you.
        Last edited by Killer42; Aug 28 '07, 08:26 AM. Reason: Shortened excessive quote block, removed "Plzzzzzz"

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          Originally posted by Ali Rizwan
          Thanks but I want the digital clock made by dots means some dots will make numbers for the clock not displaying it in label.
          You can make some picture boxes and add each the image or the dots you want to show.
          Use the functions Hour, Minute and Second to get each number.
          Suppose you have the numbers in picture boxes named as the number and make some cases:

          You can put something like this in your timer

          [CODE=vb]Select Case Hour(Time)
          Case 1
          picturebox1.Pic ture = one.Picture
          Case 2
          picturebox1.Pic ture = two.Picture
          ' (...and so on ...)
          End Select[/CODE]


          Originally posted by Ali Rizwan
          Hi
          Can you give me a short example for analog clock
          I'll very thankful to you.
          May God bless you
          Sure, just make 3 lines in VB (I don't know how to make them in VBA)
          Let's say the center of the clock is at 200, 200.

          Remember the formula for a circle is X^2 + Y^2 = r^2, and lets say that r (the length of the line) will be 50, and will be the minute hand

          x1 will always be 200
          y1 will always be 200 too

          The angle will be 90 - 6 * Minute(Time)
          And if this is negative let's just add 360 to it. Something like:

          Dim angle As Single
          angle = 90 - (6 * Minute(Time))
          If angle < 0 Then angle = angle + 360

          Now see then sin(angle) = Y/r and cos(angle) = X/r.
          Remember that you have your center at 200,200 and you're done:

          line1.X2 = 200 - r * Cos(angle)
          line1.Y2 = 200 - r * Sin(angle)

          Something like that should work, I didn't revise it since I have a lot of work here (sorry about that) but it's the main idea.

          Good Luck

          Comment

          • Ali Rizwan
            Banned
            Contributor
            • Aug 2007
            • 931

            #6
            Originally posted by kadghar
            You can make some picture boxes ... Good Luck
            Thanks a lot for all this
            Last edited by Killer42; Aug 28 '07, 08:07 AM. Reason: Shortened excessive quote block

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by Ali Rizwan
              Hi
              How to make clocks
              Analog and digital
              Can somebody help me
              Here's one I prepared earlier. :)

              About seven years earlier, to be precise. In VB3.

              Just add the form file to a new project, and run it.
              Attached Files

              Comment

              • Ali Rizwan
                Banned
                Contributor
                • Aug 2007
                • 931

                #8
                Originally posted by Killer42
                Here's one I prepared earlier. :)

                About seven years earlier, to be precise. In VB3.

                Just add the form file to a new project, and run it.
                Oh i see it but there is large coding behind it but thanks a lot it will help me lot.

                Comment

                • sephirote
                  New Member
                  • Aug 2007
                  • 3

                  #9
                  right click in the componentsand find digital clock and apply it in your form that's the way it is....so simple!try it....

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by Ali Rizwan
                    Oh i see it but there is large coding behind it but thanks a lot it will help me lot.
                    I would hardly call it "large" coding. And some of it can be removed. For example, I see there's code in there to stop waiting and update immediately if the user double-clicks on it or presses a key.

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #11
                      Originally posted by sephirote
                      right click in the componentsand find digital clock and apply it in your form that's the way it is....so simple!try it....
                      This must be a VB.Net thing, right?

                      Comment

                      Working...