Results 1 to 16 of 16

Thread: Time

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    Once my program starts, how would I get it to grab the time and have its own clock. I can do this however only be refreshing the label1.caption every second. There has to be a better method, any ideas?
    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604
    hi,

    create a timer, set the interval to 1000 and make sure that it is enabled, then put the following code in it

    label1.caption = time

    hope this helps


    Merlin ?

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    How frequently do you want to update?

    zmerlinz has told you how most of us would probably do the job. Having a timer set to 1000 milliseconds is not much of a burden on the system if that is what you are worried about.

    When he mentioned "put the following code in it", of course, he means ion the Timer1_Timer event.

    Regards
    Paul Lewis

  4. #4
    Addicted Member
    Join Date
    Jan 2000
    Location
    Oshkosh, WI
    Posts
    163
    If you just want a clock. Add a status bar control and set one the panel to be a clock.

    Glenn D
    Development/Analyst

  5. #5
    Guest
    Originally posted by PaulLewis
    How frequently do you want to update?
    The most you can update the standard clock is by 1 second. You would just be repeating many times if you went lower.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    As timer control is a very inaccurate timer (up to 53 ms), you may notice it won't update each second if you put interval to 1000ms. you may have to update it each 100 ms if you want to have a accurate looking clock or you would have to use a loop with a timer method or use settimer api
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Guest
    I don't think API is necessary for making a simple clock on the program. If you want it really accurate, just set the Timer's interval to 1.

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Long time ago when I still used timers to make clocks I setted it's interval to 200 or 300 so it nearly updates every second. To prevent flickering check if the label already contains the time:
    Code:
    Private Sub Timer1_Timer()
        If Not Label1.Caption = Time Then: Label1.Caption = Time
    End Sub

  9. #9
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    ' only refresh label when time has changed
    ' timer at intervals of whatever 100ms?

    timer1_timer()


    localtimer = format(datetime,"h:mm:ss")

    if localtimer <> lasttimer then
    label1.caption = localtimer
    lasttimer = localtimer

    end if

    exit sub
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If you want it really accurate, just set the Timer's interval to 1.
    Just by setting it to 1 you won't get it accurate less than 53 millisecond and the event will also fire less than 20 times a second
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11
    Guest
    That is a good thing, kedaman, because we are only concered with the accuracy of the second, not the milliseconds.

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If there's a visual purpose, you want to have the time to be updated using an event which won't be accurate if you use timer control, therefore by setting a small interval you will update it as accurate as possible.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Guest
    Yes, but that's what we want, as long as there is no flickering involved.

  14. #14
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Talking

    Clash of the Titans (GURU's)

    What's this about the staus bar being set to clock? I've never heard of that!! Thanks's Glen. Think it's time to have a play...

    Paul
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  15. #15
    Guest
    Try something like this.

    Code:
    Private Sub Timer1_Timer()
    
        StatusBar1.Panels(1).Text = Time
    
    End Sub

  16. #16
    Addicted Member
    Join Date
    Jan 2000
    Location
    Oshkosh, WI
    Posts
    163
    Unless you require a clock with seconds you don't need to use a timer with the status bar. Just set the style property of the panel to sbrTime.

    Glenn D
    Development/Analyst

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width