|
It's a question of good coding practice.
Functions should (as far as possible) be black boxes. You supply input, you get output. All variables used within the function should be in the local scope - there are a couple of exceptions but this rule should hold generally true.
Having the UDF change the environment of the parent process is generally a bad idea, as it leads to hard to diagnose faults and makes the code far less portable. It also forces the parent process to declare variables in the global scope.
Howards solution safely returns the multiple values as an array, which is a little trickier to handle but avoids the scope issues. I'd add some helper constants to define what the array elements held to make the code easier to read when they are referenced.
In this case if the values are only every going to be used to write the line to a file a single formatted string could have been returned instead, but it's not clear if this is the case.
|