Making Countdown Timer
In this tutorial you will learn to make a countdown timer. Open Visual Basic 6.0 and select STANDARD .EXE .
Add 3 Labels (lblCD visible = false,label1 & label2) , 1 Command Button , 1 timer (Interval 1000 , Enabled = False) , 2 Textboxes . Like me.
Lets write the code now:
Private Sub Command1_Click()
Timer1.Enabled = True
lblCD.Visible = True 'lbl is visible
lblCD.Caption = Text1.Text 'lbl caption number is write you typed in text1
Command1.Enabled = False
Text1.Enabled = False
Text2.Enabled = False
End Sub
Private Sub Timer1_Timer()
On Error GoTo a:
If lblCD.Caption = 0 Then
Timer1.Enabled = False 'when Countdowning is finished timer1 enabled is false
Command1.Enabled = True 'when Countdowning is finished command1 enabled is true
Text1.Enabled = True 'when Countdowning is finished text1 enabled is true
Text2.Enabled = True 'when Countdowning is finished text2 enabled is true
If Text2.Text = "" Then
MsgBox (Text1.Text), vbInformation, "Countdown Timer" 'show default text in MSGBOX
MsgBox "Seconds passed.", vbInformation, "Countdown Timer"
Else
MsgBox (Text2.Text), vbInformation, "Countdown Timer" 'show text2.text in MSGBOX
End If
Else
lblCD.Caption = lblCD.Caption - 1 'start countdowning.
End If
a:
End Sub
If you have any questions , suggestions or if you find bugs just comment !
HAVE A NICE DAY!
Post a Comment