How to call subroutine in asp tutorial
Call a subroutine using VBScript, sample code:
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>You can call a program like this:</p>
<p>Result: <%call vbproc(3,4)%></p>
<p>Or, like this:</p>
<p>Result: <%vbproc 3,4%></p>
</body>
</html>
Call a subroutine using JavaScript, sample code:
<%@ language=javascript %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
<p>
Result: <%jsproc(3,4)%>
</p>
</body>
</html>
Call subroutines using VBScript and JavaScript, sample code: <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>
<p>Result: <%call vbproc(3,4)%></p>
<p>Result: <%call jsproc(3,4)%></p>
</body>
</html>
ASP source code can contain subroutines and functions:
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>Result: <%call vbproc(3,4)%></p>
</body>
</html>
Write the line <%@ language=language %> to <
html
> Above the tag, you can use another scripting language to write subroutines or functions:
<%@ language=javascript %>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>
<p>Result: <%jsproc(3,4)%></p>
</body>
</html>
Differences between VBScript and JavaScript
When calling a VBScript or JavaScript subroutine from an ASP file written in VBScript, you can use the keyword call, followed by the subroutine name. If a subroutine requires parameters, the parameters must be surrounded by parentheses when using the call keyword. If call is omitted, the parameters do not need to be surrounded by parentheses. If the subroutine has no parameters, the parentheses are optional. When calling a VBScript or JavaScript subroutine from an ASP file written in JavaScript, you must use parentheses after the subroutine name.