==========================================
Part I: Why User-Defined Functions (UDFs)?
==========================================
Why do you want to write a UDF?
Most scripts contain actions that are performed multiple times. Just think of mapping 5 shares to drive letters. You end up having five sections that delete the potentially existing old drive mapping, create the new drive mapping, check for errors, and print out error/success messages. By using a UDF you encapsulate these steps in to a function/endfunction segment and pass information into the function as parameters just like you'd do with regular KiXtart functions. You now have a UDF.
Once you have this UDF, you can call it from anywhere in your script. You can also create a separate file containing UDFs as a library. You initialize this library at the beginning of your script and you now have a whole collection of UDFs availabe to you. The Kixtart.org UDF Forum already contains over 300 UDFs performing a wide range of tasks.
Another advantage of this UDF collection is that you can use them in different scripts by just including your library. You can easily share these functions with other script-writers and standardize your scripts based on these functions.
The next part will illustrate a standardized UDF format based on best practices collected from different UDF authors. It gives a good introduction in how to write a UDF that is easy to understand, portable, and emulates native KiXtart functionality pretty well.


Edited by kdyer (2004-02-09 04:47 PM)
_________________________
There are two types of vessels, submarines and targets.