VBScript Statements: Explanation of the Function Statement - The VBScript Network and Systems Administrator's Cafe

The VBScript Network and Systems Administrator's Cafe

Sep 13 2008   11:11PM GMT

VBScript Statements: Explanation of the Function Statement



Posted by: Jerry Lees
VBScript, Functions, VBScript Statements, VBScript Functions

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+4
end Function

Comment on this Post


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