<head>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
</head>
<body>
<p>
You can call a procedure like this:
</p>
<p>
Result: <%call vbproc(3,4)%>
</p>
<p>
Or, like this:
</p>
<p>
Result: <%vbproc 3,4%>
</p>
</body>
</html>
<%@ language=javascript %> <html> <head> <% function jsproc(num1,num2) { Response.Write(num1*num2)}%></head><body><p>Result: <%jsproc (3,4)%></p></body></html> <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中子程式的應用程式之ASP基礎教學ASP原始碼可包含子程式和函數:
<html> <head><%sub vbproc(num1,num2)response.write(num1*num2)end sub%></head><body><p>Result: <%call vbproc(3,4)%> </p></body></html>
將<%@ language=language %>這一行寫到<html>標籤的上面,就可以使用另一個腳本語言來寫子程式或函數:
<%@ language=javascript %> <html> <head> <% function jsproc(num1,num2) { Response.Write(num1*num2) } %> </head> <body> <p>Result: <%jsproc (3,4)%></p> </body> </html>當從一個用VBScript寫的ASP檔案中呼叫VBScript或JavaScript子程式時,可以使用關鍵字call,後面跟著子程式名稱。假如子程式需要參數,當使用關鍵字call時必須使用括號包圍參數。假如省略call ,參數則不必由括號包圍。假如子程式沒有參數,那麼括號則是可選項。
當從一個用JavaScript編寫的ASP檔案中呼叫VBScript或JavaScript子程式時,就必須在子程式名稱後使用括號。