OOP Lesson 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

Computer Programming

3 – O.O.P
Vb.Net Looping Statements
• For Next Loop - is used to repeatedly execute a sequence of code or a block of
code until a given condition is satisfied. A For loop is useful in such a case when
we know how many times a block of code has to be executed. In VB.NET, the For
loop is also known as For Next Loop.
Vb.Net Looping Statements
• For Each loop is used to iterate block of statements in an array or collection
objects. Using For Each loop, we can easily work with collection objects such as
lists, arrays, etc., to execute each element of an array or in a collection. And
when iteration through each element in the array or collection is complete, the
control transferred to the next statement to end the loop.
Vb.Net Looping Statements
• Do While loop is used to execute blocks of statements in the program, as long
as the condition remains true.
Vb.Net Looping Statements
• While End loop is used to execute blocks of code or statements in a program,
as long as the given condition is true. It is useful when the number of executions
of a block is not known. It is also known as an entry-controlled loop statement,
which means it initially checks all loop conditions.
What is OOP?
• Stands for Object Oriented Programming.
• OOP is a computer programming model that organizes
software design around data, or objects, rather than
functions and logic. An object can be defined as a data field
that has unique attributes and behavior. It also focuses on
the objects that developers want to manipulate rather than
the logic required to manipulate them. This approach to
programming is well-suited for programs that are large,
complex and actively updated or maintained.
What is a Sub?
• A Sub is a procedure that performs a task and then returns
control to the calling code, but it does not return a value to
the calling code. Each time the procedure is called, its
statements are executed, starting with the first executable
statement after the Sub statement and ending with the first
End Sub or Exit Sub.
• Sub Declaration Syntax

• Example
What is a Function
• A Function is a series of statements enclosed by the Function
and End Function statements. The Function procedure
performs a task and then returns control to the calling code.
When it returns control, it also returns a value to the calling
code. Each time the procedure is called, its statements run,
starting with the first executable statement after the
Function statement and ending with the first End Function,
Exit Function or Return statement encountered.
• Function Declaration Syntax

• Example
Function Returning Values
• Using Return keyword - It uses the Return Keyword to specify
the return value, and returns control immediately to the
calling program. The following example illustrates this.
• Using own function name - It assigns a value to its own function name in one
or more statements of the procedure. Control does not return to the
calling program until an Exit Function or End Function Keyword is
executed. The following example illustrates this.

The advantage of assigning the return value to the function name is that
control does not return from the procedure until it encounters an Exit
Function or End function. This allows you to assign a preliminary value and
adjust it later if necessary.
Recursive function
• a recursive function is a function that solves a problem by
solving smaller instances of the same problem. This
technique is commonly used in programming to solve
problems that can be broken down into simpler, similar
subproblems.
Classes
• A Class is a group of different data members or objects with the
same properties, processes, events of an object, and general
relationships to other member functions.
• We can create a class using the Class keyword, followed by the
class name. And the body of the class ended with the statement
End Class.
[ Access_Specifier ] Class ClassName
' Data Members or Variable Declaration
' Methods Name
' Statement to be executed
End Class
Objects
• Objects are the basic run-time units of a class. Once a class is
defined, we can create any number of objects related to the
class to access the defined properties and methods.

' Declaration of object


Dim Obj_Name As Class_Name = New Class_Name()
' Access a method using the object
Obj_Name.Method_Name()
Constructor
• In VB.NET, the constructor is a special method that is
implemented when an object of a particular class is created.
Constructor is also useful for creating and setting default
values for a new object of a data member.
• Example
Parameterized Constructor
• In VB.NET, when we pass one or more arguments to a
constructor, the constructor is known as a parameterized
constructor. And the object of the class should be initialized
with arguments when it is created.
• Example
Arrays
• array stores a fixed-size sequential collection of elements of
the same type. An array is used to store a collection of data,
but it is often more useful to think of an array as a collection
of variables of the same type.
• All arrays consist of contiguous memory locations. The
lowest address corresponds to the first element and the
highest address to the last element.
• In the above declaration, array_name is the name of an
array, and the Data_Type represents the type of element
(Integer, char, String, Decimal) that will to store contiguous
data elements in the VB.NET array.
• Now, let us see the example to declare an array.
• In VB.NET, we can initialize an array with New keyword at
the time of declaration. For example,
Dynamic Arrays
• Dynamic arrays are arrays that can be dimensioned and re-
dimensioned as par the need of the program. You can
declare a dynamic array using the ReDim statement.
• Syntax for ReDim statement
• Example

You might also like