Saturday, May 26, 2007

VBScript Functions and Subroutines

The main difference between a function and a subroutine is that a subroutine will do some processing of the code and then quit, while a function processes some code and then returns the result back.

VBScript functions are described using the Function and End Function keywords.

Adding numbers by passing parameters:

Function to get square of a number:

A Sub procedure is a series of VBScript statements, enclosed by Sub and End Sub statements

I have written the calling statement (call square()) in the script itself.

Passing variable by reference example:

This shows that only the address is being passed that is why it is showing the updated value third time in Back in mysub.

Passing variable by value example:

This shows that another value is being passed as can be seen by the result of the third x as in Back in mysub.