Jump to content

loop the same function with different wait times


Recommended Posts

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>
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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>
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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>
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...