|
-
Oct 1st, 2000, 03:32 PM
#1
Thread Starter
Lively Member
How do I make a timer?
I want it to count down from 500 until it gets to 0.
I have this code in my formload:
----------------
Do
Label3.caption = label3 - 1
loop
----------------
VB gets pissed off and crashes though... Am I doing something wrong?
-
Oct 1st, 2000, 10:48 PM
#2
Lively Member
Yep
The best way to do it is to use the timer object, though most people hate it, the code would be:
Code:
Dim intcount As Integer
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
intcount = 501
End Sub
Private Sub Timer1_Timer()
intcount = intcount - 1
If count <> 1 Then
Label1.Caption = intcount
Else
Timer1.Enabled = False
End If
End Sub
Hope this helps
-
Oct 2nd, 2000, 02:09 PM
#3
Thread Starter
Lively Member
Thanks
-
Oct 2nd, 2000, 02:14 PM
#4
Thread Starter
Lively Member
Um... How do I make it stop at 0 and not go to the - numbers?
-
Oct 2nd, 2000, 03:09 PM
#5
You can also do it without a Timer.
Code:
Sub CountDown(StartValue As Integer, lbl As Label)
lbl = StartValue
Do Until lbl = 0
Start = Timer
Do While Timer < Start + 1
DoEvents
Loop
lbl = lbl - 1
Loop
End Sub
Private Sub Command1_Click()
CountDown 10, Label1
End Sub
-
Oct 2nd, 2000, 06:21 PM
#6
Lively Member
If statement
Use and if statement to tell it the program it must be more than 0...
Code:
Dim intcount As Integer
Option Explicit
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
intcount = 501
End Sub
Private Sub Timer1_Timer()
intcount = intcount - 1
If count > 0 Then
Label1.Caption = intcount
Else
Timer1.Enabled = False
End If
End Sub
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
|