|KiXtart 2001 Manual|
|Action:||Declares the name, arguments, and code that form the body of a Function procedure.
A Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the values of its arguments. A Function procedure can be used on the right side of an expression in the same way you use any intrinsic function, such as Len or Asc, when you want to use the value returned by the function.
name [(argument1, argument2, [optional]argumentx)]
[name = expression]
|Remarks:||Function procedures have a global scope, that is, they are visible to all other scripts and procedures in the scripts. The value of local variables in a Function is not preserved between calls to the procedure.
You cannot define a Function procedure inside another procedure.
The Return statement causes an immediate exit from a Function procedure. Program execution continues with the statement that follows the statement that called the Function procedure. Any number of Return statements can appear anywhere in a Function procedure.
You call a Function procedure using the function name, followed by the argument list in parentheses, in an expression.
Note: Function procedures can be recursive, that is, they can call themselves to perform a given task. However, recursion can lead to stack overflow.
To return a value from a function, assign the value to the function name. Any number of such assignments can appear anywhere within the procedure. If no value is assigned to name, the procedure returns an empty value.
Variables used in Function procedures fall into two categories: those that are explicitly declared within the procedure and those that are not. Variables that are explicitly declared in a procedure (using Dim) are always local to the procedure. Variables that are used but not explicitly declared in a procedure are global.
Note: a procedure can use a variable that is not explicitly declared in the procedure, but a naming conflict can occur if anything you have defined at the script level has the same name. If your procedure refers to an undeclared variable that has the same name as another procedure, constant, or variable, it is assumed that your procedure is referring to that script-level name.
Function ReadNC( $ServerName )
;More examples can be found at the ScriptLogic.com Function Library.