分享

ASP Sub Procedures---ASP Function Procedures

 liu_jinbo 2006-09-16

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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多