Results 1 to 6 of 6

Thread: how do timers work???????

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    81

    Post

    Hello everyone im new to vb first timer and well as soon as im a first timer i would like someone to help me out with timers in vb how do they trigger and how do they work, could someone please send me some sample code so i can see how they trigger and how they trigger events

    thankyou in advance

  2. #2
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    The way a timer works is this. The only properties you really need to worry about (at least to begin with) are: Name, Enabled, and Interval. The Name property is obvious what it does. It's just the same as on every other control in VB and so is the Enabled property. However, the Interval is where you set how long you want the timer to wait before firing the code. You set the time in milliseconds, meaning that if you want it to fire every second, you would put 1000 in this box because a millisecond is 1/1000 of a second. Now as far as how it executes code, you just put the code into the timer that you want it to execute. As soon as the timer is activated it begins timing. Once it has reached the length of time that you specified in the Interval property. It then executes the code, and continues counting, and once it reaches the specified time again, it will fire the code again. It will continue this process until it is disabled. Additionaly, the Timer is considered activated once it is loaded on a form when you run a program (that is assuming the timer is enabled when the form is loaded). But if you disable the timer at design time and then enable at run-time then that is when it becomes activated and it counts from the moment that it is enabled. Hope that helps. Just put one on a form and try some things with it, that's the best way to figure out things in VB is to just try them. But, we are always here to help. Especially Newbies, because we were all newbies at one time.
    -Ryan
    I smell varmint poontang, and the only good varmint poontang is dead varmint poontang...

    -Bill Murray, Caddyshack

  3. #3
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    Gimpster, that was an explanation if I have ever read one here! Johnny, in my current project I am using a timer to show the time and date, and here is the code so that you have an example.

    Form1 has controls Label1 and Timer1 with Timer1's interval property set to 1 (1 second)

    Code:
    Private Sub Timer1_Timer()
    
    Label1.Caption = Now
    
    End Sub
    That code will make the label's caption show the system time, updated once per second.

    Edited by DrewDog_21 on 02-23-2000 at 08:39 PM

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    I think the Timer's interval should be 1000 (1 sec) to be fired every second.

  5. #5
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Yes, Serge is correct. The interval needs to be set to 1000 if you want it to fire every second. However, you wouldn't notice that in this example, becaue the time only changes every second, so even though the label is changing a thousand times per second, you only notice the change every second, because that's when the time changes.


    Form1 has controls Label1 and Timer1 with Timer1's interval property set to 1 (1 second)
    -Ryan
    I smell varmint poontang, and the only good varmint poontang is dead varmint poontang...

    -Bill Murray, Caddyshack

  6. #6
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    You never notice it changed a thousand times a second, but your processor sure will, and so other apps if you are multitasking. So it is useless to set time intervals shorter than needed. (No want to polemize, just to clear)

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