Sign in to follow this  
Followers 0
krboun

infinitely script repeating

19 posts in this topic

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

Share this post


Link to post
Share on other sites



krboun,

Welcome to the AutoIt forum. :D

Take a look at AdlibRegister in the Help file. It lets you run a function at reqular intervals. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

EndFunc
What is still needed is a way to tell the script to exit.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

While cycle works fine, thanks

but i don´t know how to y use AdlibRegister

script

Func _A ()
;something
EndFunc[/i]
AdlibRegister("_A",3000)

doesn´t do anything

Edited by krboun

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (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? :D

M23

Edit: Good evening water! :oops:

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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)??

Share this post


Link to post
Share on other sites

krboun,

Look in the Help file under <Macro Reference - Time and Date Macros>. :D

You will need to do something like this: :oops:

If @HOUR = "18" And @Min = "00" And @SEC = "00" Then
    ; Run the function
EndIf

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Edit: Good evening water! :oops:

Hi Melba! :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

krboun,

Look in the Help file under <Macro Reference - Time and Date Macros>. :D

You will need to do something like this: :oops:

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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... :)

Share this post


Link to post
Share on other sites

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´clock

50 second checking periond ... i dont know 60 would be also good ;) i want be sure i can not miss correct time

Share this post


Link to post
Share on other sites

#19 ·  Posted (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 by magodiez

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0