ASP VBScript Sub Procedures
By Stephen Bucaro
A procedure is a block of code that performs a task and can be referenced within
the program to performs that task. VBScript has two kinds of procedures: Subs and
Functions. The difference between a Sub and a function is that a function is that
a function returns a value, while a Sub does not.
Sub stands for subroutine. The term "subroutine" comes from the early days of computers
and is not used in any modern programming language. Actually, the term "procedure"
comes from the early days of computers and is not a term that is commonly used today.
Today's programming languages use functions and if no explicit return value is required,
a function always returns a value indicating if it has completed successfully.
The primary purpose of a Sub is to create a block of code that can be called by a
reference (it's name). You might want to place code in a block in order to organize
your program, but usually because you want to perform the task multiple times in
your program. An example of place code in a block for organizing purposes is if you've
used code form another program or from a code library.
Shown below is the structure of a Sub.
A Sub can take parameters as shown below.
Sub subName(parameter1, parameter2)
• There's a debate about the difference between the word "parameter" and "argument".
When you define a procedure, you are defining the parameters that will take the arguments.
When you call a procedure, you pass in arguments, the actual values of the variables that
get passed to the procedure. The general consensus is that it's OK to use these terms
One of the most common uses of Subs in ASP is to write html code and text, an example is shown below.
Response.Write "<a href='http://bucarotechelp.com/search/000600.asp'>[Site User Agreement]</a> "
Response.Write "<a href='http://bucarotechelp.com/search/000100.asp'>[Search This Site]</a> "
Response.Write "<a href='http://bucarotechelp.com/search/000700.asp'>[Contact Form]</a>"
Calling a Sub in ASP is very simple, as shown below.
<% writeFooter %>
Or with arguments, as shown below.
response.write(num1 * num2)