ASP Net Center.com


 
For ASP Hosting deals, Click Here!

l
l
l
l
l
l
l
l
l
l
l
l
Please visit our Sponsor:
VideoGameDeals.com (MyVGD.com) is the best place to buy video games!
For Video Game deals, Click Here!

l
l
l
l
l
l
l
l
l
l
l
l
ASP Tutorials & Basics
Introduction
Variables & Arrays
Sub & Functions
If Statements
Case Statements
Loop Statements
Date Objects
Form Processing
Text File Objects
Database Access
Adding Record
Updating Record
Deleting Record
Virtual Includes
Cookies
E-mail
Server Variables
Creating Login Page

ASP Sub Procedures

ASP Sub Procedures are a collection of ASP statements that perform a task, and are executed by an event procedure. Event Procedures are any clickable objects, or onload event. Sub procedures do not return a value, but executes it's content on "call".

 

 
This is an asp sub procedure that is used to write information stored in variables:
 
<%
Sub GetInfo()
dim name,telephone,fee
name="Mr. John Doe"
telephone="555-5555"
fee=20
Response.write("Name: "& name &"<br>")
Response.write("Telephone: "& telephone &"<br>")
Response.write("Fee: "& fee &"<br>")
End Sub
GetInfo()
%>
This example simply declares, populates, & writes three variables in the asp sub procedure, 'GetInfo'. This sub is executed right after the end sub.
 
Here is the execution result:
 
Name: Mr. John Doe
Telephone: 555-5555
Fee: 20

 
You can pass an argument to the asp sub procedure, and provide the value(s) when calling it.
This is an asp sub procedure that accepts an argument:
 
<%
Sub circle(r)
dim pi,area,diameter,circum
pi=3.14
area=pi*r^2
diameter=2*r
circum=2*pi*r
Response.write("The Circle with a radius of: "&r&" has the area of: "&area)
Response.write(", the diameter of: "&diameter&" and a circumference of: "&circum)
End Sub
%>
Here is the execution result:
 
The Circle with a radius of: 2 has the area of: 12.56, the diameter of: 4 and a circumference of: 12.56

 

 

ASP Function Procedures

ASP Function Procedures are a series of VBscript statements enclosed by the 'Function', and 'End Function' statements. Function procedures are similar to a 'Sub procedure', but can also return a value. An asp function procedure can accept arguments (constants, variables, or expressions) that are passed to it by calling a procedure).
 
This is a none-parameterized asp function procedure:
 
<%
function userName()
userName="MaryLou"
end function
%>

 
This function procedure remembers a username. You can use this function any number of times in your program, and you can change it once to maintain it- use 'userName()' to call this function. For example: response.write("The username is: "&userName())
 
This is a parameterized asp function procedure:
 
<%
Function total(price)
dim tax
tax=price*.09
total=price+tax
end Function
%>

 
The price value is provided when calling the function- Example: response.write("The total price is: " & total(50))
This is an asp function procedure that accepts an argument:
 
<%
Function profit(sellPrice, cost)
dim pr
profit=sellPrice-cost
End Function
dim currProfit currProfit=profit(1280,890) Response.write("Profit: $"&currProfit)
%>
Here is the execution result:
 
Profit: $390

Variables & Arrays If Statements