WipeoutFTW Posted August 20, 2006 Posted August 20, 2006 Ok guys, I want to convert a number to time format. $TimeLeft = Round($MinutesLeft, 1) This is code will give me numbers like 1.5 minutes left. How can I convert that to 1:30 (Minutes:Seconds) Thanks guys!
Examiner Posted August 20, 2006 Posted August 20, 2006 can you show us the script... how you got $timeleft that could help us... help you 8)
Paulie Posted August 20, 2006 Posted August 20, 2006 (edited) Ok guys, I want to convert a number to time format. $TimeLeft = Round($MinutesLeft, 1) This is code will give me numbers like 1.5 minutes left. How can I convert that to 1:30 (Minutes:Seconds) Thanks guys!Just do this MsgBox(0, $Timeleft, DecToTime($TimeLeft)) Func DecToTime($decimal) $Min_Sec = StringSplit($decimal, ".") $DecSecs = 10/$Min_Sec[2] $TimeSecs = 60/$DecSecs Return $Min_Sec[1]&":"&$TimeSecs EndFunc Edited August 20, 2006 by Paulie
WipeoutFTW Posted August 20, 2006 Author Posted August 20, 2006 Here is my program code in full. It just automates a task and im trying to create almost a progress ticker for it. expandcollapse popup#include <GUIConstants.au3> $hMainGUI = GUICreate("Auto Publisher", 200, 100); save handle to GUI $Label_1 = GUICtrlCreateLabel("Publish how many?", 30, 10); save control ID of label (in case you want to change it later) $Input_1 = GUICtrlCreateInput("10", 30, 50, 60); save control ID of input (for reading it later) $Button_1 = GUICtrlCreateButton("Publish", 100, 47, 60); save control ID of button (to see if it's pushed) GUISetState(@SW_SHOW) While 1 $Msg = GuiGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop; Exit loop if GUI gets closed Case $Button_1 $InputData = GuiCtrlRead($Input_1); read the input control $InputLeft = GuiCtrlRead($Input_1); read the input control $TotalPosts = GuiCtrlRead($Input_1); read the input control MsgBox(64, "Auto Publisher", "Number to Publish: " & $InputData) ExitLoop; Exit loop when done EndSwitch Wend MsgBox(64, "Auto Publisher", "Make sure you have the first email open.") For $i = $InputData to 1 Step -1 $SecondsLeft = $InputLeft * 9.25 $MinutesLeft = $SecondsLeft / 60 $TimeLeft = Round($MinutesLeft, 1) $Completed = $TotalPosts - $InputLeft $PercentComplete = $Completed / $TotalPosts MouseClick("left", 343, 616, 2); Link to the publish page Sleep(3000);two seconds MouseClick("left", 55, 307, 2);Publish Button Sleep(3000);two seconds MouseClick("left", 1260, 12, 2);Close Window Sleep(250);1/4 a second MouseClick("left", 1236, 406, 2);Next Button $InputLeft = $InputLeft - 1 #include <GUIConstants.au3> GUICreate("Progress", 200, 80); save handle to GUI GUICtrlCreateLabel($InputLeft &" left to publish.", 30, 10) GUICtrlCreateLabel("About "& $TimeLeft &" minutes left.", 30, 30) GUICtrlCreateLabel($PercentComplete &"% complete.", 30, 50) GUISetState(@SW_SHOW) Sleep(3000);two seconds Next MsgBox(0,"", $InputData & " posting(s) published.")
nitekram Posted August 20, 2006 Posted August 20, 2006 Ok guys, I want to convert a number to time format.$TimeLeft = Round($MinutesLeft, 1)This is code will give me numbers like 1.5 minutes left. How can I convert that to 1:30 (Minutes:Seconds)Thanks guys!How about multiple the decimal part by 60 - that will give you 30 in your example:30 = 0.5 * 60 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow."  WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI  CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
nitekram Posted August 20, 2006 Posted August 20, 2006 How about multiple the decimal part by 60 - that will give you 30 in your example:30 = 0.5 * 60EDIT - that will make me read the post again before posting - I made something to eat and came back and just posted 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow."  WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI  CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
Paulie Posted August 20, 2006 Posted August 20, 2006 (edited) How about multiple the decimal part by 60 - that will give you 30 in your example:30 = 0.5 * 60 *Points to post #3* Edited August 20, 2006 by Paulie
nitekram Posted August 21, 2006 Posted August 21, 2006 *Points to post #3* I know - I should have just posted my answer before trying to eat - but at least you gave an example - you get extra points for that 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow."  WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI  CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
buzz44 Posted August 21, 2006 Posted August 21, 2006 (edited) Maybe these might help you that I created awhile back > http://www.autoitscript.com/forum/index.php?showtopic=12124 Edited August 21, 2006 by Burrup qq
WipeoutFTW Posted August 21, 2006 Author Posted August 21, 2006 is there any way to take the remainder from rounding?
buzz44 Posted August 21, 2006 Posted August 21, 2006 Try this?expandcollapse popup$test1 = "00:50" $test2 = "00:40" MsgBox(0,"Time", "$test1 = " & $test1 & @CRLF & "$test2 = " & $test2) MsgBox(0,"Result Add", _TimeAdd($test1,$test2)) ;Will return 01:30 MsgBox(0,"Result Sub", _TimeSub($test1,$test2)) ;Will return 00:10 Func _TimeAdd($iVal1,$iVal2) $aVal1 = StringSplit($iVal1,":") If @error Then SetError(1) ; Time in incorrect format Return 0 EndIf $aVal2 = StringSplit($iVal2,":") If @error Then SetError(1) ; Time in incorrect format Return 0 EndIf If ($aVal1[0] > 4) Or ($aVal2[0] > 4) Then SetError(1) ; Time in incorrect format Return "" ElseIf $aVal1[0] = 2 Then $iHourA = 0 $iMinA = $aVal1[1] $iSecA = $aVal1[2] ElseIf $aVal1[0] = 3 Then $iHourA = $aVal1[1] $iMinA = $aVal1[2] $iSecA = $aVal1[3] EndIf If $aVal2[0] = 2 Then $iHourB = 0 $iMinB = $aVal2[1] $iSecB = $aVal2[2] ElseIf $aVal2[0] = 3 Then $iHourB = $aVal2[1] $iMinB = $aVal2[2] $iSecB = $aVal2[3] EndIf If ($iSecA + $iSecB) < 60 Then $iSecC = ($iSecA + $iSecB) ElseIf ($iSecA + $iSecB) > 59 Then $iSecC = ($iSecA + $iSecB) - 60 $iMinA = $iMinA + 1 EndIf If ($iMinA + $iMinB) < 60 Then $iMinC = ($iMinA + $iMinB) ElseIf ($iMinA + $iMinB) > 59 Then $iMinC = ($iMinA + $iMinB) - 60 $iHourA = $iHourA + 1 EndIf $iHourC = $iHourA + $iHourB If StringLen($iSecC) = 1 Then $iSecC = "0" & $iSecC If StringLen($iMinC) = 1 Then $iMinC = "0" & $iMinC If $iHourC = 0 Then Return ($iMinC & ":" & $iSecC) ElseIf $iHourC <> 0 Then Return ($iHourC & ":" & $iMinC & ":" & $iSecC) EndIf EndFunc Func _TimeSub($iVal1,$iVal2) $aVal1 = StringSplit($iVal1,":") If @error Then SetError(1) ; Time in incorrect format Return 0 EndIf $aVal2 = StringSplit($iVal2,":") If @error Then SetError(1) ; Time in incorrect format Return 0 EndIf If ($aVal1[0] > 4) Or ($aVal2[0] > 4) Then SetError(1) ; Time in incorrect format Return "" ElseIf $aVal1[0] = 2 Then $iHourA = 0 $iMinA = $aVal1[1] $iSecA = $aVal1[2] ElseIf $aVal1[0] = 3 Then $iHourA = $aVal1[1] $iMinA = $aVal1[2] $iSecA = $aVal1[3] EndIf If $aVal2[0] = 2 Then $iHourB = 0 $iMinB = $aVal2[1] $iSecB = $aVal2[2] ElseIf $aVal2[0] = 3 Then $iHourB = $aVal2[1] $iMinB = $aVal2[2] $iSecB = $aVal2[3] EndIf If ($iSecA - $iSecB) > 0 Then $iSecC = ($iSecA - $iSecB) ElseIf ($iSecA - $iSecB) = 0 Then $iSecC = "00" ElseIf ($iSecA - $iSecB) < 1 Then $iSecC = 60 + ($iSecA - $iSecB) $iMinA = $iMinA - 1 EndIf If ($iMinA - $iMinB) > 0 Then $iMinC = ($iMinA - $iMinB) ElseIf ($iMinA - $iMinB) = 0 Then $iMinC = "00" ElseIf ($iMinA - $iMinB) < 1 Then $iMinC = 60 + ($iMinA - $iMinB) $iHourA = $iHourA - 1 EndIf $iHourC = $iHourA - $iHourB If StringLen($iSecC) = 1 Then $iSecC = "0" & $iSecC If StringLen($iMinC) = 1 Then $iMinC = "0" & $iMinC If $iHourC = 0 Then Return ($iMinC & ":" & $iSecC) ElseIf $iHourC <> 0 Then Return ($iHourC & ":" & $iMinC & ":" & $iSecC) EndIf EndFunc qq
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now