Jump to content

Skipping Optional Parameters


Recommended Posts

I'm asking the same thing as this question, but it didn't get a clear answer, so I figured I'd ask more directly.

It appears that I can use the Default keyword in place of specifying a value to an optional parameter to have it behave as if I didn't specify anything all, while allowing me to specify optional parameters afterwards, like so:

GuiCreate("Title", 100, 100, Default, Default, $Style)

Is this the correct idiomatic method of skipping optional parameters to specify later ones?

Additionally, is there any gotchas I may have to look out for while doing this?

Link to comment
Share on other sites

https://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm

from doc :
GUICreate ( "title" [, width [, height [, left = -1 [, top = -1 [, style = -1 [, exStyle = -1 [, parent = 0]]]]]]] )
your :
GuiCreate("Title", 100, 100, Default, Default, $Style) 

option 1 :
GuiCreate("Title", 100, 100, -1, -1, $Style)

option 2 :
$gui = GuiCreate("Title", 100, 100)
;GUISetStyle ( Style [, ExStyle [, winhandle]] )
GUISetStyle ( $Style , -1 , $gui )
Quote

For UDF's, it is the scripter's responsibility to check if the parameter has been set to Default and to perform the desired behavior in this situation.

https://www.autoitscript.com/autoit3/docs/keywords/Default.htm u can test the sample of this page for understand better how Default works

Link to comment
Share on other sites

@Synapsee, you linked to the same pages I linked to, quoting things from the same pages.

You've shown two methods that appear to do the same thing as my snippet, but I don't know if they're actually the same; hence my question.

Is it more idiomatically correct to refer to the documentation and use the listed default values? And is using the Default keyword even consistently correct? This is, are there any built-in functions in which Default will not do the same thing as writing the default listed values in the documentation?

I understand that for UDFs, Default may not work, depending on the implementation; however, to my knowledge, the built-in functions aren't implemented in AU3; thus it would presumably be the job of the lexer to implement Default on a global level, which makes me think that Default should behave universally across all built-in functions.

Link to comment
Share on other sites

  • Developers
10 hours ago, nrmh said:

which makes me think that Default should behave universally across all built-in functions.

Correct.

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...