How do I make a label countdown, from data from another form, where you input a number in a text box, The number equaling Minutes. and the countdown in HH:MM:SS format.. :bigyello:
Printable View
How do I make a label countdown, from data from another form, where you input a number in a text box, The number equaling Minutes. and the countdown in HH:MM:SS format.. :bigyello:
:eek2:
Here si a quicky for you TT:
you will need a Command button, Timer and Label to run sample.
VB Code:
Option Explicit Dim lngMinutes As Long Private Sub Command1_Click() Dim strMinutes$, sTime$ strMinutes = InputBox("Type number of minutes.", "Countdown", "60") If Not IsNumeric(strMinutes) Then MsgBox "Cannot begin count down - invalid number." Exit Sub Else lngMinutes = CLng(strMinutes) End If sTime = Str$(lngMinutes * 60 \ 3600) & " hours " & _ Str$(lngMinutes * 60 Mod 60) & " minutes " & _ Str$(lngMinutes * 60 Mod 60) & " seconds " Label1.Caption = sTime Timer1.Enabled = True Timer1.Interval = 60000 '1 minute End Sub Private Sub Form_Load() Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Dim sTime$ Static lSeconds& lngMinutes = lngMinutes - 60 lSeconds = lngMinutes * 60 sTime = Str$(lSeconds \ 3600) & " hours " & _ Str$(lSeconds \ 60) & " minutes " & _ Str$(lSeconds Mod 60) & " seconds " Label1.Caption = sTime End Sub
hey thanks for the reply, i tested it and for 60 mins.. Says 1 hour then goes to 0, then nothin happens lol :x how i would i get it to say the seconds as they pass...
That is only a sample and you should have tried to work it out but here is another (modified) "version":
VB Code:
Option Explicit Dim lngMinutes As Long Private Sub Command1_Click() Dim strMinutes$, sTime$ strMinutes = InputBox("Type number of minutes.", "Countdown", "60") If Not IsNumeric(strMinutes) Then MsgBox "Cannot begin count down - invalid number." Exit Sub Else lngMinutes = CLng(strMinutes) End If sTime = Str$(lngMinutes \ 60) & " hours " & _ Str$(lngMinutes Mod 60) & " minutes " & _ Str$(lngMinutes * 60 Mod 60) & " seconds " Label1.Caption = sTime Timer1.Enabled = True Timer1.Interval = 1000 '1 second End Sub Private Sub Form_Load() Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Dim sTime$ Static lSeconds& If lSeconds = 0 Then lSeconds = lngMinutes * 60 sTime = Str$(lSeconds Mod 3600) & " hours " & _ Str$(lSeconds \ 60) & " minutes " & _ Str$(lSeconds Mod 60) & " seconds " Else lSeconds = lSeconds - 1 sTime = Str$(lSeconds \ 3600) & " hours " & _ Str$(lSeconds \ 60) & " minutes " & _ Str$(lSeconds Mod 60) & " seconds " End If Label1.Caption = sTime If lSeconds = 0 Then Timer1.Enabled = False End Sub
This the answer
VB Code:
Label1.Caption=format(time, "hh:mm:ss"
Set the interval to 1000 :thumb:
That would just give you a current system time which isn't what TrueThreat asked for: he needs to begin a countdown from a given point (say 40 minutes left, then 39 min and 57 seconds and so on ...)
Sorry RhinoBull i thought that is code..
You don't have to be sorry - I don't have any problem with someone's trying to help. :wave:
ok it works good, thanks but theres a slight problem, i want it in the format hh:mm:ss, which i got it, but like 01:00:00 then it goes to 00:60:00 lol so its like 60 mins + an extra second, why is it doing this? :x thanks again for the help :bigyello:
bump.. lol why does it go from 01:00:00 to 01:60:00 then 00:59:00 when it should go straight to 59.. :ehh:
heres a different approach.
VB Code:
Option Explicit Private secs As Long Private Sub Form_Load() Timer1.Enabled = False Timer1.Interval = 1000 End Sub Private Sub Command1_Click() Dim inp As String inp = InputBox("Enter number of minutes", "Countdown") If IsNumeric(inp) Then secs = Val(inp) * 60 Timer1.Enabled = True Else MsgBox "Must be numeric", vbInformation, "Error" End If End Sub Private Sub Timer1_Timer() Label1.Caption = CDate(secs / 86400) secs = secs - 1 If secs < 0 Then Timer1.Enabled = False End If End Sub
casey.
lol this makes it like am/pm i want like a Count down say like 60 mins, 01:00:00, 00:59:59, 00:59:58 etc etc, but thanks this is interesting, ill try to tweak it, see what I can do with it. :bigyello: