ASP functions and ASP processes 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 (function does not return a value, start with the Group keyword, and end up with the end), you simply type:
<%@ language= "VBSCRIPT"%>
<%
Sub subroutinename (parameter_1, ..., parameter_n)
Statement_1
Statement_2
...
Statement_n
End Sub
%>
The function is different in that it returns the data, and the function of the keyword, and finally 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, ..., parameter_n)
Statement_1
Statement_2
...
Statement_n
End Function
%>
In a program code that prints information on a page, it looks
Select Actionselect alltry it<%@ language= "VBSCRIPT"%>
<%
Sub GetInfo (name, phone, fee)
Response.Write ("Name:" & name & "<br>")
Response.Write ("Telephone:" & Telephone & "<br>")
Response.Write ("Fee:" & Fee & "<br>")
End Sub
%>
Now let's consider how to invoke the child. There are two ways of doing this:
<%
' The
Call GetInfo ("Mr. O ' Donnel", "555-5555", 20)
' The second One
GetInfo "Mr O ' Donnel", "555-5555", 20
%>
In each case, the actual parameters are passed to the sub 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
%>