Tru Posted November 18, 2012 Share Posted November 18, 2012 (edited) Hello. I am trying to figure out a way to make this show the proper Hours:Minutes:Seconds in a tooltip, and I just can't seem to get it to calculate correctly. It will properly get 1 of the 3, but combined, after hitting the 00:01:00 mark the seconds continue on into oblivion and don't stop. Do I need to do some sort of If $Seconds = 60 Then '$Seconds = 0' reset type thing? Local $MSeconds = Round(TimerDiff($T)/100, 0) Local $Seconds = Round(TimerDiff($T)/1000, 0) If $Seconds < 10 Then $Seconds = "0" & $Seconds EndIf Local $Minutes = Round($Seconds/60, 0) If $Minutes < 10 Then $Minutes = "0" & $Minutes EndIf Local $Hours = Round($Minutes/60, 0) If $Hours < 10 Then $Hours = "0" & $Hours EndIf Local $TStamp = String($Hours & ":"& $Minutes & ":" & $Seconds) Or do I need to parse the values somehow? Any help is appreciated. Edited November 18, 2012 by Tru Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2012 Share Posted November 18, 2012 Tru, If you are trying to show the current HH:MM:SS then tooltip(@hour & ':' & @min & ':' & @sec) sleep(5000) See the help file for macro definitions. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Tru Posted November 18, 2012 Author Share Posted November 18, 2012 (edited) I'm not trying to show the current time, I'm trying to show the amount of time running an autoit script using TimerInit() If there is any easier way, please fill me. Edited November 18, 2012 by Tru Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2012 Share Posted November 18, 2012 Tru,If you are trying to show wall (clock) time then use _datediff. See the help file. Without seeing your whole script it's hard to tell what you are doing.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Tru Posted November 18, 2012 Author Share Posted November 18, 2012 (edited) At this point, this is just a test script to get a working timer going. I just want it to count how long the script has been running. expandcollapse popupHotKeySet('{PAUSE}', "Pause") HotKeySet('{END}', "Stop") Global $Go = True Global $On = True Global $T = TimerInit() While $On While $Go Local $MSeconds = Round(TimerDiff($T)/100, 0) Local $Seconds = Round(TimerDiff($T)/1000, 0) If $Seconds < 10 Then $Seconds = "0" & $Seconds EndIf Local $Minutes = Round($Seconds/60, 0) If $Minutes < 10 Then $Minutes = "0" & $Minutes EndIf Local $Hours = Round($Minutes/60, 0) If $Hours < 10 Then $Hours = "0" & $Hours EndIf Local $TStamp = String($Hours & ":"& $Minutes & ":" & $Seconds) ;MouseClick("left", 0, 0) ;Send('a') ToolTip($TStamp, 15, 0, "Time Running") WEnd WEnd Func Pause() If $Go == True Then $Go = False Else $Go = True EndIf EndFunc Func Stop() Exit EndFunc If I use a _datediff, I would need to do a global for each of the variables (hour/minute/second) then do a diff for each? Or can I do an entire timestamp difference? Edited November 18, 2012 by Tru Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2012 Share Posted November 18, 2012 Tru, Like so #include <date.au3> local $start_time = _nowcalc() sleep(2000) tooltip('Time difference = ' & _datediff('s',$start_time,_nowcalc()) & ' seconds' & @lf) sleep(2000) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2012 Share Posted November 18, 2012 Tru,ThisIf I use a _datediff, I would need to do a global for each of the variables (hour/minute/second) then do a diff for each? Or can I do an entire timestamp difference? leads me to believe that the help file might be your best friend. There are also several good wiki topics on autoit, just google it.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
BrewManNH Posted November 18, 2012 Share Posted November 18, 2012 Here's how I would do it. The $OldCounter check is only so that it doesn't constantly print to the console, but only puts something there when the time changes. $OldCounter = "11:11:11" $Timer = TimerInit() While 1 $iSetTime = TimerDiff($Timer)/1000 ;split the seconds into minutes and seconds $Hours = Int($iSetTime / 3600) $Minutes = Int((($iSetTime / 3600) - $Hours) * 60) $iSeconds = Int((((($iSetTime / 3600) - $Hours) * 60) - $Minutes) * 60) Local $Counter = StringFormat("%02u:%02u:%02u", $Hours, $Minutes, $iSeconds) If $Counter <> $OldCounter Then ConsoleWrite($Counter & @CRLF) $OldCounter = $Counter EndIf Sleep(10) WEnd If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Tomoya Posted November 18, 2012 Share Posted November 18, 2012 (edited) Here is a function that I used to capture the elapsed time since a button was pressed. I'm sure you could just call it at the start of your script and have it display where ever you want. Func ElapTime() Local $sec, $min, $hr $sec = Mod($seconds, 60) $min = Mod($seconds / 60, 60) $hr = Floor($seconds / 60 ^ 2) GUICtrlSetData($BlankElapsedTimeLabel, StringFormat("%02i:%02i:%02i", $hr, $min, $sec)) $seconds += 1 EndFunc @BrewManNH, I can never get my code to look right when I use the autoit tags. Why is that? Edited November 18, 2012 by Tomoya Link to comment Share on other sites More sharing options...
BrewManNH Posted November 18, 2012 Share Posted November 18, 2012 @BrewManNH,I can never get my code to look right when I use the autoit tags. Why is that?Don't use the full featured editor when pasting code into the code tags, switch to the basic editor (it's the button on the top left of the edit box), then paste the code. You can switch back after the code has been pasted.But if you edit the post, the formatting gets messed up again even when using the basic edit mode. Just an FYI Tomoya 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
guinness Posted November 18, 2012 Share Posted November 18, 2012 You could also look at using AdlibRegister every 1000ms instead of in a loop. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2012 Share Posted November 18, 2012 Tru, If you don't mind.... @brewmanNH and Tomoya, Why do you prefer to do the calcs instead of using _datediff? Just curious. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
BrewManNH Posted November 18, 2012 Share Posted November 18, 2012 If you do it the way I did, you can format it so that you can create a timer with it. DateDiff just gives you a difference, you can get the time from anywhere in any method you'd like, using TimerDiff was just for display purposes. If you put this into a function and call it with AdLibRegister every 1 second, you can just use a counter variable that keeps track of the times the function is called. Although, there is a possibility that the AdLib might get blocked by another function and cause the timer to be off by a bit. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2012 Share Posted November 18, 2012 @BrewmanNH, Thanks... @Tru, This is an example of what guiness and BrewmanNH are alluding to (using adlib's) #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #AutoIt3Wrapper_Add_Constants=n Opt("GUIOnEventMode", true) local $giu010 = guicreate('Your Training App GUI') GUISetOnEvent($gui_event_close,'_exit') local $btn010 = guictrlcreatebutton('Start Clock',10,10,380,50) guictrlsetfont($btn010,16,800,-1,'tahoma') GUICtrlSetOnEvent($btn010,'_clock') local $lbl010 = guictrlcreatelabel("",50,100,300,100,$ss_center+$ss_sunken) guictrlsetfont($lbl010,24,800, -1, 'courier new') guictrlsetcolor($lbl010,0xaa0000) local $lbl020 = guictrlcreatelabel('Clock Stopped',50,370,300,20,$ss_center) guictrlsetfont($lbl020,12,800,-1,'comic sans ms') guictrlsetcolor($lbl020,0x0000aa) guisetstate() while 1 sleep(250) wend func _clock() if guictrlread($btn010) = 'Start Clock' then guictrlsetdata($btn010,'Stop Clock') guictrlsetdata($lbl020,'Clock Started') adlibregister('_update_clock',1000) else guictrlsetdata($btn010,'Start Clock') guictrlsetdata($lbl020,'Clock Stopped') adlibunregister('_update_clock') EndIf endfunc func _exit() Exit endfunc func _update_clock() guictrlsetdata($lbl010,@MON & '/' & @MDAY & '/' & @YEAR & @crlf & @HOUR & ':' & @MIN & ':' & @sec) endfunc You can adapt it to whatever you need. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Tru Posted November 19, 2012 Author Share Posted November 19, 2012 Thanks everyone, but I'm trying to do this with a ToolTip on, not a GUI. I don't need it to start and stop, just count up from start to whenever the entire thing is stopped. Link to comment Share on other sites More sharing options...
BrewManNH Posted November 19, 2012 Share Posted November 19, 2012 The script I posted can be used anywhere, a label, a tooltip, an edit box. The variable $Counter holds the time formatted in HH:MM:SS so you can use that to populate your tooltip. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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