![]() |
|
|
Functions and Subprocedures Functions and subprocedures have many similarities: The difference between a function and a sub is that a sub will do some stuff (like printing something to the screen) and then quit, while a function runs some code and then returns the result back to the code that called it. A Function could be used to do a calculation and then return a result. How to declare/write each: <% <%
You will notice above parameter1 and parameter2. Data is passed
into a procedure through the use of these arguments. Arguments are
separated by commas and put into parenthesis after the procedure
name. <% Below is a subprocedure that prints out details on the page: <% To call the Sub, I could do one of the following: <% OR <% Note that in each example, the actual argument passed into the
subprocedure is passed into the subprocedure in the corresponding
position. Like the Sub procedure, a Function can accept arguments, but unlike the Sub procedure, a Function can return a value. Functions are especially good for doing calculations and returning a value. <% This is how the function was called: <% Sum=Total(2,100) %>
Calling the Total function made the value of Total equal to the value returned by the function, which then can be displayed by doing <% response.write Sum %>
The output of the above is: 102 Note that the returned value is named the same as the function.
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|