barrano247 Posted July 30, 2018 Share Posted July 30, 2018 Hello, basically I'm using /AutoIt3ExecuteScript and the RunWait function to run code within text files. I have a variable that is defined within the main autoit script, which I need to call from a .txt file which is run using /AutoIt3ExecuteScript. Unfortunately, I always get the error "variable $example is undefined" when AutoIT encounters $example in the .txt file. I've heard that there's no way to run code using a variable defined in the AutoIT script from another file via /AutoIt3ExecuteScript, but I want to make sure before I complicate my project any further. Thanks! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 30, 2018 Share Posted July 30, 2018 @barrano247 Can you please post ythe code you are working with? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
pixelsearch Posted July 30, 2018 Share Posted July 30, 2018 (edited) Hello barrano247, As you're working a lot with /AutoIt3ExecuteScript , Run & Runwait, this could help you. You can pass parameters between 2 scripts, like in the detailed example I just worked on, based on 2 scripts named "Test part1.au3" and "Test part2.au3" ; This is "Test Part1.au3" #include <MsgBoxConstants.au3> Local $par1 = "1st par (variable)", $par2 = 2 $iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & chr(34) & @ScriptDir & "\test part2.au3" & chr(34) & _ " " & chr(34) & $par1 & chr(34) & _ " " & $par2 & _ " " & "3" & _ " " & chr(34) & "4th par (string)" & chr(34)) If $iPID = 0 Then MsgBox($MB_SYSTEMMODAL, "Error", "'test part2' didn't lauch") Exit Else ProcessWaitClose($iPID) MsgBox($MB_SYSTEMMODAL, "Great", "This message shows only after 'test part2' has ended") EndIf ; This is "Test Part2.au3" #include <MsgBoxConstants.au3> $sParams = "$CmdLineRaw = " & $CmdLineRaw For $i = 0 To $CmdLine[0] $sParams &= @CRLF & "$CmdLine[" & $i & "] = " & $CmdLine[$i] Next MsgBox($MB_SYSTEMMODAL, "Parameters passed from 'test part1' to 'test part2'", Eval("sParams")) $CmdLineRaw and $CmdLine[0] are always accessible, in any script, without error when accessed. The value in $CmdLine[0] indicates how many parameters have been passed from one script to the other. Here I passed 4 parameters : two directly in the Run() command (param 3 & 4) and two as variables created before (param 1 & 2), so we have the syntax ok for different cases. Eval() without Assign() + the For/Next loop did a great job in "Test part 2", allowing to display all parameters fluently in MsgBox() with few code lines : nothing to change in "Test part 2" even if you got dozens of parameters ! Hope this helps Edited August 11, 2018 by pixelsearch Link to comment Share on other sites More sharing options...
barrano247 Posted July 31, 2018 Author Share Posted July 31, 2018 (edited) 14 hours ago, pixelsearch said: Hello barrano247, As you're working a lot with /AutoIt3ExecuteScript , Run & Runwait, this could help you. You can pass parameters between 2 scripts, like in the detailed example I just worked on, based on 2 scripts named "Test part1.au3" and "Test part2.au3" ; This is "Test Part1.au3" #include <MsgBoxConstants.au3> Local $par1 = "1st par (variable)", $par2 = 2 $iPID = Run(@AutoItExe & " /AutoIt3ExecuteScript " & chr(34) & @ScriptDir & "\test part2.au3" & chr(34) & _ " " & chr(34) & $par1 & chr(34) & _ " " & $par2 & _ " " & "3" & _ " " & chr(34) & "4th par (string)" & chr(34)) If $iPID = 0 Then MsgBox($MB_SYSTEMMODAL, "Error", "'test part2' didn't lauch") Exit Else ProcessWaitClose($iPID) MsgBox($MB_SYSTEMMODAL, "Great", "This message shows only after 'test part2' has ended") EndIf ; This is "Test Part2.au3" #include <MsgBoxConstants.au3> $sParams = "$CmdLineRaw = " & $CmdLineRaw For $i = 0 To $CmdLine[0] $sParams &= @CRLF & "$CmdLine[" & $i & "] = " & $CmdLine[$i] Next MsgBox($MB_SYSTEMMODAL, "Parameters passed from 'test part1' to 'test part2'", Eval("sParams")) $CmdLineRaw and $CmdLine[0] are always accessible, in any script, without error when accessed. The value in $CmdLine[0] indicates how many parameters have been passed from one script to the other. Here I passed 4 parameters : two directly in the Run() command (param 3 & 4) and two as variables created before (param 1 & 2), so we have the syntax ok for different cases. Eval() without Assign() + the For/Next loop did a great job in "Test part 2", allowing to display all parameters fluently in MsgBox() with few code lines : nothing to change in "Test part 2" even if you got dozens of parameters ! Hope this helps Very interesting, thanks for the help I'll have to try this! @FrancescoDiMuro RunWait( '"' & @AutoItExe & ' " /AutoIt3ExecuteScript '&matnomat&'.txt' ) ;runs (and waits till done) the code in file to load values from zenai This is the line where I'm running /AutoIt3ExecuteScript in autoit (derp) Heres the code in the text file #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> $xpos = "1500" $ypos = "-2000" $zfpos = "-1500" $zlpos = "-1650" MouseClick($MOUSE_CLICK_LEFT, 276, 510, 1, 60) ;click on lowest item in list MouseClick($MOUSE_CLICK_LEFT, 322, 494, 1, 60) ;click on move MouseClick($MOUSE_CLICK_LEFT, 258, 494, 1, 60) ;click on add item MouseClick($MOUSE_CLICK_LEFT, 288, 513 + (17*(4)), 1, 30) ;click on the new item to edit it MouseClick($MOUSE_CLICK_LEFT, 322, 494, 1, 60) ;click on move MouseClick($MOUSE_CLICK_LEFT, 85, 590, 3, 300) ;double-click on xpos field Send("{BACKSPACE}") ;clear xpos field Send($xpos) ;enter xpos info MouseClick($MOUSE_CLICK_LEFT, 85, 638, 3, 300) ;double-click ypos field Send("{BACKSPACE}") ;clear ypos field Send($ypos) ;enter ypos info MouseClick($MOUSE_CLICK_LEFT, 85, 686, 3, 300) ;double-click zpos field Send("{BACKSPACE}") ;clear zpos field Send($zfpos) ;enter z first MouseClick($MOUSE_CLICK_LEFT, 184, 507, 1, 60) ;click set first MouseClick($MOUSE_CLICK_LEFT, 85, 686, 3, 300) ;double-click zpos field Send("{BACKSPACE}") ;clear zpos field Send($zlpos) ;enter z last MouseClick($MOUSE_CLICK_LEFT, 184, 547, 1, 60) ;click set last MouseClick($MOUSE_CLICK_LEFT, 272, 512, 1, 60) ;click on lowest item in the list MouseClick($MOUSE_CLICK_LEFT, 292, 494, 1, 60) ;click remove button This code works, but in line #12 w/ the ";click on the new item" comment ideally id pass a variable $spm instead of that 4 in parentheses, which is defined in autoit. Edited July 31, 2018 by barrano247 Link to comment Share on other sites More sharing options...
barrano247 Posted August 7, 2018 Author Share Posted August 7, 2018 (edited) @pixelsearch Thank you so much for your help, I finally got around to testing your code and I got it to work in a 'test' run. I presume it will work in my actual script with the way I've implemented it. I'l be sure to come back if I have any new questions! Edited August 7, 2018 by barrano247 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