nitekram Posted July 15, 2006 Share Posted July 15, 2006 Can anyone direct me to a thread that has done something like this. I have a 2 or more strings that I would like to add together - representing TIME 00:12:03 + 00:17:57 = 00:30:00 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 Link to comment Share on other sites More sharing options...
evilertoaster Posted July 15, 2006 Share Posted July 15, 2006 will the _DateAdd() UDF in the beta work? Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Author Share Posted July 15, 2006 will the _DateAdd() UDF in the beta work?That looks like it might work - but it will only add one add a time. Is there something else that will take the string and convert it to an integer and then I can add them and then convert it back? 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 Link to comment Share on other sites More sharing options...
evilertoaster Posted July 15, 2006 Share Posted July 15, 2006 _TimeToTicks () * 1000 should give seconds... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 Here I made this, see if it does what you want:Local $Time1 = '00:42:56', $Time2 = '00:17:03' MsgBox(0, '', _AddTime($Time1, $Time2)) Func _AddTime($sTime1, $sTime2) Local $aSplit1 = StringSplit($sTime1, ':') Local $aSplit2 = StringSplit($sTime2, ':') Local $nAddSec = 0, $nAddMin = 0, $nAddHour = 0 $nAddSec += Int($aSplit1[3]) + Int($aSplit2[3]) If $nAddSec > 59 Then $nAddMin = 1 $nAddSec = $nAddSec - 60 EndIf $nAddMin += Int($aSplit1[2]) + Int($aSplit2[2]) If $nAddMin > 59 Then $nAddHour = 1 $nAddMin = $nAddMin - 60 EndIf $nAddHour += Int($aSplit1[1]) + Int($aSplit2[1]) Return StringFormat('%02d', $nAddHour) & ':' & StringFormat('%02d', $nAddMin) & ':' & StringFormat('%02d', $nAddSec) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
evilertoaster Posted July 15, 2006 Share Posted July 15, 2006 yea that looks good. Hey maybe change the if-then loops to for-next to let it handle times greater than 120 seconds/minutes? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 (edited) yea that looks good. Hey maybe change the if-then loops to for-next to let it handle times greater than 120 seconds/minutes?120 seconds? 60 seconds is 1 minute... Anyway, I was going to do a for loop but it isn't necessary since not all the options are the same only 1 and 2 do the same thing. But for giggles here you go:Local $Time1 = '00:44:56', $Time2 = '00:17:03' MsgBox(0, '', _AddTime($Time1, $Time2)) Func _AddTime($sTime1, $sTime2) Local $aSplit1 = StringSplit($sTime1, ':') Local $aSplit2 = StringSplit($sTime2, ':') Local $aAddTime[4] = ['', 0, 0, 0] For $iCount = UBound($aSplit1) - 1 To 2 Step - 1 $aAddTime[$iCount] += Int($aSplit1[$iCount]) + Int($aSplit2[$iCount]) If $aAddTime[$iCount] > 59 Then $aAddTime[$iCount - 1] = 1 $aAddTime[$iCount] = StringFormat('%02d', String($aAddTime[$iCount] - 60)) EndIf Next $aAddTime[1] += Int($aSplit1[1]) + Int($aSplit2[1]);Weird couldn't use StringFormat correctly here Return StringFormat('%02d', $aAddTime[1]) & ':' & $aAddTime[2] & ':' & $aAddTime[3] EndFunc Edit: Made it a tad smaller Weird that I couldn't get $aAddTime[1] += StringFormat('%02d', String((Int($aSplit1[1]) + Int($aSplit2[1])))To work Edited July 15, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
evilertoaster Posted July 15, 2006 Share Posted July 15, 2006 (edited) yea i said that wrong i guess. A do-until might be better, I was meaning somthing like- Local $Time1 = '00:1142:56', $Time2 = '00:17:03' MsgBox(0, '', _AddTime($Time1, $Time2)) Func _AddTime($sTime1, $sTime2) Local $aSplit1 = StringSplit($sTime1, ':') Local $aSplit2 = StringSplit($sTime2, ':') Local $nAddSec = 0, $nAddMin = 0, $nAddHour = 0 $nAddSec += Int($aSplit1[3]) + Int($aSplit2[3]) Do If $nAddSec > 59 Then $nAddMin = 1 $nAddSec = $nAddSec - 60 EndIf Until $nAddSec<60 $nAddMin += Int($aSplit1[2]) + Int($aSplit2[2]) Do If $nAddMin > 59 Then $nAddHour = 1 $nAddMin = $nAddMin - 60 EndIf Until $nAddMin<60 $nAddHour += Int($aSplit1[1]) + Int($aSplit2[1]) Return StringFormat('%02d', $nAddHour) & ':' & StringFormat('%02d', $nAddMin) & ':' & StringFormat('%02d', $nAddSec) EndFunc In case someone wanted to have more that 60 seconds or minutes. Edited July 15, 2006 by evilertoaster Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Author Share Posted July 15, 2006 Made it a tad smaller Weird that I couldn't get $aAddTime[1] += StringFormat('%02d', String((Int($aSplit1[1]) + Int($aSplit2[1])))To work Either way - thanks - I will look at the difference between the two but for now the first one works - did you already have the code or are you that fast Thanks again - works great 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 yea i said that wrong i guess. A do-until might be better, I was meaning somthing like- Local $Time1 = '00:1142:56', $Time2 = '00:17:03' MsgBox(0, '', _AddTime($Time1, $Time2)) Func _AddTime($sTime1, $sTime2) Local $aSplit1 = StringSplit($sTime1, ':') Local $aSplit2 = StringSplit($sTime2, ':') Local $nAddSec = 0, $nAddMin = 0, $nAddHour = 0 $nAddSec += Int($aSplit1[3]) + Int($aSplit2[3]) Do If $nAddSec > 59 Then $nAddMin = 1 $nAddSec = $nAddSec - 60 EndIf Until $nAddSec<60 $nAddMin += Int($aSplit1[2]) + Int($aSplit2[2]) Do If $nAddMin > 59 Then $nAddHour = 1 $nAddMin = $nAddMin - 60 EndIf Until $nAddMin<60 $nAddHour += Int($aSplit1[1]) + Int($aSplit2[1]) Return StringFormat('%02d', $nAddHour) & ':' & StringFormat('%02d', $nAddMin) & ':' & StringFormat('%02d', $nAddSec) EndFunc In case someone wanted to have more that 60 seconds or minutes.How would you ever get that many minutes? Do you run programs that do that? Sorry if I misunderstood what nitekram wanted. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 (edited) Either way - thanks - I will look at the difference between the two but for now the first one works - did you already have the code or are you that fast Thanks again - works greatNo, I made it when you asked the question. But it seemed easy enough. Edit: Added evils suggestion just to play it safe:Local $Time1 = '00:1144:5600', $Time2 = '00:17:03' MsgBox(0, '', _AddTime($Time1, $Time2)) Func _AddTime($sTime1, $sTime2) Local $aSplit1 = StringSplit($sTime1, ':') Local $aSplit2 = StringSplit($sTime2, ':') If $aSplit1[0] <> 3 Or $aSplit2[0] <> 3 Then SetError(1) Return 0 EndIf Local $aAddTime[4] = ['', 0, 0, 0] For $iCount = UBound($aSplit1) - 1 To 2 Step - 1 $aAddTime[$iCount] += Int($aSplit1[$iCount]) + Int($aSplit2[$iCount]) Do If $aAddTime[$iCount] > 59 Then $aAddTime[$iCount - 1] += 1 $aAddTime[$iCount] = StringFormat('%02d', String($aAddTime[$iCount] - 60)) EndIf Until Int($aAddTime[$iCount]) < 60 Next $aAddTime[1] += Int($aSplit1[1]) + Int($aSplit2[1]);Weird couldn't use StringFormat correctly here Return StringFormat('%02d', $aAddTime[1]) & ':' & $aAddTime[2] & ':' & $aAddTime[3] EndFunc Edited July 15, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
evilertoaster Posted July 15, 2006 Share Posted July 15, 2006 How would you ever get that many minutes? Do you run programs that do that? Sorry if I misunderstood what nitekram wanted.You'd not usually have that many, just a 'what if' scenario I think what you had first will work fine for nitekram, i was just thinking if for some reason you had like'it will take 3000 seconds to do somthing' and you wanted it returned in standard form...i dont know probably just over thinking it ^^ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 You'd not usually have that many, just a 'what if' scenario I think what you had first will work fine for nitekram, i was just thinking if for some reason you had like'it will take 3000 seconds to do somthing' and you wanted it returned in standard form...i dont know probably just over thinking it ^^No it was a good point... You see all kinds of scenerios on here, I changed it above if you see... also made sure to help with a little error handling. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Author Share Posted July 15, 2006 No, I made it when you asked the question. But it seemed easy enough.You all make it look so easy all the time. I spend hours making something that takes you like 15 mins.The only chance I have at beating you at anything - is at pool, but I am sure that you would beat me at that too. By the way how did you do in the last tournament? 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 You all make it look so easy all the time. I spend hours making something that takes you like 15 mins.The only chance I have at beating you at anything - is at pool, but I am sure that you would beat me at that too. By the way how did you do in the last tournament?There are many on here that do the same to me nitekram, I usually take the longest route for the same result.2nd - But got moved to the vegas position, just not the tournament 1st cash position. That's next month. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Author Share Posted July 15, 2006 There are many on here that do the same to me nitekram, I usually take the longest route for the same result.2nd - But got moved to the vegas position, just not the tournament 1st cash position. That's next month.Maybe before you were a guru - I hardly ever see a question from you. You are very helpful though, and I speak for all the noobs out here - we love the help.You a nine ball player? Ever play snooker? 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 15, 2006 Moderators Share Posted July 15, 2006 Maybe before you were a guru - I hardly ever see a question from you. You are very helpful though, and I speak for all the noobs out here - we love the help.You a nine ball player? Ever play snooker?Ha, I always have questions, I wear the search function out... And MSDN is on speed dial (favorites lol).I've played them all 3 cushion/14:1/1 pocket/snooker/10ball/9ball/8ball/7ball/golf (on a pool table) and a few hundred others I'm sure. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
nitekram Posted July 15, 2006 Author Share Posted July 15, 2006 Ha, I always have questions, I wear the search function out... And MSDN is on speed dial (favorites lol).I've played them all 3 cushion/14:1/1 pocket/snooker/10ball/9ball/8ball/7ball/golf (on a pool table) and a few hundred others I'm sure.Well, I try to play them all. I wish you luck in Vegas - remember what happens in Vegas, uh I can't remember. Last time our team was there we were out the second day - think it was all the money we lost at the tables (not pool) the night before. 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 Link to comment Share on other sites More sharing options...
HardCopy Posted July 15, 2006 Share Posted July 15, 2006 (edited) Ha, I always have questions, I wear the search function out... And MSDN is on speed dial (favorites lol).I've played them all 3 cushion/14:1/1 pocket/snooker/10ball/9ball/8ball/7ball/golf (on a pool table) and a few hundred others I'm sure.U will go blindU bad boy! Edited July 15, 2006 by HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
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