Sign in to follow this  
Followers 0
dazza

Calling other autoIt scripts within a script

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Ok...

1) How do I merge scripts

2) What are the rules of an UDF, and if child.au3 sits in @scriptdir/scripts/ how do I put his into the #include?

Thanks again.

Share this post


Link to post
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.

Share this post


Link to post
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

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