simple Posted December 23, 2005 Share Posted December 23, 2005 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 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 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 Link to comment Share on other sites More sharing options...
MHz Posted December 23, 2005 Share Posted December 23, 2005 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 Link to comment Share on other sites More sharing options...
LxP Posted December 23, 2005 Share Posted December 23, 2005 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... Link to comment Share on other sites More sharing options...
MHz Posted December 23, 2005 Share Posted December 23, 2005 (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. Edit: Code typo fixed. Edited December 23, 2005 by MHz Link to comment Share on other sites More sharing options...
Valik Posted December 23, 2005 Share Posted December 23, 2005 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. Link to comment Share on other sites More sharing options...
simple Posted December 23, 2005 Author Share Posted December 23, 2005 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 i only used Run (@ScriptDir & '\script.au3') and it works nice n simple Thanks again Link to comment Share on other sites More sharing options...
MHz Posted December 23, 2005 Share Posted December 23, 2005 (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 December 23, 2005 by MHz Link to comment Share on other sites More sharing options...
Valik Posted December 23, 2005 Share Posted December 23, 2005 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. Link to comment Share on other sites More sharing options...
MHz Posted December 23, 2005 Share Posted December 23, 2005 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. Link to comment Share on other sites More sharing options...
LxP Posted December 24, 2005 Share Posted December 24, 2005 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now