Sign in to follow this  
Followers 0
simple

#include <x.au3> and run(c:\x.au3) or another way?

10 posts in this topic

i hav no idea how to use autoit just a few days ago so im kinda new to this

what im tryin to make is a lil prog that wil run a 2nd script wit it at same time

i hav gone thru quite a few pages and found out 2 ways

i tried usin #include <> but all the scripts underneath it would stop workin :lmao:

i also tried usin run ("directory\x.au3") which kind of get half the result of what i wanted BUT that i have to put down the exact directory location like run ("C:\folder\x.au3") so if i move the folder wit the scripts im guess it wont work :P

how can i make it so it just runs the next script from the same directory as the startin script so tey both run together and if i move the script to another folder it still would work?

eg folder with 1st.au3 2nd.au3

Share this post


Link to post
Share on other sites



Here is a couple of functions that may help you run 2 scripts at once. Just add the functions to your main script and call the functions as shown at the top of code below. A function is available to suit your version of AutoIt.

; Example function call for 3.1.1 release to run a script.
_RunScriptProd(@ScriptDir & '\script.au3')

; Example function call for beta > v3.1.1.91 release to run a script.
_RunScriptBeta(@ScriptDir & '\script.au3')


; The functions which will do the work.

Func _RunScriptProd($script, $parameter = '')
; Run a Au3 file when uncompiled only. (3.1.1)
    If Not @Compiled And FileExists($script) Then
        Return Run(@AutoItExe & ' "' & $script & '" ' & $parameter)
    EndIf
    Return SetError(1) And 0
EndFunc

Func _RunScriptBeta($script, $parameter = '')
; Run a Au3 file when compiled or uncompiled. (> v3.1.1.91 beta)
    If FileExists($script) Then
        Return Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $script & '" ' & $parameter)
    EndIf
    Return SetError(1) And 0
EndFunc

Share this post


Link to post
Share on other sites

MHz, let me stray off-topic and say that I like what you've done here:

Return SetError(1) And 0

This idea is particularly useful for trimming code like this down:

If @Error Then
    SetError(1)
    Return 0
EndIf

If @Error Then Return SetError(1) And 0

I wonder if it can be easily adapted to return a blank string...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

MHz, let me stray off-topic and say that I like what you've done here:

Return SetError(1) And 0

This idea is particularly useful for trimming code like this down:

If @Error Then
    SetError(1)
    Return 0
EndIf

If @Error Then Return SetError(1) And 0

I wonder if it can be easily adapted to return a blank string...

Thanks. Multiline looks too basic at times.

Well for 1 line being a empty string can be:

$result = _test1()
MsgBox(0, '', @error & ' : "' & $result & '"')

$result = _test2()
MsgBox(0, '', @error & ' : "' & $result & '"')

Func _test1()
    If SetError(1) Then Return ''
EndFunc

Func _test2()
    SetError(1); Just forcing an error to test
    If @error And SetError(1) Then Return ''
EndFunc

Just makes you think to get it right now. :P

Edit: Code typo fixed.

Edited by MHz

Share this post


Link to post
Share on other sites

MHz, let me stray off-topic and say that I like what you've done here:

Return SetError(1) And 0

This idea is particularly useful for trimming code like this down:

If @Error Then
    SetError(1)
    Return 0
EndIf

If @Error Then Return SetError(1) And 0

I wonder if it can be easily adapted to return a blank string...

This is yet another one of the things I need to do. I proposed but never sent in a feature where-by SetError() takes a 3rd parameter which alters its return value to be the parameter. Thus the above could just be:

Return SetError(1, 0, 0)

Or to return 100:

Return SetError(1, 0, 100)

It would also support strings or arrays.

Share this post


Link to post
Share on other sites

Thanks for the help i got it to work the way i wanted now. Even though i dont get what most part of the codes does :P i only used Run (@ScriptDir & '\script.au3') and it works nice n simple :lmao:

Thanks again :(

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

; 3.1.1

$script = "script.au3"

Run(@AutoItExe & ' "' & $script & '"')

; or the present AutoIt Beta

$script = "script.au3"

Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $script & '"')

simple, Not sure how your solution works. Quoted a simpler solution for you to understand. i do not see it working without AutoIt running the au3 file.

Valik, do you wish to elaborate on your return concept ? It may make returns a clearer concept perhaps. On second thought, your 3rd parameter is just the return value of the function so is simply error, extended and return value. Sounds OK to me.

Edited by MHz

Share this post


Link to post
Share on other sites

Correct. Instead of SetError() always returning 1, it will instead return 1 by default unless the third parameter is specified in which case, the third parameter will be returned. I am not modifying the Return syntax, I think it will add confusion as opposed to clarity.

Share this post


Link to post
Share on other sites

Correct. Instead of SetError() always returning 1, it will instead return 1 by default unless the third parameter is specified in which case, the third parameter will be returned. I am not modifying the Return syntax, I think it will add confusion as opposed to clarity.

It is perhaps how it is conveyed across in the helpfile is to how easy to understand.

SetError ( error, [extended, [return value]] )

It takes getting used to like anything else. I'm in favor of correct timing of introduction of new functions etc and if this is suitable later then be it so.

Or perhaps some bigger and better idea may come before this is thought of implementing. Thanks for your idea. :P

Share this post


Link to post
Share on other sites

Valik, I like your idea of modifying SetError() to accept an optional return value. It would be great to see this incorporated into/before the next official release.

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