Ventura Posted July 30, 2016 Share Posted July 30, 2016 I use a function to make the Timer tho show as Minutes:Seconds.Miliseonds but I have an issue. It doesn't add the timers and thus it shows 0 as the return. It works for the normal timer and also for TicksToTime but doesn't with this function. ; Should show 0:xx.xxx as the return but shows 0 Func Timer(Const $Timer) Local $Ms = Int(Mod(TimerDiff($Timer), 1000)) Local $Timer2 = TimerDiff($Timer) / 1000 Local $Mins = Int($Timer2 / 60) Local $Secs = Floor(Mod($Timer2, 60)) Return StringFormat("%01i:%02i.%03i", $Mins, $Secs, $Ms) EndFunc ;==>Timer $iBegin = TimerInit() Sleep(Random(500,2000)) $Int1 = Timer($iBegin) $iBegin = TimerInit() Sleep(Random(500,2000)) $Int2 = Timer($iBegin) $IntT = $Int1 + $Int2 MsgBox(0, '', $IntT) Link to comment Share on other sites More sharing options...
InunoTaishou Posted July 30, 2016 Share Posted July 30, 2016 It's not being returned as a numerical value but as a string %01i:%02i.%03i n:nn.nnn Adding two string together is always going to return 0. Are you trying to add the time together? This should do it if that's what you're wanting to accomplish: expandcollapse popupLocal $iBegin = TimerInit() Sleep(2205) Local $aTime1 = Timer($iBegin) Local $iBegin = TimerInit() Sleep(1150) Local $aTime2 = Timer($iBegin) Local $aTimeTotal = TimerAdd($aTime1, $aTime2) MsgBox(0, '', StringFormat("%01i:%02i.%03i", $aTimeTotal[0], $aTimeTotal[1], $aTimeTotal[2])) Func Timer(Const $Timer) Local $Ms = StringFormat("%03i", Int(Mod(TimerDiff($Timer), 1000))) Local $Timer2 = TimerDiff($Timer) / 1000 Local $Mins = StringFormat("%01i", Int($Timer2 / 60)) Local $Secs = StringFormat("%02i", Floor(Mod($Timer2, 60))) Local $aReturn[3] = [$Mins, $Secs, $Ms] Return $aReturn EndFunc ;==>Timer Func TimerAdd(Const $aArr1, Const $aArr2) Local $aReturn[3] = [$aArr1[0] + $aArr2[0], $aArr1[1] + $aArr2[1], $aArr1[2] + $aArr2[2]] Local $iAddUp = 0 If ($aReturn[2] >= 1000) Then $iAddUp = Int($aReturn[2] / 1000) $aReturn[1] += $iAddUp $aReturn[2] -= $iAddUp * 1000 EndIf If ($aReturn[1] >= 60) Then $iAddUp = Int($aReturn[2] / 60) $aReturn[0] += $iAddUp $aReturn[1] -= $iAddUp * 60 EndIf Return $aReturn EndFunc Link to comment Share on other sites More sharing options...
Gianni Posted July 30, 2016 Share Posted July 30, 2016 (edited) Not clear if your goal is to add delays and then have a string formatted with the total of delays, or you are trying a way to add together the delays already expressed in the form of string. even if at first glance it seems the same thing, those require two completly different approaches (as in post #2 for example) in the first case instead you could semplify your script like this: ; Should show 0:xx.xxx as the return Func Timer($Timer) Local $Ms = Int(Mod($Timer, 1000)) Local $Timer2 = $Timer / 1000 Local $Mins = Int($Timer2 / 60) Local $Secs = Floor(Mod($Timer2, 60)) Return StringFormat("%01i:%02i.%03i", $Mins, $Secs, $Ms) EndFunc ;==>Timer $iBegin = TimerInit() Sleep(Random(500,2000)) $Int1 = TimerDiff($iBegin) ; Timer($iBegin) $iBegin = TimerInit() Sleep( Random(500,2000)) $Int2 = TimerDiff($iBegin) ; Timer($iBegin) $IntT = $Int1 + $Int2 MsgBox(0, '', Timer($IntT)) p.s. you could also be interested to this Edited July 30, 2016 by Chimp removed Const Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Ventura Posted July 30, 2016 Author Share Posted July 30, 2016 (edited) This what I'm trying to do.. The function I use actually does what I want, I get three or two formatted timestamps for the time taken and I put it in my gui as list.. So all I want was a way to add those two or three times and show exactly how long it took as a whole. For example (Mins : Secs . MS) 0:31.570 + 0:51.329 + 0:34.887 = 1:57.786 Adding those three will give me 1 min 57 secs and 786 ms.. just like this page does Maybe I have taken wrong approach for the code in OP because after looking both posts above it doesn't show exactly time taken but InunoTaishou code is closer to what I want. Edited July 30, 2016 by Ventura Link to comment Share on other sites More sharing options...
Ventura Posted July 30, 2016 Author Share Posted July 30, 2016 Here is my full code.. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> $Form = GUICreate("Form1", 300, 340, 0, 0) GUISetBkColor(0x494E48) $Border = GUICtrlCreateGraphic(10, 10, 280, 280) $Header = GUICtrlCreateGraphic(10, 10, 280, 25) $Label = GUICtrlCreateLabel("SPLITS", 15, 15, 40, 15) $splits = GUICtrlCreateButton("Add Item", 50, 300, 80, 30) $getsplit = GUICtrlCreateButton("Show Item", 160, 300, 80, 30) GUICtrlSetColor($Border, 0x696A65) GUICtrlSetColor($Header, 0x696A65) GUICtrlSetColor($Label, 0x00FF00) GUICtrlSetState($Border, $GUI_DISABLE) GUICtrlSetState($Header, $GUI_DISABLE) $Listview = GUICtrlCreateListView("Column1|Column2|Column3|Column4", 15, 40, 270, 240, _ BitOR($LVS_SHOWSELALWAYS, $LVS_NOCOLUMNHEADER), $WS_EX_TRANSPARENT) GUICtrlSetColor($Listview, 0xEEEEEE) _GUICtrlListView_SetExtendedListViewStyle($Listview, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_TRANSPARENTBKGND, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetColumnWidth($Listview, 0, 67) _GUICtrlListView_SetColumnWidth($Listview, 1, 67) _GUICtrlListView_SetColumnWidth($Listview, 2, 67) _GUICtrlListView_SetColumnWidth($Listview, 3, 69) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $splits Addtolist() Case $getsplit EndSwitch WEnd Func Timer(Const $Timer) Local $Ms = Int(Mod(TimerDiff($Timer), 1000)) Local $Timer2 = TimerDiff($Timer) / 1000 Local $Mins = Int($Timer2 / 60) Local $Secs = Floor(Mod($Timer2, 60)) Return StringFormat("%01i:%02i:%03i", $Mins, $Secs, $Ms) EndFunc ;==>Timer Func Addtolist() $i = 0 $rw = 0 Local $aItem1, $aItem2, $aItem3 While 1 $Time = TimerInit() Sleep(1000) ;; Some function to do here $splits1 = Timer($Time) _GUICtrlListView_AddItem($Listview, $splits1, $i) $Time = TimerInit() Sleep(1000) ;; Some function to do here $splits2 = Timer($Time) _GUICtrlListView_AddSubItem($Listview, $i, $splits2, 1, 1) $Time = TimerInit() Sleep(1000) ;; Some function to do here $splits3 = Timer($Time) _GUICtrlListView_AddSubItem($Listview, $i, $splits3, 2, 2) $i = $i + 1 $aItem1 = _GUICtrlListView_GetItem($Listview, $rw) $aItem2 = _GUICtrlListView_GetItem($Listview, $rw, 1) $aItem3 = _GUICtrlListView_GetItem($Listview, $rw, 2) $aItemT = $aItem1[3] + $aItem2[3] + $aItem2[3] MsgBox(1, "1", "Total time:" & @TAB & $aItemT) $rw = $rw + 1 WEnd EndFunc ;==>Addtolist Link to comment Share on other sites More sharing options...
Gianni Posted July 30, 2016 Share Posted July 30, 2016 a possible way using a function for adding two timers at a time expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> $Form = GUICreate("Form1", 300, 340, 0, 0) GUISetBkColor(0x494E48) $Border = GUICtrlCreateGraphic(10, 10, 280, 280) $Header = GUICtrlCreateGraphic(10, 10, 280, 25) $Label = GUICtrlCreateLabel("SPLITS", 15, 15, 40, 15) $splits = GUICtrlCreateButton("Add Item", 50, 300, 80, 30) $getsplit = GUICtrlCreateButton("Show Item", 160, 300, 80, 30) GUICtrlSetColor($Border, 0x696A65) GUICtrlSetColor($Header, 0x696A65) GUICtrlSetColor($Label, 0x00FF00) GUICtrlSetState($Border, $GUI_DISABLE) GUICtrlSetState($Header, $GUI_DISABLE) $Listview = GUICtrlCreateListView("Column1|Column2|Column3|Column4", 15, 40, 270, 240, _ BitOR($LVS_SHOWSELALWAYS, $LVS_NOCOLUMNHEADER), $WS_EX_TRANSPARENT) GUICtrlSetColor($Listview, 0xEEEEEE) _GUICtrlListView_SetExtendedListViewStyle($Listview, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_TRANSPARENTBKGND, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_SetColumnWidth($Listview, 0, 67) _GUICtrlListView_SetColumnWidth($Listview, 1, 67) _GUICtrlListView_SetColumnWidth($Listview, 2, 67) _GUICtrlListView_SetColumnWidth($Listview, 3, 69) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $splits Addtolist() Case $getsplit EndSwitch WEnd Func Timer(Const $Timer) Local $Ms = Int(Mod(TimerDiff($Timer), 1000)) Local $Timer2 = TimerDiff($Timer) / 1000 Local $Mins = Int($Timer2 / 60) Local $Secs = Floor(Mod($Timer2, 60)) Return StringFormat("%01i:%02i:%03i", $Mins, $Secs, $Ms) EndFunc ;==>Timer Func _SumTimers($sT1, $sT2) ; merge the 2 timers by sum and convert all in millisecond if $sT1 = "" Then $sT1 = '0:0.0' if $sT2 = "" Then $sT2 = '0:0.0' Local $iTotMs = 0 ; totalizer of milliseconds Local $aT1 = StringSplit($sT1, ":.") Local $aT2 = StringSplit($sT2, ":.") $iTotMs = ($aT1[1] + $aT2[1]) * 60000 ; add both mins to milliseconds $iTotMs += ($aT1[2] + $aT2[2]) * 1000 ; add both secs to milliseconds $iTotMs += $aT1[3] + $aT2[3] ; add both milliseconds ; returns the sum of timers in a formatted string Return StringFormat("%01i:%02i.%03i", Int(($iTotMs/1000) / 60), Floor(Mod(($iTotMs/1000), 60)) ,Int(Mod($iTotMs, 1000))) EndFunc ;==>_SumTimes Func Addtolist() $i = 0 $rw = 0 Local $aItem1, $aItem2, $aItem3, $aItemT While 1 $Time = TimerInit() Sleep(1000) ;; Some function to do here $splits1 = Timer($Time) _GUICtrlListView_AddItem($Listview, $splits1, $i) $Time = TimerInit() Sleep(1000) ;; Some function to do here $splits2 = Timer($Time) _GUICtrlListView_AddSubItem($Listview, $i, $splits2, 1, 1) $Time = TimerInit() Sleep(1000) ;; Some function to do here $splits3 = Timer($Time) _GUICtrlListView_AddSubItem($Listview, $i, $splits3, 2, 2) $i = $i + 1 $aItem1 = _GUICtrlListView_GetItem($Listview, $rw) $aItemT = _SumTimers($aItemT, $aItem1[3]) $aItem2 = _GUICtrlListView_GetItem($Listview, $rw, 1) $aItemT = _SumTimers($aItemT, $aItem2[3]) $aItem3 = _GUICtrlListView_GetItem($Listview, $rw, 2) $aItemT = _SumTimers($aItemT, $aItem3[3]) ; $aItemT = $aItem1[3] + $aItem2[3] + $aItem2[3] MsgBox(1, "1", "Total time:" & @TAB & $aItemT) $rw = $rw + 1 WEnd EndFunc ;==>Addtolist Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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