masonje Posted October 10, 2006 Share Posted October 10, 2006 (edited) I want to create my own runwait function to add some options, but I can't figure out how to create optional parameters. _runWait("file" [, working dir [, flag [, i/o flag]]]) How do I make a pass in variable optional? Edited October 10, 2006 by masonje Link to comment Share on other sites More sharing options...
jvanegmond Posted October 10, 2006 Share Posted October 10, 2006 The second parameter is optional and is by default 1. Func Add($a,$b=1) Return $a+$b EndFunc github.com/jvanegmond Link to comment Share on other sites More sharing options...
GaryFrost Posted October 10, 2006 Share Posted October 10, 2006 Func _MyFunc($s_text, $myflag = 0) ; do something here EndFunc $myflag would be optional SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
masonje Posted October 10, 2006 Author Share Posted October 10, 2006 Rock! I see that now in the help, but it didn't sink in....dork Link to comment Share on other sites More sharing options...
masonje Posted October 10, 2006 Author Share Posted October 10, 2006 (edited) question 2. is there a way to not have to put quotes around the "@SW_HIDE" option? As is, the _runWait() func goes to Else if I don't quote around the option. _runWait('net start "Automatic Updates"', "", "@SW_HIDE") Func _runWait($r, $w='', $f='', $sf='') AutoItSetOption("RunErrorsFatal", 0) Select Case $sf <> '' $pid = run($r, $w, $f, $sf) Case $f <> '' $pid = run($r, $w, $f) Case $w <> '' $pid = run($r, $w) Case Else $pid = run($r) EndSelect if @error Then MsgBox(48, "Error", "Error running " & $r) Return "error" Else ProcessWaitClose($pid) EndIf AutoItSetOption("RunErrorsFatal", 1) EndFunc BTW The only reason I'm doing a new runwait is b/c runwait doesn't always seem to stick. That and I want to be able to add some options...and learn more functions. Edited October 10, 2006 by masonje Link to comment Share on other sites More sharing options...
Helge Posted October 10, 2006 Share Posted October 10, 2006 Instead of all those Case's I think you can without any problems just make your function pass on the default values that your function uses, and for the third parameter you can just use @SW_SHOWDEFAULT as the default value. Also note that there is a macro called @NumParams which could have helped you if you choose to keep the Case's, however it's not needed in this case. 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