Sign in to follow this  
Followers 0
Thomymaster

Calling a function with omitting some of its parameters, how?

7 posts in this topic

Hi

 

I wrote some functions which, if the require parameters, always have default values

Func _Example($sName,$sParam="",$bSilent=FALSE)
...
EndFunc

When i call the UDF and i only want the third parameter to be set (and not the second one, it goes to its default value) the following fails:

_Example("Test",,TRUE)

whereas this suceeds

_Example("Test","Param1",TRUE)

Is there a way in AutoIT to make the above work, so that if i completely omit a parameter, its taken from its default value in the function header?

 

Cheers Thomy

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

_Example("Test", "", True)

Edit:

Just send the default parameter data.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Use "Default" Keyword

_Example("Data",Default,True)

it`s easier.

Share this post


Link to post
Share on other sites

Use "Default" Keyword

_Example("Data",Default,True)

it`s easier.

Be careful with that... It's not used how you think it is in udf's.

Run this:

_Example("name", Default, True)
Func _Example($sName,$sParam="",$bSilent=FALSE)
    ConsoleWrite($sParam & @CRLF)
EndFunc

Which is why I said to do it how I had it ;) ...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

OK thanks.

And for what exactly is the "Default" keyword good?

I mean i can always set the default parameters in the UDF header like:

Func _test($iNum=1,$sString="Test")

Share this post


Link to post
Share on other sites

I wouldn't unless you're validating for the default keyword inside the function, and if it exists, changing the var to the default param string again, total waste of time unless you're making public functions IMO... test for yourself.

_test(Default, Default)
Func _test($iNum=1,$sString="Test")
    ConsoleWrite($sString & @CRLF)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

OK, thanks a lot for the explanation :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0