Guest aallison Posted July 1, 2004 Share Posted July 1, 2004 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 More sharing options...
pekster Posted July 1, 2004 Share Posted July 1, 2004 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 More sharing options...
Guest aallison Posted July 1, 2004 Share Posted July 1, 2004 Thanks for the speedy response. I'll try the empty string approach. Link to comment Share on other sites More sharing options...
trids Posted July 2, 2004 Share Posted July 2, 2004 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 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