VBScript Statements: Explanation of the Function Statement
Posted by: Jerry Lees
The Function statement creates a function and allows you to list the arguments (if any) which are to be passed into the function.
The major difference between a function and a subroutine, is that a function can return a value. To return a value you use the function name as if it were a already declared variable and simply set the name of the function to the value you want to return. However, you do not not have to assign or Set a return value.
Functions can be declared Private or Public (the default). You can drop out of a function, without exiting the script entirely by using the Exit statement. You can call other functions or subroutines from within a function (nesting). You must end every function with End Function or you will get an error message.
Here is an example of a function and it’s use:
wscript.echo add(2,3)
function add(x , y)
add = x+4end Function



You must be logged-in to post a comment. Log-in/Register