|
Procedures
ASP code can contain procedures and functions:
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body> The result of the calculation is: <%call vbproc(3,4)%>
</body>
</html>
Use the HTML <script> tag to include procedures or functions
that is written in another scripting language than the default:
<html>
<head>
<script language="javascript" runat="server">
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
</script>
</head>
<body> The result of the calculation is: <%jsproc(3,4)%>
</body>
</html>
The "language" attribute in the <script> tag defines the script
language for the code block inside the script element. The "runat=server"
attribute in the <script> tag defines that this is a server side
script. If you omit the "runat=server" attribute, the script
will be executed on the browser.
Calling a Procedure
When calling a JavaScript procedure from a VBScript, always use
parentheses after the procedure name.
When calling a JavaScript procedure or VBScript procedure from a
JavaScript, always use parentheses after the procedure name.
When calling a VBScript procedure from a VBScript, you can use
the "call" keyword before the procedure name. If the procedures
requires parameters, the parameter list must be enclosed in
parentheses. If you do not use the "call" keyword, and the
procedures requires parameters, the parameter list must not be
enclosed in parentheses.
Example
1.How to call a VBScript procedure from VBScript.
Coding
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
The result of the calculation is:
<%call vbproc(3,4)%>
</body>
</html>
Output
The result of the calculation is: 12
2.How to call a JavaScript procedure from a JavaScript.
Coding
<%@ language="javascript" %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
The result of the calculation is:
<%jsproc(3,4)%>
</body>
</html>
Output
The result of the calculation is: 12
3.How to call a JavaScript procedure and a VBScript procedure
from a VBScript.
Coding
<html>
<head>
<%
sub vbproc(num1,num2)
Response.Write(num1*num2)
end sub
%>
<script language="javascript" runat="server">
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
</script>
</head>
<body>
The result of the calculation is:
<%call vbproc(3,4)%><br><br>
The result of the calculation is:
<%call jsproc(3,4)%>
</body>
</html>
Output
The result of the calculation is: 12
The result of the calculation is: 12
|