The VBScript Network and Systems Administrator's Cafe

Sep 13 2008   11:11PM GMT

VBScript Statements: Explanation of the Function Statement

Jerry Lees Jerry Lees Profile: 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+4
end Function

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: