The
ASP functions and ASP procedures provide a way to create reprogramming code available modules and avoid rewriting code each time you perform a specific task in the same block. If you do not have any functions/ASP pages in the program, ASP page execution from top to bottom, the ASP parsing engine is only processing from the beginning to the end of the entire file. Asp/vbscript functions and programs, however, only in the so-called execution, do not conform to the rest of the code inline. A function or subroutine can be reused as needed, thus saving you time and a less-than-favorite bunch of beautiful web-making tutorials many times.
You can write them in a similar way in the ASP to write them in visual Basic. It is good programming practice to use functional modular code and better provide reuse. To declare a subroutine (the function does not return a value, starts with the group keyword and ends with the end), you simply type:
<%@ language= "VBSCRIPT"%>
<%
Sub subroutinename ( Parameter_1, ..., parameter_n)
statement_1
statement_2
... The
statement_n
End Sub
%>
function differs in that it returns the data, the keyword of the feature, and ends the start function subroutine. Functions are especially good for doing calculations and returning a value. The syntax for declaring a function is similar to the following:
<%@ language= "VBSCRIPT"%>
<%
function functionname (parameter_1, ..., parame Ter_n)
statement_1
statement_2
...
statement_n
End Function
%>
appears in a program code that prints information on a page
Select actionselect alltry it<%@ LAN Guage= "VBSCRIPT"%>
<%
Sub GetInfo (name, phone, fee)
Response.Write ("Name:" & name &) ;br> ")
Response.Write (" Telephone: "& Telephone &" <br> ")
Response.Write (" Fee: "& Amp Fee & "<br>")
End Sub
%>
Now let's consider how to call theChild There are two ways:
<%
' The first way
call GetInfo ("Mr. O ' Donnel", "555-5555")
' second one
GetInfo ' Mr . O ' Donnel ', ' 555-5555 ',
%>
In each case, the actual arguments are passed to the child process and are passed in the appropriate position. Note that if you use a telephone declaration, the parameters must be enclosed in parentheses. If you do not use the phone, parentheses are not used.
Now let's look at a function that takes an integer value code and returns the square of that value. It also includes code to call the function.
<%
Function Square (num)
Square = num * num
End Function
' Returns 25
Response.Write (Square (5))
' Should print ' is less than 8^2
If < Square (7) Then
Response.Write ("is less than 8^2")
Else
Response.Write ("8^2 is less than 40")
End If
%>