Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VBScript Programs

VBScript Programs


VBScript can use two kinds of procedures:


VBScript Subroutines

Subroutines:

Sub mysub()

some statements

End Sub

or

Sub mysub(argument1,argument2)

some statements

End Sub

Example (for IE only)

Sub mysub()

document.write("I was written by a sub procedure")

End Sub

Try it »


VBScript Functions

Function procedures

Function myfunction()

some statements

myfunction=

some value

End Function

or

Function myfunction(argument1,argument2)

some statements

myfunction=

some value

End Function

Example (for IE only)

function myfunction()

myfunction=Date()

end function

Try it »


Calling Procedures

This simple function is called to calculate the sum of two parameters:

Example (for IE only)

Function myfunction(a,b)

myfunction=a+b

End Function

document.write(myfunction(5,9))

Try it »

The function "myfunction" returns the sum of parameter "a" and parameter "b". Here the return value is 14.

When you call a procedure, you can use the Call statement, as shown below:

Call MyProc(argument)

Alternatively, you can omit the Call statement, as shown below:

MyProc argument