Count down timer
Posted: Sun Jun 25, 2017 2:10 pm
So i've made this code in a project of mines, and i thought id share this piece of it.
Idk if there are any like this already, or better, but this was my method.
First, we declare 2 variables
Anything you guys dont understand about it, ill be glad to answer your questions
Idk if there are any like this already, or better, but this was my method.
First, we declare 2 variables
Code: Select all
Second, in form_load, we assign a value of your choice. My code counts from 7 Minutes, so ill go with 6:59
Dim seconds, minutes As Integer
Code: Select all
Now in a timer, that will be triggered by your choice, add this code
seconds = 59
minutes = 6
Code: Select all
Of course, i did use labels to display the time. They turn red at the 1 minute mark.If seconds >= 10 Then
Label30.Text = seconds
Else
Label30.Text = "0" & seconds
End If
Label29.Text = "0" & minutes
seconds -= 1
If minutes = 6 And seconds = 0 Then
minutes -= 1
seconds = 59
End If
If minutes = 5 And seconds = 0 Then
minutes -= 1
seconds = 59
End If
If minutes = 4 And seconds = 0 Then
minutes -= 1
seconds = 59
End If
If minutes = 3 And seconds = 0 Then
minutes -= 1
seconds = 59
End If
If minutes = 2 And seconds = 0 Then
minutes -= 1
seconds = 59
End If
If minutes = 1 And seconds = 0 Then
minutes -= 1
seconds = 59
End If
If minutes = 0 And seconds = 59 Then
Label28.ForeColor = Color.Red
Label29.ForeColor = Color.Red
Label30.ForeColor = Color.Red
Label31.ForeColor = Color.Red
End If
If minutes = 0 And seconds = 0 Then
Timer3.Stop()
MsgBox("Time's Up!")
Button1.PerformClick()
End If
Anything you guys dont understand about it, ill be glad to answer your questions