CSET 3250
Functions and Procedures

Introduction

Functions and procedures are named blocks of code that perform an action. In general, a function returns data and a procedure does not.

Procedures

In VBScript a procedure is defined by using the keyword Sub followed by the procedure name and any arguments, if needed. When used without arguments, a procedure must include an empty set of parentheses ( ).The End Sub keyword indicates the end of the procedure.

Sub procname (arg1, arg2, ..)
[code]
End Sub
The call statement can be used to call a procedure
call procname(arg1,arg2)

Functions
A function is a set of statements enclosed by the Function and End function keywords. It can take arguments that are passed to it by a calling procedure. Without arguments, it must include an empty set of parentheses ( ). A function returns a value by assigning a value to its name .

Function nameoffunction()
 [code]
nameoffunction = somevalue
End Function

 
The function can be called in the code as follows
valuereturned = nameoffunction()
The value returned by the function is stored in the variable valuereturned.
Another way of doing this is as follows.
msgbox "Your value is " & nameoffunction()

 

There have been visitors since 11/26/2003

Added to the Web: May 26, 2000.

Web page design by Dan Solarek.

http://cset.sp.utoledo.edu/cset3250/