OK - adding the "optional" parameters fixes the problem, but breaks the script when executed with 4.50. I changed the AScan line to
Code:
$P = AScan($UDFNames, $, 0, , 0)
which are supposedly the default values. 
Have I missed something? Are the "optional" parameters not really optional?
Thanks,
Glenn