|
-
Feb 23rd, 2000, 06:41 AM
#1
Thread Starter
Lively Member
-
Feb 23rd, 2000, 07:14 AM
#2
Hyperactive Member
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
-
Feb 23rd, 2000, 08:39 AM
#3
Hyperactive Member
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
-
Feb 23rd, 2000, 08:43 AM
#4
I think the Timer's interval should be 1000 (1 sec) to be fired every second.
-
Feb 23rd, 2000, 08:59 AM
#5
Hyperactive Member
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
-
Feb 23rd, 2000, 01:39 PM
#6
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|