kzar Posted March 29, 2007 Posted March 29, 2007 I was wondering is it possible to make a function that takes autoit code as a parameter and then runs that code? I am trying to get rid of a lot of duplication in my script. Thanks
dabus Posted March 29, 2007 Posted March 29, 2007 What do you mean if you say "run code" ? AutoIt3.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line" Or Sample ('calc.exe') Sample ('notepad.exe') Sample ('cmd.exe') Func Sample ($a) MsgBox(0, 'Sample', 'This is '&$a) Sleep (1000) MsgBox(0, 'Sample', $a&' is getting ready') Run ($a) ;.... EndFunc
kzar Posted March 29, 2007 Author Posted March 29, 2007 No I don't meen run a executable or somthing. In your example you pass sample a string containing the filename of the program you would like to execute. I would like it to actually treat the string as autoit code and run it.
Shevilie Posted March 29, 2007 Posted March 29, 2007 That should do the trickhttp://www.autoitscript.com/autoit3/docs/f...ons/Execute.htm Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit
xcal Posted March 29, 2007 Posted March 29, 2007 (edited) Or does he mean... AutoIt3.exe /AutoIt3ExecuteLine "MsgBox(0, 'My Message Box', 'Woot!')" or from the helpfile... Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(0, ''Hello World!'', ''Hi!'')"') ? Edited March 29, 2007 by xcal How To Ask Questions The Smart Way
kzar Posted March 30, 2007 Author Posted March 30, 2007 (edited) Cool thanks thats what I was after. I was trying to cut out code duplication in my scripts. I have been using lod3n's idea from another topic to automate program installs reliably by looping through all the possible different windows there could be, handling them and waiting till they are gone: run("installer.exe") while 1 sleep(100) select case WinExists("Confirmation","Are you sure") ControlClick("Confirmation","Are you sure","Button2") While WinExists("Confirmation","Are you sure") sleep(100) wend case WinExists("Installation Complete","Installation completed succ") ControlClick("Installation Complete","Installation completed succ","Button1") While WinExists("Installation Complete","Installation completed succ") sleep(100) wend exitloop endselect wend exit So here is what I have got so far, I get an error on line 4 I think because I have a string going over several lines. Anyway my question is am I on the right track here or would you do it a different way? I am trying to make reliable installer automation scripts that are as neat as possible with little duplicated code. ; This If statement would be a case in a select inside a loop normaly If WinExists("Example window", "Welcome to the example program blah blah") Then HandleWin("Confirmation","Are you sure", "Example window", "Welcome to the example program blah blah", "MsgBox(0, 'Huray', 'it worked!') MsgBox(0, 'Huray', 'And this!')") EndIf Func HandleWin($title, $text, $commands) ; Split up the commands and count $command = StringSplit($commands, '\n', 1) $commandCount = UBound($command) ; Loop through commands and execute them For $i = 0 to $commandCount Step +1 Execute($command[$i]) Next ; Wait for window to close While WinExists($title,$text) sleep(100) wend Return $value EndFunc Thanks Edited March 30, 2007 by kzar
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