ASP Sub Procedures
Sub procedure is collection of ASP statements that performs a
task and executes when it's called on event procedure.
Event procedure is any clickable objects or on load event.
Sub procedure does not return value but executes its content on call.
The following example uses sub procedure to write information stored
in variables:
<%
Sub GetInfo()
dim name,telephone,fee
name="Mr. Warsame Guled"
telephone="555-55555"
fee=1999
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 Sub procedure GetInfo.
This sub is executed right after the end sub.
|
You can pass an argument to the sub procedure and provide the
value(s) when calling it.
The following example is sub procedure that
takes an argument.
<%
Sub circle(r)
dim pi, area, diameter,circon
pi=3.14
area=pi*r^2
diameter=2*r
circon=2*pi*r
response.write("The Circle with radius of "&r&" has the area "&area)
response.write(" , diameter of " & diameter & " and circonference of "&circon)
End Sub
circle(2)
%>
|
ASP Function Procedures
A Function procedure is a series of VBScript statements enclosed by
the Function and End Function statements. A Function procedure is
similar to a Sub procedure, but can also return a value.
A Function procedure can take arguments (constants, variables, or
expressions that are passed to it by a calling procedure).
[msdn.microsoft]
Here is a syntax for none-parameterized function procedure:
<%
function userName()
userName="Maryamna"
end function.
%>
This function remembers user name. You can use this function any
number of times in your program and you change it once in here to
maintain. Use userName() to call this function.
eg; response.write("The usre name is: "& userName()).
Here is a syntax for parameterized function:
<%
Function total(price)
dim tax
tax=price*.09
total=price+tax
end Function
%>
The price value is provided when calling the function.
eg; response.write("Total price is: " & total(50)).
The following example is function procedure that
takes an argument.
<%
function profit(sellPrice, cost)
dim pr
profit=sellPrice-cost
End Function
dim currProfit
currProfit=profit(1280,890)
response.write("Profit: $"&currProfit)
%>
|
|