Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

ASP VBScript Sub Procedures

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.

Sub subName()
  code statements
End Sub

A Sub can take parameters as shown below.

Sub subName(parameter1, parameter2)
  code statements
End Sub

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 interchangeably.

One of the most common uses of Subs in ASP is to write html code and text, an example is shown below.

Sub writeFooter()
  Response.Write "<table><tr><td>"
  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>"
  Response.Write "</td></tr></table>"
End Sub

Calling a Sub in ASP is very simple, as shown below.

<% writeFooter %>

Or with arguments, as shown below.

sub multNums(num1,num2)
  response.write(num1 * num2)
end sub

multNums(6, 5)

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2010 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269