cag8f Posted December 2, 2010 Share Posted December 2, 2010 Hi all. I'm an amateur coder who is playing around with AutoIt for the first time. 2 questions, the first simple, the second more involved: 1. Is there a way for a function to exist on its own as a separate file? I'd then like to be able to call that function with parameters. 2. I'm trying to do this to test a rather complicated program (complicated for me at least). I'd obviously like to test my program as I keep adding to it. However testing it requires changing a handful of lines of code each time. To efficiently test my program, I thought of changing it to a function. Then I could call the function with a test parameter, which would tell the function to use certain lines of code for testing. Does that make sense? I'm sure people who code for a living have much better testing/QA methods. If anyone has the time, I'd really love to hear them. Thanks in advance! Link to comment Share on other sites More sharing options...
JohnOne Posted December 2, 2010 Share Posted December 2, 2010 do you mean the #include directive ? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2010 Moderators Share Posted December 2, 2010 cag8f,Two ways to do what you want:- 1. Use #include to get the "function" file into your main script. The content of the file will be incorporated into your main script at the point where you have the #include line - so make sure all the required variables are declared beforehand. If you do this, passing parameters is as easy as it is for any other function and getting return values is simple. - 2. Keep the file as a separate entity and run it from within your main script. In this case you would have to pass your parameters as part of the invocation command line within the main script:Run(@ScriptFullPath & " /AutoIt3ExecuteScript Function_file.au3 param1 param2 ...")You would then use the special $CmdLine array to determine what the parameters are - details are in the Help file under <Using AutoIt - Command Line Parameters>. However, getting any return values back to the main script is more tricky - there are lots of threads on inter-script communication to help, though. Over to you - you know where we are if you run into problems. M23 Fr33b0w 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
cag8f Posted December 2, 2010 Author Share Posted December 2, 2010 Thanks for the reply. I forgot to mention that I looked into #include. It seemed to be perfect, but I couldn't figure out how to pass parameters to the file. Is it as simple as: $param_1 = 1 ;Parameter 1 is defined in the main script #include <auxscript.au3> ; Does aux script now know the value of parameter 1? Link to comment Share on other sites More sharing options...
cag8f Posted December 2, 2010 Author Share Posted December 2, 2010 Nevermind, tested it and that appears to be how it works. Didn't think to try that very simple method. Thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2010 Moderators Share Posted December 2, 2010 (edited) cag8f, I couldn't figure out how to pass parameters to the fileThe joy of using #include is that you do not have to! The file in already in your script. A short example. Save this as "file_2.au3": Func _Sum($i1, $i2) Return ($i1 + $i2) EndFunc Now save this as "file_1.au3" and run it in SciTE: $iParam_1 = 1 $iParam_2 = 2 MsgBox(0, "Result", _Sum($iParam_1, $iParam_2)) #include "file_2.au3" You see that it works passing values each way. The #include directive means that "file_1.au3" actually looks like this as far as AutoIt is concerned: $iParam_1 = 1 $iParam_2 = 2 MsgBox(0, "Result", _Sum($iParam_1, $iParam_2)) Func _Sum($i1, $i2) Return ($i1 + $i2) EndFunc So you can see why you have no problems. All clear? M23 Edit: I see it is! Edited December 2, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
cag8f Posted December 2, 2010 Author Share Posted December 2, 2010 Thanks again for the help. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2010 Moderators Share Posted December 2, 2010 cag8f, My pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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