krboun Posted December 8, 2011 Posted December 8, 2011 Hello everyone I am quite new with AutuIt and i can not solve one problem. I have scrip, works fine, but i want to repeat it in time period infinitely(example every 500 000 miliseconds) until manual stop. I was thinking about very long "for" cycle and in each cycle "sleep" for required time. But that is very weird. Do you know any better solution? Many thanks
Moderators Melba23 Posted December 8, 2011 Moderators Posted December 8, 2011 krboun,Welcome to the AutoIt forum. Take a look at AdlibRegister in the Help file. It lets you run a function at reqular intervals. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
water Posted December 8, 2011 Posted December 8, 2011 Put everything you have now into a function and call this function in a loop. Something like: While 1 _Your function() Sleep(500000) WEnd Func _Your_function() ; here goes your code EndFuncWhat is still needed is a way to tell the script to exit. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
jchd Posted December 8, 2011 Posted December 8, 2011 Use an infinite loop, HotKeySet to map (say Esc) to an exit function and AdLibRegister to launch your function every 500 seconds. See if you can come up with a working script this way. (Too late!) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
krboun Posted December 8, 2011 Author Posted December 8, 2011 (edited) While cycle works fine, thanksbut i don´t know how to y use AdlibRegisterscriptFunc _A () ;something EndFunc[/i] AdlibRegister("_A",3000)doesn´t do anything Edited December 8, 2011 by krboun
water Posted December 8, 2011 Posted December 8, 2011 (edited) Because this script doesn't run long enough to call function _A. You need some kind of loop: Func _A () ConsoleWrite("*" & @CRLF);something EndFunc AdlibRegister("_A",3000) While 1 Sleep(10) WEnd Edited December 8, 2011 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Moderators Melba23 Posted December 8, 2011 Moderators Posted December 8, 2011 (edited) krboun, You need to keep the script alive like this: ; Press ESC to exit HotKeySet("{ESC}", "On_Exit") ; Produce a MsgBox every 5 secs AdlibRegister("Fred", 5000) ; Keep script alive in an infinite loop While 1 Sleep(10) ; Important so as not to burn up the CPU WEnd Func Fred() MsgBox(0, "Adlib", "Hi there!") EndFunc Func On_Exit() Exit EndFunc All clear? M23 Edit: Good evening water! Edited December 8, 2011 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
krboun Posted December 8, 2011 Author Posted December 8, 2011 I think i understand, AdlibRegister perform function during other part of scrip is running in case above while cycle is infinite and is there any way how to run script, or function in script in exact time (e.g. 6pm)??
Moderators Melba23 Posted December 8, 2011 Moderators Posted December 8, 2011 krboun,Look in the Help file under <Macro Reference - Time and Date Macros>. You will need to do something like this: If @HOUR = "18" And @Min = "00" And @SEC = "00" Then ; Run the function EndIfM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
kylomas Posted December 8, 2011 Posted December 8, 2011 krboun, There are many ways to do either of what you are asking, however, you are asking for a couple very different things. PLease define your goal and show whatever code you've produced, so far. Good Luck, 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
water Posted December 8, 2011 Posted December 8, 2011 Edit: Good evening water! Hi Melba! My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
krboun Posted December 8, 2011 Author Posted December 8, 2011 krboun, Look in the Help file under <Macro Reference - Time and Date Macros>. You will need to do something like this: If @HOUR = "18" And @Min = "00" And @SEC = "00" Then ; Run the function EndIf M23 thanks a lot that is perfect, i am stlill getting used to
krboun Posted December 14, 2011 Author Posted December 14, 2011 Hello i have a problem, my script si something like this: while 1 If @HOUR="19" Or @HOUR="01" Or @HOUR="07" Or @HOUR="13" And @MIN="00" then ..... .... .... sleep(1800000) ;sleep 5 hours Else sleep(50000) EndIf WEnd this script should perform at 1,7,13,19 o´clock in infine loop but i don´t know why it doesn´t work , i found that it doesn´t work only when i work with computer because it worked in the evenng at 1 O´clock but in the morning nothing
jchd Posted December 14, 2011 Posted December 14, 2011 Use parenthesis to express the correct condition you want. If (@HOUR="19" Or @HOUR="01" Or @HOUR="07" Or @HOUR="13") And @MIN="00" then This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
magodiez Posted December 14, 2011 Posted December 14, 2011 you miss a 0 in the 5 hours sleep(18000000) why are you sleeping 5 hours if you need 6 hours?? why don't do something like while 1 If (@HOUR="19" Or @HOUR="01" Or @HOUR="07" Or @HOUR="13") And @MIN="00" then $timeStart = TimerInit() yourFunction() sleep(21600000 - Round(TimerDiff($timeStart))) ;sleep 6 hours - execution time ;you don't need the else EndIf WEnd Func yourFunction() ... ... EndFunc
krboun Posted December 14, 2011 Author Posted December 14, 2011 sleep(18000000) is there because the script is very short and i want only one cycle each 6 hours (so 1 minute would be enough) but if there is 18000000 script will do nothing for 5 hours and last 1 hour will check for requested time (so script don´t have to check time every 50 seconds (therefore in the end is sleep(50000). i think my problem was missing brackes, i am still very new with autoit
magodiez Posted December 14, 2011 Posted December 14, 2011 sleep(18000000) is there because the script is very short and i want only one cycle each 6 hours (so 1 minute would be enough) but if there is 18000000 script will do nothing for 5 hours and last 1 hour will check for requested time (so script don´t have to check time every 50 seconds (therefore in the end is sleep(50000). i think my problem was missing brackes, i am still very new with autoit That's my point, if you only need a cycle every 6 hours, why don't you simply sleep for 6 hours (- execution time) after executing the cycle, so the script isn't checking the time in your computer every 50 seconds??? and if you really need to check it during the last hour, why 50 seconds and not 60??? Just trying to optimize it for you...
krboun Posted December 14, 2011 Author Posted December 14, 2011 That's my point, if you only need a cycle every 6 hours, why don't you simply sleep for 6 hours (- execution time) after executing the cycle, so the script isn't checking the time in your computer every 50 seconds???and if you really need to check it during the last hour, why 50 seconds and not 60???Just trying to optimize it for you... script can not sleep 6 hours because execution time is always different (it could be a few second or minutes) therefore after execution is 5 hours pause (just my estimate because of different lenght of script) and then i can look for 1 7 13 or 19 o´clock50 second checking periond ... i dont know 60 would be also good i want be sure i can not miss correct time
magodiez Posted December 14, 2011 Posted December 14, 2011 (edited) script can not sleep 6 hours because execution time is always different (it could be a few second or minutes) therefore after execution is 5 hours pause (just my estimate because of different lenght of script) and then i can look for 1 7 13 or 19 o´clock 50 second checking periond ... i dont know 60 would be also good i want be sure i can not miss correct time That's why I told you to sleep (6 hours - execution time), this way you don't need to be checking... no matters the execution time, you can wait the exact time: $timeStart = TimerInit() yourFunction() sleep(21600000 - Round(TimerDiff($timeStart))) ;sleep (6 hours - execution time) Have you tried to do it with the Windows Task Scheduler??? May be a better solution to your problem... Edited December 14, 2011 by magodiez
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