ASP Subroutines


In ASP, you can call JavaScript subroutines from VBScript, and vice versa.


Subroutines

ASP source code can contain subroutines and functions:

Examples

<!DOCTYPE html>
<html>
<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>

<p>Result: <%call vbproc(3,4)%></p>

</body>
</html>

Demo Examples »

Put the <%@ language=language" %> line above the <html> tag, and you can use another scripting language to write subroutines or functions:

Examples

<%@ language="javascript" %>
<!DOCTYPE html>
<html>
<head>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
</head>
<body>

<p>Result: <%jsproc(3,4)%></p>

</body>
</html>

Demo Examples »


Differences Between VBScript and JavaScript

When calling a VBScript or JavaScript subroutine from an ASP file written in VBScript, you can use the "call" keyword, followed by the subroutine name. If the subroutine requires parameters, the parameters must be enclosed in parentheses when using the "call" keyword. If you omit the "call" keyword, the parameters do not need to be enclosed in 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.


Examples

More Examples

Call a Subroutine Using VBScript
This example demonstrates how to call VBScript subroutines and JavaScript subroutines in an ASP file.


Other Extensions