<% If Request("DontFrame")<>1 Then Response.Redirect "/iissamples/sdk/asp/docs/SampFram.asp?ovfile=/iishelp/iis/htm/sdk/samp58hf.asp&srcfile=Simple/Functions" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<META NAME="DESCRIPTION" CONTENT="Internet Information Server reference information"></HEAD>
<BODY BGCOLOR=#FFFFFF TEXT=#000000>
<font face="Verdana, Arial, Helvetica">
<h3><a name="_functions_and_procedures"></a>Functions and Procedures</h3>
<p>
Functions and procedures provide you with a convenient way to avoid having to rewrite the same block of code every time you want to perform a particular task. Both VBScript and JScript allow you to call a function or procedure from any point in a script. This sample demonstrates how you can create and use these tools with ASP. </p>
<p>
If you don't have any functions in your ASP page, the ASP engine simply processes your entire file, start to finish, each time it is requested by a client browser. Functions and procedures, however, are executed only when called, not in-line with the rest of the code. </p>
<p>
You can denote functions and procedures in VBScript or JScript using the <b>Function</b> statement. In addition, VBScript makes a distinction between a function that returns a value and functions that do not; the latter type are denoted with the <b>Sub</b> statement, indicating that it is a subroutine. </p>
<p>
This sample defines one function, <b>PrintOutMsg</b>, that takes as parameters a message, and a number that specifies how many times the message is to be written to the client browser with the <b>Response.Write</b> method. The function, for the purposes of this sample, simply returns the number of times the message was printed back to the client browser. </p>
<p>
It is also very important to note the RUNAT attribute of the <SCRIPT> tag. If this attribute is not included, ASP will assume that it is client-side scripting, and will pass the code back to the browser for processing. ASP would then not recognize <b>PrintOutMsg</b>, and would return an error and abort. </p>