Sign in to follow this  
Followers 0
huskies

loop the same function with different wait times

8 posts in this topic

Hi I would like to run my GetData function that I wrote,the relevant parameter here is the last one, which indicates the time in seconds in should wait before running it self again. I haven't inplemeted this yet, so right now it's just a useless parameter.

For example I would like to run GetData for technician1 once every 1460000 seconds and the same for technicians2 once every 2460000 seconds. I can't seem to come up with a way to add that within the function itself. Because if I am looping a fucntion, it will just sit there and wait and will not move onto the next function.

Call ("GetData", technician1, 1460000) ;<-the last variable is the time I want the function to wait and then rerun itself
Call ("GetData", technician2, 2460000)
Call ("GetData", technician3, 1500000)
Call ("GetData", technician4, 3000000) 
Call ("GetData", technician5, 4760000) 
Call ("GetData", technician6, 5230000)

<It Shall Be Done>

Share this post


Link to post
Share on other sites



huskies,

I would look at Adlib in the Help file. It allows you to run a function at a specified interval without having to call it specifically. :)

By the way, you do not need to use Call in your posted code - it is only needed if you have the function name in a string variable. You just use the function name directly:

GetData(technician3, 1500000)
GetData(technician4, 3000000) 

; This is when you would use it

$sFunction = "GetData"
Call (sFunction, technician3, 1500000)
Call (sFunction, technician4, 3000000)

All clear? :)

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

Hi

Thanks for the reply, it does seem like a very good idea. However, it seems that in AdlibRegister , AdlibRegister ( "function" [, time] ), it doesn't give me an option to input parameters. So I can only do AdlibRegister ("GetData", 1460000) but I wouldn't be able to pass any parameters, such as the technician name. Is there a way to add that or do I have to add a functions for each technician? I want to avoid doing that because it will increase the file size.


<It Shall Be Done>

Share this post


Link to post
Share on other sites

huskies,

Just use some tiny wrapper functions like this: :)

HotKeySet("{ESC}", "On_Exit")

AdlibRegister("Tech1", 5000)

AdlibRegister("tech2", 7000)

While 1
    Sleep(10)
WEnd

Func Tech1()
    _GetData("Tech1")
EndFunc

Func Tech2()
    _GetData("Tech2")
EndFunc

Func _GetData($sTech)
    ConsoleWrite("GetData was called with " & $sTech & " as a parameter at " & @SEC & @CRLF)
EndFunc

Func On_Exit()
    Exit
EndFunc

Will that do? :)

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

Thank you very much! That will do


<It Shall Be Done>

Share this post


Link to post
Share on other sites

I have a question, is the code

While 1
    Sleep(10)
WEnd

to keep the program from shutting itself down? I didn't add that in my code because I didn't know it's purpose and my program will just close itself without calling anything in Adlib


<It Shall Be Done>

Share this post


Link to post
Share on other sites

huskies,

Indeed it is - otherwise, as you have found, the script just ends. Every program, be it a simple AutoIt script or the Windows OS itself needs an idle loop to keep it active waiting for the next input. That is why there was a HotKeySet("{ESC}", "On_Exit") line to give you an elegant way to break out of the loop. :)

As that question seems to indicate that you are relatively new to coding, could I recommend reading the Help file carefully (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) which will give you a good handle on how AutoIt code is structured. You might also consider looking at the excellent tutorials that you will find here and here - you can find other, rather more advanced, tutorials in the Wiki (the link is at the top of the page). :)

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

Thank you so much for the tip and I will definitely look into the tutorials


<It Shall Be Done>

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