Professional Documents
Culture Documents
Sub Main()
Call area(4)
Console.ReadKey()
End Sub
End Module
We can pass parameters to procedure by 2
methods
1 parameters by value(ByVal):
ByVal means that a copy of the provided value
will be sent to the procedure
2 parameters by reference(ByRef):
ByRef in means that a reference to the original
value will be sent to the procedure.
1.2 Function
• The function statement is used to define
functions like a Sub procedure but it can
return a value of a particular data type.
Syntax
[modifiers]Function functionname[(parameter
list)] As returntype
[statement]
End Function
WAP to find area of circle
Function area(ByVal r As Double) As double
Dim a As Double
a = 3.14 * r*r
Return a
End Function
Sub Main()
Dim a1 As Double
a1 = area(4)
Console.WriteLine("area" & a1)
Console.ReadKey()
End Sub
2 Class and object
• Class is a collection of data members, methods
and properties and events
• It is used to define new datatypes
• Class is referred as user defined datatype.
• Class is a blue print for an object
• To use class we need a object
Syntax
• [Access specifiers] Class Classname
[variables]
[methods]
[properties]
[events]
End Class
• Variables or fields to represent data
• Methods or operations to performed on that
data
• Properties which are used to access the
private data
• Events to perform some activities when occur.
2.1 Field in class
• Field is a member of a class which holds data
• Syntax:
[Access specifiers] variable_name As [Datatype]
• To access methods
• Objectname.Methodname()
Syntax
Dim objectname As classname= New classname
Or
End Class
Sub Main()
Dim obj As New test
obj.disp()
Console.ReadKey()
End Sub
3 Access specifiers
• Private – private members are accessed within class
• Public – public members are accessed to anyone
• Friendly- they are accessible to methods of any class in
friend class(within class +within project )
• protected- can be accessible from containing class
types inherited from containing class(within
class+derived class).
• Protected friendly- they are accessible to methods of a
class, methods of derived class from it(derived class+
+within class +within project).