Jump to content

optional func parameters


masonje
 Share

Recommended Posts

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 by masonje
Link to comment
Share on other sites

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 by masonje
Link to comment
Share on other sites

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

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...