dmitryunruh Posted February 21, 2010 Share Posted February 21, 2010 /* AutoIt3 Script Example */ Func MyFunc (ByRef $param = 0) ConsoleWrite ("Something" & @CRLF) EndFunc /* AutoIt3 Syntax Checker Output */ D:\DU\develop\AutoIt v3 Script.au3(8,27) : ERROR: syntax error Func MyFunc (ByRef $param = ~~~~~~~~~~~~~~~~~~~~~~~~~~^ D:\DU\develop\AutoIt v3 Script.au3 - 1 error(s), 0 warning(s) >Exit code: 2 Time: 0.207 /* Question */ Why ByRef parameter cannot be Optional? Or Why Optional parameter cannot be ByRef? ------------------------------------------------- AutoIt v3.3.4.0 and v3.3.5.4 Link to comment Share on other sites More sharing options...
BrettF Posted February 21, 2010 Share Posted February 21, 2010 Welcome to the forums dmitryunruh. You cannot do this because the way the function works. ByRef requires a variable as an input. So what happens in the end you are passing that variable to be used inside the function and subsequently to be change inside that function. Like so: ;$i = 1 $i = 1 MsgBox (0, "Value of $i", $i) ;$i = 11 $i = $i + 10 MsgBox (0, "Value of $i", $i) ;$i = 13 Plus2 ($i) MsgBox (0, "Value of $i", $i) ;Function to make number increase by 2 Func Plus2 (ByRef $iNumber) $iNumber += 2 EndFunc If you want it option you could do something like follows: Global $iNumber = 1 ;$iNumber= 1 $iNumber= 1 MsgBox (0, "Value of $iNumber", $iNumber) ;$iNumber= 11 $iNumber= $iNumber+ 10 MsgBox (0, "Value of $iNumber", $iNumber) ;$iNumber= 13 Plus2 () MsgBox (0, "Value of $iNumber", $iNumber) ;Function to make number increase by 2 Func Plus2 () $iNumber += 2 EndFunc What is your function? What is it's purpose? Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Beamer145 Posted August 9, 2014 Share Posted August 9, 2014 Reviving an old thread but it seems to be the most recent one treating the topic: What is your function? What is it's purpose? Possible example: I am looking for an image in the screen. By default I want to search the entire screen, but sometimes I want to pass an extra optional parameter with an array of 'search areas' (each search array is again an array with coordinates). It would be more performant if I could pass that optional parameter ByRef.... (especially since my top level search function goes about 5 levels deep by the time the actual searching is done, so the copy operations start to add up). If I don't want to pass the search areas I would use the default value 0 (cfr a NULL pointer) and test with IsArray or something.... Any tricks to realize this in Autit (apart from creating 2 functions or going the byval route as I currently do) ? Link to comment Share on other sites More sharing options...
Geir1983 Posted August 10, 2014 Share Posted August 10, 2014 Create a wrapper function without the "optional" array as an input, just calling the original function with an empty 0 elements array on the array input or something? Link to comment Share on other sites More sharing options...
water Posted August 10, 2014 Share Posted August 10, 2014 I suggest to create a new thread. The OP was using AutoIt v3.3.4.0 and v3.3.5.4. A lot has changed since then My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - 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