Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP Procedures

ASP Subroutines


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


Subroutines

ASP source code can contain subroutines and functions:

Example

<%

sub vbproc(num1,num2)

response.write(num1*num2)

end sub

%>

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

Demo Example »

data to the child component via <%@ language="languagePlace the "%>" line above the tag to write subroutines or functions in another scripting language:

Example

<%@ language="javascript" %>

<%

function jsproc(num1,num2)

{

Response.Write(num1*num2)

}

%>

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

Demo Example »


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, they must be enclosed in parentheses when using the "call" keyword. If you omit the "call" keyword, the parameters do not need to be 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.


More examples

Calling Subroutines with VBScript
This example demonstrates how to call VBScript and JavaScript subroutines in one ASP file.