You are on page 1of 3

Functions. A function is a procedure that returns a value back to the caller. ...

Subroutines. A subroutine is a procedure that does not return a value to the caller. .
Parameters. A parameter is an ASP value that is passed to the procedure for the
purpose of completing a task. ...
Calling Procedures.
Functions

A function is a procedure that returns a value back to the caller. The “caller” is
where the procedure was invoked from. Functions are created (declared) using the
Function statement and terminated with an End Function statement.

<%

Function Area (l,w)

Area = l * w

End Function

%>

In the previous example, we have an example of a function that accepts two


parameters (more about parameters below). This function takes both parameters
and multiplies the two and returns the results to the calling process.

While this function returns data, there is no requirement for this to occur. You can
declare this function anywhere in your web page and it will be made available for
you to call from anywhere within the page.

Subroutines

A subroutine is a procedure that does not return a value to the caller. Subroutines
are declared using the Sub statement and terminated with an End Sub statement.

<%
Sub ShowDate
Response.Write("Today's Date is: ")
Response.Write(Now())
End Sub
%>
In this example, we have a subroutine that will simply write the string and current
date/time information on the screen. Unlike the function, no value is returned back
to the calling process. A subroutine may or may not have parameters passed.

Parameters
A parameter is an ASP value that is passed to the procedure for the purpose of
completing a task. Parameters can either be passed ByVal (by value) or ByRef (by
reference). If you pass the parameter by value, any changes to the parameter within
the procedure, will not be reflected in the original argument.

If you pass your parameter ByRef, then any changes to the parameter update the
original argument. If you want to pass your parameters ByRef, you must include
the Call statement, when calling the procedure.

<%
Function ProcName (var)
' If the calling process omits "Call", then the parameter is
' passed ByVal. If the keyword "Call" is included, the parameter
' is passed ByRef.
End

Sub ProcName(ByRef var)


' Calling process must specify the keyword "Call"
var = new value, but also updates value of the originating parameter
End Sub

Function ProcName (ByVal var)


' Calling process may specify or omit the keword "Call"
var = some new value
End Function
%>
Calling Procedures
When invoking a function or subroutine, you need to be aware of the different
calling conventions used for each. If you do not use the proper calling conventions,
you may get unexpected results (ByVal vs ByRef). Generally, when you call a
function or a procedure, you enclose the parameters within a set of parenthesis.
If you are passing string data, enclose the string within quotes. If you are passing
multiple parameters, separate the parameters using commas. Use the keyword Call,
especially if you are passing parameters via ByRef.
' Call a function, results are assigned to variable, myArea.
myArea = area(4,3)

' Ignore the results from the funtion, or


' call a subroutine
area(4,3)
' if passing ByRef, firstName and lastName will be
' updated if new values are assigned in the procedure.
Call fullName(firstName,lastName)
Namespace and Assembly ?
A .Net Namespace provides the fundamental unit of logical code grouping while
an assembly provides a fundamental unit of physical code grouping.
Namespace
Namespaces is a logical group of related classes that can be used by any other
language targeting the Microsoft .Net framework . It is more used for logical
organization of your classes. Namespaces are a way of grouping type names and
reducing the chance of name collisions.

Hierarchy and Fully-Qualified Names

The fully qualified name of a class is constructed by concatenating the names of all
the namespaces that contain the type. For e.g. the fully qualified name of the
TextBox class is System.Windows.Forms.TextBox . That means TextBox class is
contained in the Forms namespace that is contained in the Windows namespace
that is contained in the root System namespace.

Textbox namespace Hierarchy


Assembly-namespace
Assembly
An assembly is a collection of types and resources that are built to work together
and form a logical unit of functionality. It is an Output Unit, that is .exe or .dll file.
It is a unit of Deployment and a unit of versioning and also it contain MSIL
(Microsoft Intermediate Language) code. Assemblies are self describing, it
contains all the metadata about the modules, types, and other elements in the form
of a manifest.

Assemblies are of two types: Private and Shared Assemblies.

Private Assemblies

Private assembly is intended only for one application. The files of that assembly
must be placed in the same folder of the application.
Shared Assemblies

Shared assembly is to be made into a Shared Assembly, then the naming


conventions are very strict since it has to be unique across the entire system

You might also like