|
-
Jan 6th, 2005, 05:50 PM
#1
Thread Starter
Junior Member
Count Down Help..
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..
-
Jan 6th, 2005, 07:27 PM
#2
New Member
-
Jan 6th, 2005, 08:18 PM
#3
Re: Count Down Help..
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
-
Jan 6th, 2005, 09:06 PM
#4
Thread Starter
Junior Member
Re: Count Down Help..
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...
-
Jan 6th, 2005, 09:21 PM
#5
Re: Count Down Help..
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
-
Jan 6th, 2005, 09:38 PM
#6
Addicted Member
Re: Count Down Help..
This the answer
VB Code:
Label1.Caption=format(time, "hh:mm:ss"
Set the interval to 1000
" I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."
" Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
- Thomas Alva Edison-
In God We Trust 
-
Jan 6th, 2005, 09:41 PM
#7
Re: Count Down Help..
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 ...)
-
Jan 6th, 2005, 09:48 PM
#8
Addicted Member
Re: Count Down Help..
Sorry RhinoBull i thought that is code..
" I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."
" Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
- Thomas Alva Edison-
In God We Trust 
-
Jan 6th, 2005, 09:53 PM
#9
Re: Count Down Help..
You don't have to be sorry - I don't have any problem with someone's trying to help.
-
Jan 6th, 2005, 10:45 PM
#10
Thread Starter
Junior Member
Re: Count Down Help..
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
-
Jan 9th, 2005, 02:54 AM
#11
Thread Starter
Junior Member
Re: Count Down Help..
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..
-
Jan 9th, 2005, 04:36 AM
#12
Re: Count Down Help..
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.
-
Jan 9th, 2005, 05:36 AM
#13
Thread Starter
Junior Member
Re: Count Down Help..
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.
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
|