Lanc1988 Posted February 16, 2004 Posted February 16, 2004 I am looking for a very simple code to do a countdown in a label. I have a label on my form, a start, stop, reset buttons, and the TimerControl. So all i need is the code to have the timer control display in the label a countdown that when start is clicked will start counting down from 20 mins. :confused: can someone help me? Quote
GetYourAnswers Posted February 16, 2004 Posted February 16, 2004 Hi Lanc1988, Try This, Set the Timers Interval Property to 1000 milliseconds. Set the Timers Enabled Property to False. Declare a Variable as, Dim iMaxTime as Integer = 1200. Dim iMinutes as Integer = 20. In Start Buttons Click add Follwing Code: Timer1.Enabled = True In Stop Buttons Click add the following Code: Timer1.Enabled = False In Reset Buttons Click add the following Code: iMaxTime = 1200 iMinutes = 20 Label1.Text = "" In the Timers Event which will fire every 1 second add folowing code, If iMaxTime>0 then If IMaxTime Mod 60 = 0 then Label1.Text = IMinutes iMinutes-=1 End If End IF iMaxTime-=1 HOPE THIS WORKS OUT TRY IT!!! GetYourAnswers Quote
Lanc1988 Posted February 16, 2004 Author Posted February 16, 2004 it doesn't seem to be updating the label as it counts down. Quote
Moderators Robby Posted February 16, 2004 Moderators Posted February 16, 2004 place "Application.doevents" before this line "Label1.Text = IMinutes" Quote Visit...Bassic Software
Lanc1988 Posted February 16, 2004 Author Posted February 16, 2004 still doesn't update the time.. i have all of this in the Timer's code: 'Declare SkullTimer Variables Dim iMaxTime As Integer = 1200 Dim iMinutes As Integer = 20 Dim iSeconds As Integer = 60 'Sets timer to countdown from 20 mins. If iMaxTime > 0 Then If IMaxTime Mod 60 = 0 Then Application.DoEvents() Label3.Text = iMinutes iMinutes -= 1 End If End If iMaxTime -= 1 Quote
Lanc1988 Posted February 16, 2004 Author Posted February 16, 2004 (edited) could you post what i would add for it to show seconds also? like 20:00 (20 mins and 0 seconds) Edited February 16, 2004 by Lanc1988 Quote
Lanc1988 Posted February 17, 2004 Author Posted February 17, 2004 anyone know how to add seconds to it and get it to update the label every 1 second? Quote
Lanc1988 Posted February 18, 2004 Author Posted February 18, 2004 someone? any ideas at all? it seems like the label isnt updating itself every second.. Quote
TechnoTone Posted February 18, 2004 Posted February 18, 2004 Here's my version:form1.vb Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.