Laezylion Posted January 4, 2021 Share Posted January 4, 2021 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 ! Link to comment Share on other sites More sharing options...
Developers Jos Posted January 4, 2021 Developers Share Posted January 4, 2021 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. Link to comment Share on other sites More sharing options...
Earthshine Posted January 4, 2021 Share Posted January 4, 2021 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 Link to comment Share on other sites More sharing options...
Laezylion Posted January 4, 2021 Author Share Posted January 4, 2021 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 ! Link to comment Share on other sites More sharing options...
water Posted January 4, 2021 Share Posted January 4, 2021 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 Earthshine 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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