|
-
Oct 27th, 2000, 11:29 PM
#1
Thread Starter
Member
How can you make a counter start at a number, count down to 0(or any #) and display this countdown through a label.
-
Oct 27th, 2000, 11:34 PM
#2
Code:
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
For i = 1000 To 0 Step -1
Label1.Caption = i
Sleep 1: DoEvents
Next i
End Sub
-
Oct 28th, 2000, 05:38 AM
#3
Why do all that when a timer control can be used?
Anyway, doesnt the sleep function freeze the entire application for the set time?
-
Oct 28th, 2000, 09:34 AM
#4
Lively Member
Yeah, u could simply just put the code insidde the timer. (with the label.caption and counter values)
-
Oct 28th, 2000, 10:19 AM
#5
Why do all what? It ain't much.
I like my way. But if you insist...
Code:
Private Sub Timer1_Timer()
Label1.Caption = Val(Label1.Caption) - 1
End Sub
And sleep didn't seem to freeze me. Perhaps, the DoEvents came in?
-
Oct 29th, 2000, 12:40 AM
#6
Thread Starter
Member
all i wanted to have was a countdown that could be shown through a label. None of the code worked. I know how to countdown starting at 0. I want to start at five and countdown to 0. Please help!
-
Oct 29th, 2000, 01:02 AM
#7
Fanatic Member
Code:
'//Add Timer and Label to the Form
Option Explicit
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Form_Load()
Label1.Caption = 5
End Sub
Private Sub Timer1_Timer()
If Label1.Caption <> 0 Then
Label1.Caption = Label1.Caption - 1
Else
MsgBox "End of countdown"
Timer1.Enabled = False
End If
End Sub
'//HTH
Second version (it will stop the countdown at exactly zero not one second after (like previous code)
Code:
'//Add Timer and Label to the Form
Option Explicit
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
Private Sub Form_Load()
Label1.Caption = 5
End Sub
Private Sub Timer1_Timer()
If Label1.Caption > 1 Then
Label1.Caption = Label1.Caption - 1
ElseIf Label1.Caption = 1 Then
Timer1.Interval = 1
Label1.Caption = 0
ElseIf Label1.Caption = 0 Then
MsgBox "End of countdown"
Timer1.Enabled = False
End If
End Sub
'//HTH
[Edited by QWERTY on 10-29-2000 at 01:09 AM]
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
|