Laezylion 0 Posted January 4 Hello everybody ! I'm using a function that takes one mandatory parameter, and accept several optional parameters. I'm kinda forced to use ALL parameters when I'll only need one : Func Example($iOne, $iTwo = 2, $iThree = 3, $iFour = 4) ;Whatever ... EndFunc Example(10, 10, Default, 40) Is there any way to call my function like this : Example(10, ifour = 40) Because setting all parameters to only use one is kinda boring ... specially with a function that can takes up to 12 different parameters ... I checked the help file with no answers, and digged this forum using this keywords : "function parameters" named optional With no results. Thanks in advance for your toughts ! Share this post Link to post Share on other sites
Jos 2,164 Posted January 4 Nope, that isn't valid syntax nor an option at this moment. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites
Earthshine 515 Posted January 4 How about you create a wrapper for the function that you want to use and set all the presets in that function when you call that and it calls down to the auto IT function using those pre-defined parameters My resources are limited. You must ask the right questions Share this post Link to post Share on other sites
Laezylion 0 Posted January 4 31 minutes ago, Earthshine said: How about you create a wrapper for the function that you want to use and set all the presets in that function when you call that and it calls down to the auto IT function using those pre-defined parameters Seems to be a lot of work, but in my case, might be worth It ... Will give it a shot ! Share this post Link to post Share on other sites
water 2,359 Posted January 4 If it doesn't have to be by name you could use something like this to set the parameters by number. Means: The first parameter goes to element 1 of the parameter array and so on. Example: Global $iParamsCount = 12 ; Maximum number of parameters of the function you want to call Global $aParams[$iParamsCount + 1] = ["CallArgArray"] ; Optional: Set all parameters to "Default" For $i = 1 To UBound($aParams)-1 $aParams[$i] = Default Next ; Set the needed parameters $aParams[3] = 123 Call(_TestFunction, $aParams) Exit Func _TestFunction($vP1 = Default, $vP2 = Default, $vP3 = Default, $vP4 = Default, $vP5 = Default, $vP6 = Default, $vP7 = Default, $vP8 = Default, $vP9 = Default, $vP10 = Default, $vP11 = Default, $vP12 = Default) ConsoleWrite("Number of Parameters: " & @NumParams & @CRLF) For $i = 1 To @NumParams $vParam = Eval("vP" & $i) ConsoleWrite("Parameter " & $i & ": " & $vParam & @CRLF) Next EndFunc ;==>_TestFunction 1 Earthshine reacted to this My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites