Jump to content

Calling other autoIt scripts within a script


Recommended Posts

I have a parent script. In it is a label called $progress.

I have a child script (child.au3). In it is a function called "do_some_stuff", it makes reference to $progress.

How do I include/inherit the child so I can call the function "do_some_stuff" from the parent script?

Thanks in advance.

Edited by dazza
Link to comment
Share on other sites

It depends...

If "child.au3" is only user defined functions (UDFs) you can use

#include <child.au3>

However, if child.au3 is more than just some UDFs you will have to merge the two together.

Bob

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

I don't know that there are any "rules" regarding UDF's for your own use. Basically, if child.au3 consists of only variable and constants definitions and functions (defined by Func and EndFunc statements) then it can be included without too much issue. Essentially, the "included" scripts are appended to the front of your script. Thus, if you have instructions such as creating a GUI or running other code outside of a function, this code will be executed before your "main" script. Typically, includes only have function definitions that can then be called in the main script; however, there could be instances where there are code snippits that you want to always run thus you put them in an include (such as a splash screen or a particular memory allocation). This is bad practice as these things could be put into UDF's and called from the main script. If the "child.au3" only has one function that you want you use, you may want to isolate that function and put it into its own .au3 file or append it to your main script. Without seeing the particular scripts, this is about as much help as can be offered.

If you want to include your "child.au3" file use #include "[path\]filename" (notice quotes instead of <> to define the file). The path is relative to the script location so in your instance should be #include "/scripts/child.au3"

Hope this helps.

Bob

You can't see a rainbow without first experiencing the rain.

Link to comment
Share on other sites

That's cracking. Cheers mate.

The final chapter to this thread involves the following (and then I'm done...honest)

parent.au3 has a listbox of script names e.g. child1, child2, child3 etc.

Each child carries a single function of the same name eg child1, child2, child3

If I click in the listbox in parent gui and select child2, and then a RUN button: how do I get the function (Func child2) to run?

Something like:

Func run_this_script

call_the_function(listbox.text)

EndFunc

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