Jump to content
Sign in to follow this  
Guest aallison

Optional Function Parameters

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.


Anthony Allison

Share this post

Link to post
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.

Share this post

Link to post
Share on other sites
Guest aallison

Thanks for the speedy response. I'll try the empty string approach.

Share this post

Link to post
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


;Function with optional parameters
Func _MyFunc($psParms)
    $asParm = StringSplit($psParms, "|")
        Case $asParm[0] = 1
        Case $asParm[0] = 2
           ;..the optional timeout was passed

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.