View Full Version : Solved: time counter format (mm:ss)
danbrix
10-04-2010, 10:28 AM
Hi guys,
I have a countdown timer on a userform. The users sets the pause time (the total duration) in textbox1 and textbox2 displays the counter. I have already got it to do that. The problem is the counter works in seconds right now. How do I format the counter (textbox2) to be in mm:ss?
Thank you for your help
Bob Phillips
10-04-2010, 11:10 AM
Something like
TextBox2.Text = Format(elapsed_time/86400,"mm:ss")
nepotist
10-04-2010, 11:12 AM
Something like
TextBox2.Text = Format(elapsed_time/86400,"mm:ss")
Xld when should you use .text and .value?
does it make any difference?
danbrix
10-04-2010, 11:25 AM
Thanks xld for your reply ...
Now it is in mm:ss format but
mm is stuck at 12 and ss is fine
Any ideas, please?
Bob Phillips
10-04-2010, 12:02 PM
Can you post the workbook to make it easy for me?
danbrix
10-04-2010, 12:28 PM
Just done that, xld.
Thanks for your help again.
Bob Phillips
10-04-2010, 02:58 PM
I think this is all that you need
Private Sub CommandButton1_Click()
Status = True
Dim PauseTime, Start, Finish, TotalTime, MyTime, Period, Value
If TextBox1.Text <> "" Then
PauseTime = TextBox1.Text ' Set duration
Period = 1
Value = PauseTime + Period
Start = Timer ' Set start time.
While (Value > Period And Status)
Value = Value - Period
Sleep 10
TextBox2.Text = Application.Text(Value / 86400, "mm:ss")
Wend
If (Value <= Period) Then TextBox2.Text = "Time Up!"
End If
End Sub
danbrix
10-04-2010, 03:44 PM
Thanks xld ... for some reason all I am getting is Time Up! But I replaced the main change of the code TextBox2.Text = Application.Text(MyTime / 86400, "mm:ss") into my original code and it works fine.
Thank you again
Bob Phillips
10-04-2010, 03:48 PM
Your code seemed overly complex to me.
You said TextBox1 contained a counter in seconds, I assumed you meant deciaml seconds. Were you inputting say 3:20?
danbrix
10-04-2010, 03:59 PM
Your code seemed overly complex to me.
You said TextBox1 contained a counter in seconds, I assumed you meant deciaml seconds. Were you inputting say 3:20? I was just putting say 200 (in seconds) and starts at 3:20 and was working fine. Now after my last post it runs fine but after completion it is giving Run Time Error '13'.
Bob Phillips
10-04-2010, 04:21 PM
We're on the same page then. Post the workbook and we will talke it from there.
danbrix
10-04-2010, 04:40 PM
Thanks xld, it is working fine now. (But don't know what I did right ... :dunno)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.