Jump to content

Optional Function Parameters


Guest aallison
 Share

Recommended Posts

Guest aallison

Is it possible to setup optional parameters in user-defined functions.

I saw a post suggesting passing in an array, but I was wondering if anyone know of something else.

Thanks,

Anthony Allison

Link to comment
Share on other sites

As of the current version, optional paramaters are not supported in UDF's. Two current solutions involve the use of an array, or using "placeholder" paramaters, like 0's or 1's or an empty string. Just have your function either check the array, or the paramaters for the fillers, and use some function default in its place.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

There's also the option of sending your parms in a pipe-delimited string that you then parse internally into an array:

;Calling the function ..
;--------------------------
    _MyFunc("hello")   ;standard call
    _MyFunc("hello|5");send optional timeout parm

EXIT


;Function with optional parameters
;----------------------------------------
Func _MyFunc($psParms)
    $asParm = StringSplit($psParms, "|")
    Select
        Case $asParm[0] = 1
            MsgBox(0,"",$asParm[1])
        Case $asParm[0] = 2
           ;..the optional timeout was passed
            MsgBox(0,"",$asParm[1],$asParm[2])
    EndSelect
EndFunc
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...