In my first review of your script I mention two Links How to use UDFs and How to write a UDF please read these then correct the function code that you just posted.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)