0% found this document useful (0 votes)
27 views112 pages

FINAL

.NET is a framework developed by Microsoft for building various types of applications, not a programming language. It includes features like rich functionality, multi-language support, and automatic memory management, and consists of components such as the Common Language Runtime (CLR) and the Framework Class Library (FCL). The document also covers application types, IDE components, assembly concepts, and control statements in .NET.

Uploaded by

Abhay Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views112 pages

FINAL

.NET is a framework developed by Microsoft for building various types of applications, not a programming language. It includes features like rich functionality, multi-language support, and automatic memory management, and consists of components such as the Common Language Runtime (CLR) and the Framework Class Library (FCL). The document also covers application types, IDE components, assembly concepts, and control statements in .NET.

Uploaded by

Abhay Rana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 112

.

NET TERMINOLOGY

1. What is .NET?
 .NET stands for Network Enabled Technology.
 .NET is not programming language. It is a framework which provides
platform in which .NET application is executed.
 It is a product of Microsoft that was developed in 2000.
 It is used in the development of various kinds of application like
desktop based, web based, mobile based application etc.

2. Explain the features of .NET.


 Rich Functionality out of the box
 Easy development of web applications
 OOPs Support
 Multi-Language Support
 Multi-Device Support
 Automatic memory management
 Strong XML support
 Ease of deployment and configuration
 Security
3. What is Microsoft .NET Framework?
The Microsoft.NET Framework is the new computing platform from
Microsoft designed to simplify the development for distributed
environment such as the Internet. The .NET Framework is composed
of two main components
a. .NET Common Language Runtime or CLR
The CLR is the key component of the .NET Framework. It is a
common compiler for all Microsoft programming language. It
compiles all Microsoft languages to one Machine Language.
b. .NET Framework Class Library.

BY-NEERAJ KUMAR SINGH Page 1


A collection of ready-made reusable classes that work with the CLR.
Programmers using any of the .NET programming languages can use
these classes to include in their applications.

4. What is .NET framework class library(FCL)?


It provides the core functionality of .NET framework architecture. FCL
contains huge collection of classes, interface and value type.
FCL is organized in a hierarchical tree structure and it is divided into
namespace. The classes are accessed by namespace which reside within
assembly. The FCL classes are object oriented and easy to use in
program developments.
5. What is Common Language Runtime (CLR)

It is the execution engine of .NET framework where all .NET application


execute under the supervision of CLR

The CLR is the heart of .NET framework. It is .NET equivalent of Java


Virtual Machine (JVM). It is the runtime that converts a MSIL (Micro Soft
Intermediate Language) code into the machine language code, which is
then executed appropriately. In other words The CLR is the key
component of the .NET Framework. It is a common compiler for all
Microsoft programming language. It compiles all Microsoft languages

BY-NEERAJ KUMAR SINGH Page 2


to one Machine Language. The CLR Allows programmers to write code
in different Microsoft languages of their choice, and ensure that the
parts can work together .

The CLR provides a number of services that include:

 Loading and execution of codes


 Memory isolation for application
 Verification of type safety
 Compilation of IL into native executable code
 Providing metadata
 Automatic garbage collection
 Enforcement of Security
 Managing exceptions and errors
 Provide support for debugging and profiling

6. What is Common Type System (CTS) ?


CTS, much like Java, defines every data type as a Class. Every .NET
language must stick to this definition. Since CTS defines every data type
as a class. This means that only Object- Oriented (or Object-Based)
languages can achieve .NET compliance. There are the following a list of
CTS supported data types:

Data Type Description


System.Byte 1-byte unsigned integer between 0-255
System.Int16 2-bytes signed integer
System.Int32 4-byte signed integer
System.Int64 8-byte signed integer
System.Single 4-byte floating point
System.Double 8-bytes wide floating point
System.Object 4-bytes address reference to an object
System.Char 2-bytes single Unicode Character.
System.String string of up to 2 billion Unicode characters.
System.Decimal 12-bytes signed integer that can have 28 digits
on either side of decimal.
System.Boolean 4-Bytes number that contains true(1) or false (0

BY-NEERAJ KUMAR SINGH Page 3


7. What is Microsoft Intermediate Language (MSIL)?
A .NET programming language (C#, VB.NET, J# etc.) does not compile
into executable code; instead it compiles into an intermediate code
called Microsoft Intermediate Language (MSIL). As a programmer one
need not worry about the syntax of MSIL - since our source code in
automatically converted to MSIL. The MSIL code is then send to the CLR
(Common Language Runtime) that converts the code to machine
language which is then run on the host machine. MSIL is similar to Java
Byte code. A Java program is compiled into Java Byte code (the .class
file) by a Java compiler, the class file is then sent to JVM which converts
it into the host machine language.
8. What is .NET Framework Class Library?
A collection of ready-made reusable classes that work with the CLR.
Programmers using any of the .NET programming languages can use
these classes to include in their applications. The CLR Allows
programmers to write code in different Microsoft languages of their
choice, and ensure that the parts can work together
Examples of the classes provided by the library are:
 Database access and manipulation
 User Interface – Windows Forms, Web Forms, Web Services
 Security
 Encryption and decryption
9. What is kind of application in VB.net?
 Console Application – Usually Text only application. Runs from a
DOS or COMMAND PROMPT screen.
 Windows Application – Graphical Interface user application. Typical
Windows application that you normally use, such as MS WORD etc.
 Web Based Windows Application – Web application that uses a
Browser such as Internet Explorer.
10.What is Console based application?
 Those application that executes in DOS environment called console
based application.
 A Console Application is a program whose output is usually text
based (No Graphics).

BY-NEERAJ KUMAR SINGH Page 4


 Console Applications usually do not contain Forms or any graphics,
but they can. You can if you like from a console application call
Windows Forms etc.
 Console Applications are created when an application performs
processing that requires very or no user interaction.
 They are lighter and have less overhead than standard windows
applications since they contain no graphical libraries etc.
 Console applications are a good choice when creating programs
such as login scripts, device drivers, backend processes, test
programs, programs that control hardware devices etc.
11.What is Window based Application?
 Those application that executes in window Environment called
window application.
 Windows Applications are your standard graphical applications we
are used to using.
 Windows Apps use graphical entities such as Forms, Web Forms etc.
12.What is web based application?
 Those application that executes in web browser called web based
application.
 These are applications created for the World-Wide-Web or Internet.
 These applications run from a Browser, but the actual program code
for these applications (HTML) reside on a Web Server and are
distributed to any client or browser which makes the request.
13.What is Visual Basics Modes?
There are three visual basic mode.
 Design Time – When you design the User Interface (GUI) and writing
the code.
 Run Time – When you execute and test the program .
 Break Time – When you have Run time errors and you stop
execution.
14.What is application file in VB.net?
File Extension Explanation Example
.sln Solution File that holds information about all Login.sln
the projects in the application
.vb Object File Contain definition and code Frmlogin.vb

BY-NEERAJ KUMAR SINGH Page 5


for Forms, Modules, Class Modules etc.
.resx Resource File -This is a resource file for frmlogin.resx
the Forms in the project. It contains information

about all resources used by the form.

.vbproj Project File – This file describes the project Login.vbproj


and lists the files included in the project.
15.What is garbage collector?
This is responsible for automatic memory management in which
memory is allocated and deallocated during run time for programs.
This process is called garbage collection in which memory is deallocated
automatically.
16.Describe IDE components used in .NET framework
 The start page – The start page is the default homepage for browser
provided within visual studio dot net IDE.It allows to perform
several tasks such as specifying your preferences.
 Windows form designer- It allows you to design user interface for
an application.It allows you to add controls to a form,arrange them as
per requirement and code to perform some action.
 Solution explorer window - This window lists the solution name
,project name and all the forms and modules that are used in project.
 Properties window - Properties window displays the properties that
are associated with an object.on selecting form1 from the windows
form designer the properties window lists all the properties
associated with forms such as size and text.
 Toolbox- Toolbox displays number of tabs .each tab contains
several items.Toolbox contains tabs ,data, components, windows
forms ,clipboard ring and general.
 Output window- Output window displays message for status of
various features provided in visual studio dot net. It displays current
status and after compilation process is complete ,specifies number of
errors that occurred during compilation.
 Task list window- This displays a list of errors along with source
(file & line no) of the error .It helps you to identify & locate
problems that are detected automatically as edit or compile code.
 Server explorer window- It is handy tool for various administrative
tasks such as monitoring performance of other m/c on n/w &
locating & connecting to various servers on n/w.

BY-NEERAJ KUMAR SINGH Page 6


 Dynamic help window- This window provides with context
sensitive help .This window is constantly updated to display links to
help topics on current control ,component or keywords.
 Class view window- This window displays classes , methods ,&
properties associated with a particular file. They are displayed in a
hierarchical tree view depicting containership of these items.

 Code & text editor window-This window allows you to enter &
edit code & text.This window is called Code editor or text editor
windows based on purpose for which use it.Used this for to add code
for form.
17. What is assembly?
Assemblies are the building blocks of .NET Framework applications. It
contains the code that the runtime executes.
An assembly almost always consists of at least two files: the executable
and the manifest.
The manifest is a list of all the files that exist inside the assembly. The
executable content inside the assembly is referred to individually as a
module. An assembly is a collection of one or more .exe or dll. An
assembly is the fundamental unit for application development and
deployment in the .NET framework.
There are two types of assembly private and public assembly. A private
assembly is used by a single application and is stored in the application`s
directory. A shared assembly is normally stored in the global assembly.
Assembly consist of the following contents.

 Assembly manifest:- The metadata that describes the assembly and


its contents.
 Type metadata:- Define all types, their properties and methods.
 MSIL:- Microsoft Intermediate Language
 A set of resources:- All other resources like icons, images etc.

18. What is metadata?


Metadata also describes the methods, interfaces, and classes contained in
the module or assembly. The information the metadata provides allows
the JIT compiler to compile and run the module.
Metadata is nothing but a description of every namespace, class, method,
property etc. Metadata stored within the Assembly.
19. What is module?
Module is a logical collection of code within assembly. Assembly
contains more than one module. Module contains classes.
20. Difference between Module and Assembly

BY-NEERAJ KUMAR SINGH Page 7


A module is an .exe or .dll file. An assembly is a set of one or more
modules that together make up an application. If the application is fully
contained in an .exe file, that's a one-module assembly. If the .exe is
always deployed with two .dll files
and one thinks of all three files as comprising an inseparable unit, then
the three modules together form an assembly, but none of them does so
by itself. If the product is a class library that exists in a .dll file, then that
single .dll file is an assembly. To put it in Microsoft's terms, the assembly
is the unit of deployment in .NET
21. Explain .NET framework version.
Microsoft has launched first version of framework in the year 2000 as
Bita version and officially in the year 2002.
There are the following version.
Version year
.NET framework 1.0 2000(Bita)
.NET framework 1.0 2002(RTM)
.NET framework 1.1 2003
.NET framework 2.0 2005
.NET framework 3.0 2006
.NET framework 3.5 2007
.NET framework 4.0 2009
22. What is JIT compiler?
It is responsible for converting IL code of .NET into OS understandable
machine/native code.
Adopting a process is known as conversion gradually during the program
execution.
23. Explain advantage of .NET development tool.
 Drag and Drop design
 IntelliSense features
 Syntax highlighting and auto-syntax checking
 Excellent debugging tools
 Integration with version control software such as Visual Source Safe
(VSS)
 Easy project management
24. What is namespace?
Namespaces are the way to organize NET framework class library into a
logical grouping according to their functionality. We know that .NET
framework class library is a large collection of thousands of classes.
These classes are organized in a namespace. It is similar to package in
java. The System namespace is the root for types in the .NET framework.
We can uniquely identify any class in the .NET framework class library
by using the full namespace of the class. We can create own namespace
in .NET language.

BY-NEERAJ KUMAR SINGH Page 8


CONTROL STATEMENT

1. Decision making statement/conditional statement/sequential statement


2. Looping statement/Iterative statement
3. Jumping/ad-hoc statement

Decision making statement

a. Simple if statement/single alternative if statement


b. If-else statement/double alternative if statement
c. Else if ladder statement/if else if statement
d. Nested if statement/compound if statement
e. Select case statement

Simple if statement

Syntax:-

If condition then
Block of statements
End if

Example

Dim n as integer=10
If n mod 2=0 then
Console.writLine(“Even “)
End if
If n mod 2=1 then
Console.writLine(“odd “)
End if

If - else statement

Syntax:-

If condition then
Block of statements
Else
Block of statements
End if

Example

Dim n as integer=10
If n mod 2=0 then
Console.writLine(“Even “)
else
Console.writLine(“odd “)
End if

If else if statement

Syntax:-

If condition1 then
Block of statements
Elseif condition2 then
Block of statements
Elseif condition3 then
Block of statements
..............................
...............................
..................................
Elseif condition n then
Block of statements
Else
Block of statements
End if

Example

Dim a%, b%, c%, gt%


WriteLine("Enter three numbers")
a = CInt(ReadLine())
b = CInt(ReadLine())
c = CInt(ReadLine())
If a > b And a > c Then
gt = a
ElseIf b > c Then
gt = b
Else
gt = c

End If
WriteLine("Greatest number=" & gt)

Nested if statement

Syntax:-

If condition then
If condition then
Block of statements
Else
Block of statements
End if
Else
If condition then
Block of statements
Else
Block of statements
End if
End if

Example

Dim a%
WriteLine("Enter any number")
a = CInt(readLine())
If a Mod 2 = 0 Then
If a > 0 Then
WriteLine("Even +ve")
Else
WriteLine("Even -ve")
End If
Else
If a > 0 Then
WriteLine("odd +ve")
Else
WriteLine("odd -ve")
End If
End If

Select case statement

Syntax-1:- For matching value

Select case variable


Case value1
Block of statements
Case value2
Block of statements
Case value3
Block of statements
.............................
.................................
..................................
Case value n
Block of statements
Case else
Block of statements
End select

Example:-
Dim ch As Char
WriteLine("Enter any alphabet")
ch = ChrW(Read())
Select Case ch
Case "a", "A", "e", "E", "i", "I", "o", "O",
"u", "U"
'WriteLine("vowel")
MessageBox.Show("vowel")
Case Else
' WriteLine("Consonent")
MessageBox.Show("consonent")
End Select

Syntax-2:- For specifying range

TO:- This keyword is used to specify range.

Select case variable


Case value1 TO value2
Block of statements
Case value1 TO value2
Block of statements

Case value1 TO value2


Block of statements

Case value1 TO value2


Block of statements
...................................
.......................................
Case value1 TO value n
Block of statements

Case else
Block of statements
End select

Example:-
Dim roll As Integer, nm As String, cs As String, c, cpp,
java, vb, tm As Integer, pm As Single, remark As String
WriteLine("Enter rollno, name,course and marks of
four subject")
roll = CInt(ReadLine())
nm = ReadLine()
cs = ReadLine()
c = CInt(ReadLine())
cpp = CInt(ReadLine())
java = CInt(ReadLine())
vb = CInt(ReadLine())
tm = c + cpp + java + vb
pm = tm / 4
Select Case pm
Case 90 To 100
remark = "Excellent"
Case 75 To 89
remark = "very good"
Case 60 To 74
remark = "good"
Case 45 To 59
remark = "poor"
Case Else
remark = "Fail"
End Select

Syntax-2:- For specifying condition

IS:- This keyword is used to specify condition

Select case variable


Case IS operator value1
Block of statements
Case IS operator value2
Block of statements

Case IS operator value3


Block of statements

Case IS operator value4


Block of statements
...............................
..................................
Case IS operator value n
Block of statements

Case else
Block of statements
End select

Example:-
Dim roll As Integer, nm As String, cs As String, c, cpp,
java, vb, tm As Integer, pm As Single, remark As String
WriteLine("Enter rollno, name,course and marks of
four subject")
roll = CInt(ReadLine())
nm = ReadLine()
cs = ReadLine()
c = CInt(ReadLine())
cpp = CInt(ReadLine())
java = CInt(ReadLine())
vb = CInt(ReadLine())
tm = c + cpp + java + vb
pm = tm / 4
Select Case pm
Case Is >= 90
remark = "Excellent"
Case Is >= 75
remark = "very good"
Case Is >= 60
remark = "good"
Case Is >= 45
remark = "poor"
Case Else
remark = "Fail"
End Select

Looping statement

1. For- Next loop

Syntax:
For index=start_value TO end_value [STEP value]
Block of statements
Next
Note:- Step keyword is used to increase or decrease value of variable. For
loop increases value of variable by one automatically.
Example:-

For i = 1 To 50 Step 2
Console.WriteLine(i)
Next

2. While loop:-
Syntax:-
While condition
Block of statements
End while

Example

i = 1
While i <= 100
Console.WriteLine(i)
i = i + 1
End While

3. Do loop:- There are four formats of do loop


A. do------loop while

Syntax:-
do
Block of statements
loop while condition

Example

i = 1
Do
Console.WriteLine(i)
i = i + 1
Loop While i <= 100

B. do------loop until
Syntax:-
do
Block of statements
loop until condition

Example
i = 1
Do
Console.WriteLine(i)
i = i + 1
Loop Until i > 100

C. do while----------loop
Syntax:-
Do while condition
Block of statements
Loop

Example
i = 1
Do While i <= 100
Console.WriteLine(i)
i = i + 1
Loop

D. do until ---------------loop
Syntax:-
Do until condition
Block of statements
Loop

Example
i = 1
Do until i > 100
Console.WriteLine(i)
i = i + 1
Loop

4. For each loop:- to print collection/array value


Syntax:-
For each variable in array_name
Block of statements
Next

Example
Dim a() As Integer = {4, 5, 6, 7, 8, 9}
For Each i In a
Console.WriteLine(i)
Next

Jumping statement

a. Exit for
b. Exit while
c. Exit do
d. Exit
e. Exit function
f. Exit sub

Array:-
It is a special variable which is used to hold multiple values.

Types of array
1. One dimensional array
2. Two dimensional array
3. Three dimensional array
4. Jagged array

One dimensional array:- It holds multiple values in single row.

i.e

10 20 30 40 50 60 70 80 90 100
0 1 2 3 4 5 6 7 8 9

Declaration:-

Syntax:-

Dim variable1(size) as data type, variable2(size) as data type,---------------

Example

Dim a(5) as integer, b(10) as single


Key points

Dim a(5) As Integer


Dim b() As Integer = {8, 9, 8, 5, 7} 'Intialization
Dim c() As Integer = New Integer(10) {} 'declaration using
new keyword
Dim d() As Integer = New Integer(3) {5, 7, 9, 90}
WriteLine("length=" & a.Length)

Program-1

'WAP in vb.net to input 10 numbers any any searching element


after that check that number is available or not.

Imports System.Console
Module Module2
Sub main()
Dim a(10) As Integer, svalue As Integer, i%, flag%
flag = 0
'WriteLine("length of array=" & a.Length)
'Dim a() As Integer = New Integer(10) {}
'Dim a() As Integer = {10, 20, 30, 40,
50}'Initialization
' Dim a() As Integer = New Integer() {10, 20, 30,
40, 50}
' Dim a() As Integer = New Integer(4) {10, 20, 30,
40, 50}
WriteLine("Enter 10 numbers")
For i = 1 To a.Length - 1
a(i) = CInt(ReadLine())
Next
WriteLine("Enter any searching element")
svalue = CInt(ReadLine())
For i = 1 To a.Length - 1
If a(i) = svalue Then
flag = 1
Exit For
End If
Next
If flag = 1 Then
WriteLine("Searching found")
Else
WriteLine("Searching not found")
End If

ReadKey()

End Sub

Program-2

'wap in vb.net to input 10 numbers after that sort in


ascending order
Imports System.Console 'including namespace
Module Module1

Sub Main()
Dim a() As Integer = New Integer(10) {}
Dim i%, j%, temp%
WriteLine("enter 10 numbers")
For i = 1 To a.Length - 1
a(i) = CInt(ReadLine())
Next
For i = 1 To a.Length - 1
For j = i + 1 To a.Length - 1
If a(i) > a(j) Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next
Next
WriteLine("All elements in ascending order")
For i = 1 To a.Length - 1
WriteLine(a(i))
Next
ReadKey()
End Sub
End Module

Two dimensional array:- It represents value in matrix format such as row and
column.

Example:-

10 20 30 ROW-1
40 50 60 ROW-2
70 80 90 ROW-3
100 110 120 ROW-4
COL-1 COL-2 COL-3

Key points

Dim e(3, 4) As Integer


Dim f(,) As Integer = {{1, 2, 3}, {6, 8, 9}}

'Intialization
Dim g(,) As Integer = New Integer(,) {{1, 2, 3}, {6,
8, 9}} 'Intialization
Dim h(,) As Integer = New Integer(1, 2) {{1, 2, 3},
{6, 8, 9}}
Dim i(,) As Integer = New Integer(3, 2) {}
'Declaration

Program:-

'wap in vb.net to input any matrix after that print it


Imports System.Console 'including namespace
Module Module1

Sub Main()
' Dim a(3, 2) As Integer, i%, j%
Dim a(,) As Integer = New Integer(3, 2) {}
'Dim a(,) As Integer = {{1, 2}, {4, 5}, {6, 7}}
'Dim a(,) As Integer = New Integer(,) {{1, 2}, {4,
5}, {6, 7}}
' Dim a(,) As Integer = New Integer(2, 1) {{1, 2},
{4, 5}, {6, 7}}
WriteLine("Enter value of matrix")
For i = 1 To 3
For j = 1 To 2
a(i, j) = CInt(ReadLine())
Next
Next

WriteLine("Matrix is")
For i = 1 To 3
For j = 1 To 2
Write(a(i, j) & vbTab)
Next
WriteLine()
Next
ReadKey()
End Sub

End Module

Three dimensional array:- It holds multiple matrices of same order.

Example:-

MATRIX-1 MATRIX-2 MATRIX-3


10 20 ROW-1 10 20 ROW-1 10 20 ROW-1
40 50 ROW-2 40 50 ROW-2 40 50 ROW-2
70 80 ROW-3 70 80 ROW-3 70 80 ROW-3
COL-1 COL-2 COL-1 COL-2 COL-1 COL-2

Key points

Dim j(5, 3, 2) As Integer 'Declaration


Dim k(,,) As Integer = {{{1, 2}, {9, 8}, {8, 6}}, {{1, 2},
{9, 8}, {8, 6}}, {{1, 2}, {9, 8}, {8, 6}}}
Dim m(,,) As Integer = New Integer(,,) {{{1, 2}, {9, 8}, {8,
6}}, {{1, 2}, {9, 8}, {8, 6}}, {{1, 2}, {9, 8}, {8, 6}}}
Dim n(,,) As Integer = New Integer(2, 2, 1) {{{1, 2}, {9,
8}, {8, 6}}, {{1, 2}, {9, 8}, {8, 6}}, {{1, 2}, {9, 8}, {8,
6}}}
Dim p(,,) As Integer = New Integer(2, 2, 1) {} 'Declaration

Program:-

'wap in vb.net to input any four matrix after that print all
it
Imports System.Console 'including namespace
Module Module1

Sub Main()
Dim a(4, 3, 2) As Integer, i%, j%, k%

WriteLine("Enter four matrix")


For i = 1 To 4
WriteLine("Enter value of matrix " & i)
For j = 1 To 3

For k = 1 To 2
a(i, j, k) = CInt(ReadLine())
Next
Next
Next

WriteLine(" All Matrix are")


For i = 1 To 4
WriteLine(" matrix " & i)
For j = 1 To 3

For k = 1 To 2
Write(a(i, j, k) & vbTab)
Next
WriteLine()
Next
Next
ReadKey()
End Sub

End Module

Jagged/Ragges array:- It is a type of two dimensional array. In this array each row
can have multiple columns a/c to requirement.

Example:-

4
5 8 9
6
7 8 10 11 23
1 2

Key points

Dim q As Integer()() = New Integer(2)() {}


q(0) = New Integer(2) {}
q(1) = New Integer(4) {}
q(2) = New Integer(1) {}
Program:-

Dim q As Integer()() = New Integer(2)() {}


q(0) = New Integer(2) {}
q(1) = New Integer(4) {}
q(2) = New Integer(1) {}
For s = 0 To q.Length - 1
For t = 0 To q(s).Length - 1
q(s)(t) = CInt(ReadLine())
Next

Next
For s = 0 To q.Length - 1
For t = 0 To q(s).Length - 1
Write(q(s)(t) & vbTab)
Next
WriteLine()

Next

Dynamic array:-

In this array we can change/modify the size of array during runtime. Size of array
is increased and decreased with the help of redim keyword a/c to requirement.

Declaration:-

Syntax:-

ReDim [Preserve] variable name(size)

Preserve:-This keyword is used to preserve an existing value in array. It means


previous value can not be lost after modifying size.

Example
Dim rollno()as integer

Redim rollno(5)

Redim preserve rollno(3)

Program:-

Imports System.Console 'including namespace


Module Module1

Sub Main()

Dim marks() As Integer


ReDim marks(2)
marks(0) = 85
marks(1) = 75
marks(2) = 90
ReDim Preserve marks(10)
marks(3) = 80
marks(4) = 76
marks(5) = 92
marks(6) = 99
marks(7) = 79
marks(8) = 75

For i = 0 To 10
Console.WriteLine(i & vbTab & marks(i))
Next
ReadKey()

End Sub

End Module
Procedure(Function & subroutine)
Procedure:- It is a block of well- defined statements which is
used to design for performing any special task a/c to
requirement.

Types of procedure
1. Subroutine
2. Function

Subroutine:- It is a type of procedure that contains block of


statements to perform any specific task a/c to requirement.

It does not return any value. But it can be parameterised.

 How to create subroutine?


It is created with the help of “sub”keyword and ended
with “end sub” clause

Syntax:-
Sub <subroutine name>([parameter list])
Block of statements
End sub

Example:-
Sub findadd()
Dim a as integer,b as integer,sum as integer
a=20
b=30
sum=a+b
writeline(“Addition=”& sum)
End sub
 How to call subroutine?
Call:- This keyword is used to call subroutine
Syntax:- call <subroutine name>()
Example:-
Sub main()
Call findadd()
End sub

Function:-

It is a type of procedure that contains block of statements to


perform any specific task a/c to requirement. It is similar to
subroutine but it returns value. It can be parameterised.

 How to create function?


It is created with the help of “function”keyword and ended
with “end function” clause

Syntax:-
function <function name>([parameter list])as<return type>
Block of statements
End function

Example:-
function findadd() as integer
Dim a as integer,b as integer,sum as integer
a=20
b=30
sum=a+b
return sum
End function
 How to call function?

Syntax:- <variable name>= <function name>()


Example:-
Sub main()
Dim rs as integer
rs=findadd()
writeline(“Addition=” & rs)
End sub

2nd method
Sub main()
writeline(“Addition=” & findadd())
End sub

Program:
' To input employee id, name,post and salary of
employee after that print it.
Imports System.Console
Module employee
Dim empid$, ename$, post$, salary% 'global
variable
Sub getInput()
WriteLine("Enter employee id, name, post and
salary")
empid = ReadLine()
ename = ReadLine()
post = ReadLine()
salary = CInt(ReadLine())
End Sub
Sub showRecord()
WriteLine("Employee id=" & empid & vbNewLine
& "Name=" & ename & vbNewLine & "Post=" & post &
vbNewLine & "Salary=" & salary)
End Sub
Sub main()
Call getInput() ' calling subroutine
Call showRecord()
ReadKey()
End Sub
End Module

Program

To input employee id, name,post and salary of


employee as parameter after that print it.
Imports System.Console
Module employee
Dim empid$, ename$, post$, salary% 'global
variable
Sub getInput(ByVal id As String, ByVal name As
String, ByVal job As String, ByVal sal As Integer)
empid = id
ename = name
post = job
salary = sal

End Sub
Sub showRecord()
WriteLine("Employee id=" & empid & vbNewLine
& "Name=" & ename & vbNewLine & "Post=" & post &
vbNewLine & "Salary=" & salary)
End Sub
Sub main()
Call getInput("E-101", "Shubham", "Manager",
50000) ' calling subroutine
Call showRecord()
ReadKey()
End Sub
End Module

 How to pass parameters in procedure?


There are two methods for passing parameter in
procedure.
1. Call by value
2. Call by reference

Call by value:- In call by value we pass value so in this case value


of actual parameter can not be changed.

It is passed with the help of “ByVal” keyword.

Example:- Swapping program

Imports System.Console
Module swapping
Sub swapping(ByVal a As Integer, ByVal b As
Integer)
Dim tmp As Integer
tmp = a
a = b
b = tmp
WriteLine("After swapping value of a=" & a &
vbNewLine & "value of b=" & b)
End Sub
Sub main()
Dim a As Integer, b As Integer 'actual
parameter
WriteLine("Enter two numbers")
a = CInt(ReadLine())
b = CInt(ReadLine())
WriteLine("Before calling swapping function
value of actual parameter" & vbNewLine & "a=" & a &
vbNewLine & " b=" & b)
Call swapping(a, b) ' calling subroutine
WriteLine("after calling swapping function
value of actual parameter" & vbNewLine & "a=" & a &
vbNewLine & " b=" & b)
ReadKey()
End Sub
End Module

Call by reference:- In call by reference we pass reference so in


this case value of actual parameter can be changed.

It is passed with the help of “ByRef” keyword.

Example:- Swapping program


Imports System.Console
Module swapping
Sub swapping(ByRef a As Integer, ByRef b As
Integer)
Dim tmp As Integer
tmp = a
a = b
b = tmp
WriteLine("After swapping value of a=" & a &
vbNewLine & "value of b=" & b)
End Sub
Sub main()
Dim a As Integer, b As Integer 'actual
parameter
WriteLine("Enter two numbers")
a = CInt(ReadLine())
b = CInt(ReadLine())
WriteLine("Before calling swapping function
value of actual parameter" & vbNewLine & "a=" & a &
vbNewLine & " b=" & b)
Call swapping(a, b) ' calling subroutine
WriteLine("after calling swapping function
value of actual parameter" & vbNewLine & "a=" & a &
vbNewLine & " b=" & b)
ReadKey()
End Sub
End Module

Program:-Passing parameter as array variable


Imports System.Console
Module greatest_array
Function findgreatest(ByVal a() As Integer) As
Integer
Dim gt%, i%
gt = 0
For i = 0 To a.Length - 1
If a(i) > gt Then
gt = a(i)
End If
Next
Return gt
End Function
Sub main()
' Dim a() As Integer = {10, 20, 30, 40, 50,
5, 6, 7, 8}
Dim s%
WriteLine("Enter the size of list")
s = CInt(ReadLine())
Dim a(s) As Integer, i%
WriteLine("Enter " & s & "Numbers")
For i = 0 To a.Length - 1
a(i) = CInt(ReadLine())
Next
' WriteLine("Greatest element=" &
findgreatest(a))
Dim rs%
rs = findgreatest(a)
WriteLine("Greatest element=" & rs)
ReadKey()
End Sub
End Module
Constructor
 It is a special type of subroutine which must be defined
with the help of new keyword instead of class in VB.NET.
 It executes automatically during creation of object.
 It does not return any value so it is treated as
subroutine instead of function
 It can be parameterized.
 It can be overloaded.
 It is not member of class
 It can not be inherited.

Types of constructor
There are the following types of constructor.
 Default constructor
 Parameterized constructor
 Copy constructor
 Shared constructor

Default constructor:-

This type of constructor does not contain parameter list.


Syntax:-
Sub New()
Block of statements
End sub

Example
Sub New()
Writeline(“Default constructor”)
End sub

Parameterized constructor:-
This type of constructor contains parameter list.
Syntax:-
Sub New(parameter list)
Block of statements
End sub

Example
Sub New(a as integer, b as integer)
Writeline(“Parameterized constructor”)
End sub

Parameterized constructor:-
This type of constructor contains parameter list.
Syntax:-
Sub New(parameter list)
Block of statements
End sub

Example
Sub New(a as integer, b as integer)
Writeline(“Parameterized constructor”)
End sub
copy constructor:-
This type of constructor is used to copy value of one object
into another object. It can have one parameter as object of
class.
Syntax:-
Sub New(object of class)
Block of statements
End sub

Example
Sub New(emp as Employee)
Writeline(“Copy constructor”)
End sub

Program

'implementation of constructor overloading


Imports System.Console
Module EMPLOYEE_RECORD
Class Employee
Dim empid As String, ename As String, post As
String, salary As Integer
Public Sub New() 'Default constructor
WriteLine("Enter employee id ,name, post and
salary")
empid = ReadLine()
ename = ReadLine()
post = ReadLine()
salary = CInt(ReadLine())
End Sub
Public Sub New(empid As String, ByVal name As
String, post As String, salary As Integer) 'Parameterized
constructor
Me.empid = empid
ename = name
Me.post = post
Me.salary = salary

End Sub
Public Sub New(emp As Employee) 'Copy constructor
empid = emp.empid
ename = emp.ename
post = emp.post
salary = emp.salary
End Sub
Public Sub showRecord()
WriteLine("Employee id=" & empid & vbNewLine &
"Name=" & ename & vbNewLine & "Post=" & post & vbNewLine &
"salary=" & salary)
End Sub
End Class
Sub main()
Dim e1 As New Employee() 'executes default
constructor
Dim e2 As New Employee("E-101", "Ritesh", "Manager",
50000) 'executes parameterizied constructor
Dim e3 As New Employee(e1) 'executes copy
constructor
Dim e4 As New Employee(e2)

e1.showRecord()
e2.showRecord()
e3.showRecord() 'print record of obect e1
e4.showRecord() 'print record of object e2
e4 = e1
e4.showRecord()

ReadKey()
End Sub
End Module

Shared keyword

This keyword is used to create static type member of class. It is


used with member variable , member function and constructor.
Shared used with member variable /class variable/static
variable/shared variable
 Those variables which are declared with the help of
shared keyword called shared variable.
 It allocates memory only once time. So its value is
preserved.
 It saves memory space.
 Its value is shared by all object.
 It is accessed with the help class name directly.

Shared used with member function /static function/shared


function

 Those functions which are declared with the help of


shared keyword called shared function.
 It is accessed with the help class name directly.
 Static function can access only static variable but non-
static function can access both static and non-static
variable.

Program:-

'to count number of object of class


Imports System.Console
Module mystatic
Class myshared
Public Shared count As Integer = 0 'static
variable/class variable
Public Sub New()
count = count + 1
End Sub
Public Shared Sub show() 'static/shared
subroutine
WriteLine("Total number of object=" &
count)
End Sub
End Class
Sub main()
Dim obj1 As New myshared() '1
'obj1.show() '1
Dim obj2 As New myshared() '2
'obj2.show() '2
Dim obj3 As New myshared() '3
'obj3.show() '3
'obj1.show() '3
' obj2.show() '3
' obj3.show() '3
myshared.show()
WriteLine("total objects=" & myshared.count)
ReadKey()
End Sub
End Module

Shared used with constructor

 Those constructors which are declared with the help


of shared keyword called shared constructor.
 It can not be parameterized. So it can not be
overloaded.
 It executes first rather than instance constructor
 It is mainly used to initialize only static
variable/shared variable.

'Implementation of shared constructor


'It is mainly used to intialized static/shared
variable
'It can not be parameterized
'It can not be overloaded
'It executes before instance constructor
Imports System.Console

Module shared_constructor
Class Shared_constructorEx
Dim rollno, name, course As String
Shared college_name As String
Public Sub New() 'instance constructor
WriteLine("Enter rollno,name and course")
rollno = ReadLine()
name = ReadLine()
course = ReadLine()
End Sub
Shared Sub New() 'shared constructor
college_name = "CIMAGE"
WriteLine("Welcome to shared
constructor")
End Sub
Public Sub showRecord()
WriteLine("Rollno=" & rollno & vbNewLine
& "Name=" & name & vbNewLine & "course=" & course &
vbNewLine & "College name=" & college_name)

End Sub
End Class
Sub main()
Dim obj As New Shared_constructorEx()
obj.showRecord()
ReadKey()
End Sub
End Module
Creating class in VB.net
Class:-class keyword is used to create class.We know that
class is a container in which member variable and
member function are composed in single unit. It provides
user-defined data type.
Members of class
1. Member variable/instance variable
2. Member function

Member variable:- Those variables which are declared


within class called member variable
Member function:- Those functions/subroutines which
are defined within function called member function.
Syntax:-
Class <class name>
Member of class
End class
Example

Class Student
Dim rollno As Integer ' default access
specifier is private
Public name As String
Private course As String
Protected fee As Single
Public Sub getInput()
WriteLine("Enter rollno,name,course and
fee")
rollno = CInt(ReadLine())
name = ReadLine()
course = ReadLine()
fee = CSng(ReadLine())
End Sub
Sub showResult()
WriteLine("Rollno=" & rollno & vbNewLine
& "Name=" & name & vbNewLine & "Course=" & course &
vbNewLine & "Fee=" & fee)

End Sub

End Class
Creating an object
Object is used to access the member of class. We can
create multiple objects of class so class is said to be
collection of objects.
Syntax:-
1st method
Dim <object name> as new <class name>()
Example
Dim obj as new student()
2nd method
Syntax:-
Dim <object name> as <class name>=new <class name>()
Example
Dim obj as student=new student()
Program
Imports System.Console

Module student
Class Student
Dim rollno As Integer ' default access
specifier is private
Public name As String
Private course As String
Protected fee As Single
Public Sub getInput()
WriteLine("Enter rollno,name,course and
fee")
rollno = CInt(ReadLine())
name = ReadLine()
course = ReadLine()
fee = CSng(ReadLine())
End Sub
Sub showResult()
WriteLine("Rollno=" & rollno & vbNewLine
& "Name=" & name & vbNewLine & "Course=" & course &
vbNewLine & "Fee=" & fee)

End Sub

End Class
Sub main()
Dim obj As Student = New Student() 'creating
object
'creating more than one object
' Dim obj1 As Student = New Student()'both
declaration and allocation
'Dim obj2 As Student = New Student()
'Dim obj3 As Student = New Student()
Dim obj1, obj2, obj3 As Student 'declaration
of multiple object
obj1 = New Student() 'allocation of object
obj2 = New Student()
obj3 = New Student()
obj.getInput() 'calling member function
obj.showResult()
WriteLine("Course=" & obj.name)
ReadKey()
End Sub

End Module

Me:- This keyword represents current object of class in


vb.net. It works as like “this” keyword in c++ & Java.
If the name of formal parameter and instance variable
are same then we use “me” keyword with instance
variable.
Example
Imports System.Console
Module Login
Class Login
Dim uname As String, pname As String, email
As String 'instance variable
Sub getLogin_details(ByVal unm As String,
pname As String, email As String)
uname = unm
Me.pname = pname
Me.email = email
End Sub
Sub validateLogin()
If uname = "cimage" And pname = "aku"
Then
WriteLine("Login success" & vbNewLine
& "Your email id is " & email)
ElseIf uname <> "cimage" And pname <>
"aku" Then
WriteLine("Login failed due to both
are invalid")
ElseIf uname <> "cimage" Then
WriteLine("Login failed due to
invalid user name")
Else
WriteLine("Login failed due to
invalid password")
End If
End Sub
End Class
Sub main()
Dim obj As New Login() 'dim obj as Login=new
Login()
obj.getLogin_details("cimage123", "aku123",
"[email protected]")
obj.validateLogin()
ReadKey()
End Sub
End Module
Function overloading:- When more than one function
and subroutine are defined with same name and
different signature called function overloading.
It is an example of compile time polymorphism.
It is implemented with the help of “overloads” keyword.
'Implementation of function overloading(function &
subroutine)
Imports System.Console
Module fun_overloading
Class shape
Overloads Sub findArea(ByVal l As Integer,
ByVal b As Integer)
WriteLine("Area of rectangle=" & l * b)

End Sub
Overloads Sub findArea(ByVal side As Integer)
WriteLine("Area of square=" & side *
side)
End Sub
Overloads Function findPeri(ByVal l As
Integer, b As Integer) As Integer

Return 2 * (l + b)

End Function
Overloads Function findPeri(ByVal side As
Integer) As Integer
Return 4 * side
End Function
End Class
Sub main()
Dim obj1, obj2 As New shape()
obj1.findArea(10, 20)
obj1.findArea(10)
WriteLine("Perimeter of rectangle=" &
obj1.findPeri(10, 30))
WriteLine("Perimeter of square=" &
obj1.findPeri(10))
'obj2 = obj1
WriteLine("Perimeter of square=" &
obj2.findPeri(10))

ReadKey()

End Sub
End Module
Inheritance

Inheritance:-
 It is the most important tool of object oriented
programming.
 It provides a technique in which one class is
inherited from other class. In other words the
process of creating sub class from super class is
called inheritance.
 It provides reusability. It means once written
source code can be reused multiple times a/c to
requirement.

Types of inheritance

1.Single level
2.Multi level
3.Multiple inheritance
4.Hierarchical
5.Hybrid

Single level inheritance:- When one sub class is


inherited from only one super class is called single
level inheritance. This type of inheritance contains
only one super and one sub class.

 How to create sub class?

Inherits:- This keyword is used to inherit the


features of super class into sub class.
Syntax:-

Class <super class>


Inherits <sub class name>

Member of class

End class

Example:-

Class xyz

Member of class

End class

Class abc
Inherits xyz

Member of class

End class

Function overriding:-

When the function of super class defined with same


name and same signature in sub class is called
function overriding. In this case an object of sub
class gives priority of own member and overridden
members are accessed within sub class.
It is an example of runtime polymorphism.

Creating overridden function and subroutine


Overridable & overrides :- These keywords are used
with overriding function.
Overridable keyword is defined with overriding
function in super class and overrides keyword is used
with overriding function in sub class.

How to call overridden member in sub class?

Mybase:- This keyword is used to access an overridden


member in sub class.

Program-1

'Implementation of single level inheritance with


function overriding

Imports System.Console
Module single_level
Class Rectangle 'super class
Protected l, b, area, peri As Integer
Overridable Sub getInput() 'subroutine
overriding/function overriding
WriteLine("Enter length and breadth") : l
= CInt(ReadLine()) : b = CInt(ReadLine())

End Sub
Overridable Function findArea() As Integer
area = l * b
Return area
End Function
Sub findPeri()
peri = 2 * (l + b)

End Sub
End Class
' Class square
'Inherits Rectangle
Class square : Inherits Rectangle 'creating sub
class
Dim s As Integer
Shadows area, peri As Integer
Overrides Sub getInput()
MyBase.getInput()

WriteLine("Enter side of square")


s = CInt(ReadLine())
End Sub
Public Overrides Function findArea() As
Integer
MyBase.findArea()
area = s * s
Return area
End Function
Public Sub calculatePeri()
peri = 4 * s
End Sub
Public Sub getResult()
WriteLine("Area of square=" & area &
vbNewLine & "Perimeter of square=" & peri) 'o/p
WriteLine("Area of rectangle=" &
MyBase.area & vbNewLine & "Perimeter of rectangle=" &
MyBase.peri) 'o/p
End Sub

End Class
Sub main()
Dim obj As New square
obj.getInput()
obj.findArea()
obj.findPeri()
obj.calculatePeri()
obj.getResult()
ReadKey()

End Sub
End Module

Constructor in inheritance:-

We know that constructor of super class can not be inherited into sub
class. But when we create an object of sub class then first default
constructor of super class will be executed after that default
constructor of sub class executes. In this case of ”mybase.new()” works
by default. It is optional.

How to call constructor of super class into constructor of sub class ?

Syntax:-

Mybase.new([parameter list])

Program-2

'implementation of constructor in inheritance


Imports System.Console
Module constructor_single_level
Class Bank
Protected bank_id As String, bank_name As
String, branch_name As String
Sub New()
WriteLine("Enter bank id, bank name and
branch name")
bank_id = ReadLine()
bank_name = ReadLine()
branch_name = ReadLine()

End Sub
Sub New(bank_id As String, bank_name As
String, branch_name As String)
Me.bank_id = bank_id
Me.bank_name = bank_name
Me.branch_name = branch_name
End Sub

End Class
Class customer : Inherits Bank
Dim cid, cname As String, balance As Integer
Sub New()
' MyBase.New() 'optional
WriteLine("Enter customer id, customer
name and balance")
cid = ReadLine()
cname = ReadLine()
balance = CInt(ReadLine())
End Sub
Sub New(bank_id As String, bank_name As
String, branch_name As String, cid As String, cname
As String, balance As Integer)
MyBase.New(bank_id, bank_name,
branch_name) 'calling parameterized constructor of
base class in constructor of sub class
Me.cid = cid
Me.cname = cname
Me.balance = balance
End Sub
Sub showResult()
WriteLine("Customer id=" & cid &
vbNewLine & "customer name=" & cname & vbNewLine &
"balance=" & balance & vbNewLine & "Bank id=" &
bank_id & vbNewLine & "Bank name=" & bank_name &
vbNewLine & "Branch name=" & branch_name)

End Sub
End Class
Sub main()
Dim obj1 As New customer() 'calling default
constructor of both class
Dim obj2 As New customer("P-102", "PNB",
"Gandhi Maidan", "C-1001", "Avinash", 400000)

obj1.showResult()
obj2.showResult()
ReadKey()
End Sub
End Module
 Multi level inheritance:-
An extending single level inheritance is called multi level
inheritance.

Program-3

'Implementation of multi level inheritance to


generate salary slip of employee
'a/c to given condition
'1. basic>=20000 then
hra=40%,da=90%,ta=30%,ma=10%,pf=10%
'2. basic>=10000 then
hra=30%,da=80%,ta=20%,ma=8%,pf=10%
'3. Other wise hra=20%,da=70%,ta=15%,ma=5%,pf=10%
Imports System.Console
Module multilevel
Class department
Protected did As Integer, dname As String
Public Sub New()
WriteLine("Enter department id &
department name")
did = CInt(ReadLine())
dname = ReadLine()
End Sub
Public Overridable Sub showResult()
WriteLine("Department id=" & did &
vbNewLine & "Department name=" & dname)
End Sub
End Class
Class Employee : Inherits department
Protected eid As Integer, ename As String,
post As String
Public Sub New()
WriteLine("Enter employee id & name &
post")
eid = CInt(ReadLine())
ename = ReadLine()
post = ReadLine()

End Sub
Public Overrides Sub showResult()
MyBase.showResult()
WriteLine("Employee id=" & eid &
vbNewLine & "name=" & ename & vbNewLine & "post=" &
post)
End Sub
End Class
Class Employee_Salary_slip : Inherits Employee
Dim bs, gs, ns, hra, da, ta, ma, pf As Single
Public Sub New()
WriteLine("Enter basic salary of
employee")
bs = CDbl(ReadLine())
End Sub
Public Sub findAllowance()
If bs >= 20000 Then
hra = bs * 40 / 100
da = bs * 90 / 100
ta = bs * 30 / 100
ma = bs * 10 / 100
pf = bs * 10 / 100
ElseIf bs >= 10000 Then
hra = bs * 30 / 100
da = bs * 80 / 100
ta = bs * 20 / 100
ma = bs * 8 / 100
pf = bs * 10 / 100
Else
hra = bs * 20 / 100
da = bs * 70 / 100
ta = bs * 15 / 100
ma = bs * 5 / 100
pf = bs * 10 / 100
End If
gs = bs + hra + da + ta + ma + pf
ns = gs - pf

End Sub
Public Sub printMarksheet()
showResult()
WriteLine("Salary details" & vbNewLine &
"-------------------------------" & vbNewLine &
"Basic salary=" & bs & vbNewLine & "HRA=" & hra &
vbNewLine & "DA=" & da & vbNewLine & "TA=" & ta &
vbNewLine & "MA=" & ma & vbNewLine & "PF=" & pf &
vbNewLine & "Gross salary=" & gs & vbNewLine & "Net
Salary=" & ns)

End Sub
End Class
Sub main()
Dim obj As New Employee_Salary_slip()

obj.findAllowance()
obj.printMarksheet()
ReadKey()
End Sub
End Module

Abstract class:-

 This class is used to achieve data abstraction.


 It is declared with the help of “mustinherit” keyword.
 It can have abstract function & subroutine. Its body must be
defined within sub class. An abstract class can have only
declaration of abstract function.
 An abstract function must be declared with the help of
“mustoverrides “ keyword.
 An abstract class must be inherited.
 Its object can not be created.
 It can have also constructor and member function.

Program-4

'implementation of abstract class


Imports System.Console

Module Abstract_class
MustInherit Class Shape 'abstract class
Protected area As Single
Protected peri As Single
Dim sname As String
Public Sub New()
WriteLine("Enter shape name")
sname = ReadLine()
End Sub
Public Sub showShapeName()
WriteLine("shape name=" & sname)
End Sub
Public MustOverride Sub findArea() 'abstract
subroutine
Public MustOverride Sub findPeri()

End Class
Class Rectangle : Inherits Shape
Dim l, b As Integer
Public Sub New()
WriteLine("Enter length and breadth")
l = CInt(ReadLine())
b = CInt(ReadLine())

End Sub
Public Overrides Sub findArea() 'overriding
area = l * b
WriteLine("Area of rectangle=" & area)
End Sub

Public Overrides Sub findPeri()


peri = 2 * (l + b)
WriteLine("Perimeter of rectangle=" &
peri)
End Sub
End Class
Class Circle : Inherits Shape
Dim r As Integer
Public Sub New()
WriteLine("Enter radius")
r = CInt(ReadLine())
End Sub
Public Overrides Sub findArea()
area = 3.14 * r * r
WriteLine("Area of circle=" & area)
End Sub

Public Overrides Sub findPeri()


peri = 2 * 3.14 * r
WriteLine("Perimeter of circle=" & peri)
End Sub
End Class
Sub main()
Dim rect As New Rectangle
Dim ci As New Circle
rect.showShapeName()
ci.showShapeName()
rect.findArea()
rect.findPeri()
ci.findArea()
ci.findPeri()
ReadKey()

End Sub
End Module

Interface:-

 An interface is mainly used to achieve multiple inheritance.


 It also supports data abstraction.
 An interface is a collection of only function and subroutine
declaration.
 It is created with the help of “interface” keyword.
 We can not create an object of interface.
 It must be implemented within class.
 The body of function and subroutine must be defined within
implemented class.
 The method of interface must be accessed publically.

Creating an interface

Syntax:-
Interface <interface name>

Function declaration
End interface

Implementing an interface:-
Implements:- This keyword is used to implement an interface.
Syntax:-
Class <class name>
Implements <interface name>

Program-5

' implementation of interface


Imports System.Console
Module myinterface
Interface shape

Sub findArea()
Sub findPeri()

End Interface
Class Square
Implements shape
Dim s, ar, pr As Integer

Sub New()
WriteLine("Enter side of square")
s = CInt(ReadLine())
End Sub
Public Sub findArea() Implements
shape.findArea
ar = s * s
WriteLine("Area of square=" & ar)
End Sub

Public Sub findPeri() Implements


shape.findPeri
pr = 4 * s
WriteLine("Perimeter of square=" & pr)
End Sub

End Class
Class Circle
Implements shape
Dim r, ar, pr As Single
Const pi As Single = 3.14
Sub New()
WriteLine("Enter radius of circle")
r = CDbl(ReadLine())
End Sub
Public Sub findArea() Implements
shape.findArea
ar = pi * r * r
WriteLine("Area of Circle=" & ar)
End Sub
Public Sub findPeri() Implements
shape.findPeri
pr = 2 * pi * r
WriteLine("Perimeter of Circle=" & pr)
End Sub
End Class
Sub main()
Dim sq As New Square()
Dim ci As New Circle()
sq.findArea()
sq.findPeri()
ci.findArea()
ci.findPeri()
ReadKey()
End Sub
End Module

Multiple inheritance:-

When one sub class inherited from more than one super class is
called multiple inheritance. This type of inheritance contains one
sub class and more super classes.
VB.net does not support multiple inheritance directly like java. It
can be implemented with the help of interface.

Program-6

'Implementation of multiple inheritance


Imports System.Console
Module multiple_inheritance
Interface bank
Sub debit()
Sub credit()
End Interface
Class customer
Protected cid, cnm As String
Protected balance As Single
Sub New()
WriteLine("Enter customer id, customer
name and balance")
cid = ReadLine()
cnm = ReadLine()
balance = CDbl(ReadLine())
End Sub
End Class
Class Transaction
Inherits customer
Implements bank
Sub New()
MyBase.New()
End Sub
Public Sub credit() Implements bank.credit
Dim amt As Integer
WriteLine("How much amount to be
credited?")
amt = CInt(ReadLine())
balance = balance + amt

End Sub

Public Sub debit() Implements bank.debit


Dim amt As Integer
WriteLine("How much amount to be
debited?")
amt = CInt(ReadLine())
If amt <= balance Then
balance = balance - amt
Else
WriteLine("Transaction failed due to
insufficient fund")
End If

End Sub
Sub showCurrentStatus()
WriteLine("Current status of account" &
vbNewLine & "Customer id=" & cid & vbTab & "customer
name=" & cnm)
WriteLine("Current balance=" & balance)

End Sub
End Class
Sub main()
Dim obj As New Transaction
obj.debit()
obj.credit()
obj.debit()
obj.debit()
obj.showCurrentStatus()
ReadKey()
End Sub
End Module
NAMESPACE
Assembly
WINDOW PROGRAMMING
ADO.NET
GUI BASED PROGRAM IN VB.NET
1. LOGIN PROGRAM

2.

Public Class Form1

Private Sub btnlogin_Click(sender As System.Object, e As System.EventArgs) Handles


btnlogin.Click
Dim unm, pnm As String
unm = txtuser.Text
pnm = txtpass.Text
If unm = "cimage" And pnm = "aku" Then
MessageBox.Show("Login success")

Me.Hide() 'hide current form


' CRICKET_TEAM.Show() 'display cricket form
Dim ct As New CRICKET_TEAM
ct.Show()

Else
MessageBox.Show("Login Failed")
End If
End Sub

Private Sub btnreset_Click(sender As System.Object, e As System.EventArgs) Handles


btnreset.Click
txtuser.Text = ""
txtpass.Text = ""
txtuser.Focus()
End Sub

Private Sub btnexit_Click(sender As System.Object, e As System.EventArgs) Handles


btnexit.Click
End
End Sub
End Class

3. ARITHMETIC OPERATION

Public Class calculator


Dim a, b, rs As Integer
Private Sub btnadd_Click(sender As System.Object, e As System.EventArgs) Handles
btnadd.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a + b
txtresult.Text = rs
lblresult.Text = "Addition=" & rs

End Sub
Private Sub btnsub_Click(sender As System.Object, e As System.EventArgs) Handles
btnsub.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a - b
txtresult.Text = rs
lblresult.Text = "Subtraction=" & rs
End Sub

Private Sub btnmulti_Click(sender As System.Object, e As System.EventArgs) Handles


btnmulti.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a * b
txtresult.Text = rs
lblresult.Text = "Multiplication=" & rs
End Sub

Private Sub btndiv_Click(sender As System.Object, e As System.EventArgs) Handles


btndiv.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a \ b
txtresult.Text = rs
lblresult.Text = "Division=" & rs
End Sub

Private Sub btnrem_Click(sender As System.Object, e As System.EventArgs) Handles


btnrem.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a Mod b
txtresult.Text = rs
lblresult.Text = "Remainder=" & rs
End Sub

Private Sub calculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub btnreset_Click(sender As System.Object, e As System.EventArgs) Handles


btnreset.Click
txtfirst.Text = ""
txtsecond.Text = ""
txtresult.Text = ""
lblresult.Text = "----------------"
txtfirst.Focus()
End Sub

Private Sub btnexit_Click(sender As System.Object, e As System.EventArgs) Handles


btnexit.Click
End
End Sub
End Class

4. STUDENT REGISTRATION FORM


Public Class student

Private Sub student_Load(sender As System.Object, e As System.EventArgs) Handles


MyBase.Load
Me.BackColor = Color.Magenta
cmbcourse.Items.Add("BCA")
cmbcourse.Items.Add("MCA")
cmbcourse.Items.Add("BBA")
cmbcourse.Items.Add("MBA")
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles
Button1.Click
Dim cs, nm, fnm, email, gen, nation, rs As String
gen = ""
nation = ""
Dim hob As String = ""
cs = cmbcourse.Text
'cs = cmbcourse.SelectedItem
nm = txtname.Text
fnm = txtfname.Text
email = txtemail.Text

If rdmale.Checked = True Then


gen = rdmale.Text
ElseIf rdfemale.Checked = True Then
gen = rdfemale.Text
End If

If rdindian.Checked = True Then


nation = rdindian.Text
ElseIf rdnri.Checked = True Then
nation = rdnri.Text
End If

If chkmusic.Checked = True Then


hob = hob & chkmusic.Text & " "

End If
If chknews.Checked = True Then
hob = hob & chknews.Text & " "

End If

If chkcricket.Checked = True Then


hob = hob & chkcricket.Text & " "

End If
rs = "Name=" & nm & vbNewLine & "Father's name=" & fnm & vbNewLine & "Course=" &
cs & vbNewLine & "Gender=" & gen & vbNewLine & "Nationality=" & nation & vbNewLine &
"Hobbies=" & hob & vbNewLine & "Email id=" & email

MessageBox.Show(rs)
End Sub

Private Sub btnreset_Click(sender As System.Object, e As System.EventArgs) Handles


btnreset.Click
txtname.Text = ""
txtfname.Text = ""
txtemail.Text = ""
' cmbcourse.Text = ""
cmbcourse.SelectedIndex = -1
rdmale.Checked = False
rdfemale.Checked = False
rdindian.Checked = False
rdnri.Checked = False
chkcricket.Checked = False
chkmusic.Checked = False
chknews.Checked = False
txtname.Focus()
End Sub
End Class

5. ADD,REMOVE,SEARCH,SORT COLOR IN COMBOBOX AND CHANGE BACKCOLOR OF FORM

Public Class combo

Private Sub btnadd_Click(sender As System.Object, e As System.EventArgs) Handles


btnadd.Click
If cmbcolor.Items.Contains(txtcolor.Text) Then
MessageBox.Show("already this color is available")

else
cmbcolor.Items.Add(txtcolor.Text)
txtcolor.Text = ""
txtcolor.Focus()
End If
End Sub

Private Sub btnremove_Click(sender As System.Object, e As System.EventArgs) Handles


btnremove.Click
cmbcolor.Items.RemoveAt(cmbcolor.SelectedIndex)
'cmbcolor.Items.Remove(cmbcolor.Text)
'cmbcolor.Items.Remove(cmbcolor.SelectedItem)
End Sub
Private Sub btnsearch_Click(sender As System.Object, e As System.EventArgs) Handles
btnsearch.Click
If cmbcolor.Items.Contains(txtcolor.Text) Then
MessageBox.Show("searching is found")
Else
MessageBox.Show("Searching is not found")
End If
End Sub

Private Sub btnsort_Click(sender As System.Object, e As System.EventArgs) Handles


btnsort.Click
cmbcolor.Sorted = True
End Sub

Private Sub btnreset_Click(sender As System.Object, e As System.EventArgs) Handles


btnreset.Click
txtcolor.Text = ""
cmbcolor.Text = ""
txtcolor.Focus()
End Sub

Private Sub btnexit_Click(sender As System.Object, e As System.EventArgs) Handles


btnexit.Click
End
End Sub

Private Sub btncolor_Click(sender As Object, e As EventArgs) Handles btncolor.Click


Dim s As String
s = cmbcolor.Text
Dim obj As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(s)
Me.BackColor = obj

End Sub

Private Sub cmbcolor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


cmbcolor.SelectedIndexChanged
Dim s As String
s = cmbcolor.Text
Dim obj As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml(s)
Me.BackColor = obj
End Sub

Private Sub combo_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class
6. MOVING & COPING PLAYER FROM ONE LIST TO ANOTHER LISTBOX

Public Class CRICKET_TEAM


Private Sub CRICKET_TEAM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackColor = Color.Chocolate
lsttest.Items.Add("VIRAT KOHALI")
lsttest.Items.Add("MAYANK")
Dim player() As String = New String() {"pujara", "Rohit sharma", "Jadeja"}
lsttest.Items.AddRange(player)

End Sub

Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


lsttest.SelectedIndexChanged

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btnmove1.Click


Dim i, j As Integer
j = 1
Try
For i = lstoneday.Items.Count - 1 To 0 Step -1
If lstoneday.GetSelected(i) = True Then
lsttest.Items.Add(lstoneday.Items(i))
'lstoneday.Items.RemoveAt(i)
lstoneday.Items.Remove(lstoneday.Items(i))

End If
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub
Private Sub btncopy1_Click(sender As Object, e As EventArgs) Handles btncopy1.Click
Dim i As Integer
For i = 0 To lstoneday.Items.Count - 1
If lstoneday.GetSelected(i) Then
If lsttest.Items.Contains(lstoneday.Items(i)) Then
MsgBox(lstoneday.Items(i) & " Already available")
Else
lsttest.Items.Add(lstoneday.Items(i))
End If
End If
Next
End Sub

Private Sub btncopy2_Click(sender As Object, e As EventArgs) Handles btncopy2.Click


Dim i As Integer
For i = 0 To lsttest.Items.Count - 1
If lsttest.GetSelected(i) Then
lstoneday.Items.Add(lsttest.Items(i))
End If
Next
End Sub

Private Sub btnmove2_Click(sender As Object, e As EventArgs) Handles btnmove2.Click


Dim i As Integer
For i = 0 To lsttest.Items.Count - 1
If lsttest.GetSelected(i) Then
lstoneday.Items.Add(lsttest.Items(i))
lsttest.Items.RemoveAt(i)
End If
Next
End Sub

Private Sub btncopy3_Click(sender As Object, e As EventArgs) Handles btncopy3.Click


Dim i As Integer
For i = 0 To lsttest.Items.Count - 1
If lsttest.GetSelected(i) Then
lst20.Items.Add(lsttest.Items(i))
End If
Next
End Sub

Private Sub btnmove3_Click(sender As Object, e As EventArgs) Handles btnmove3.Click


Dim i As Integer
For i = 0 To lsttest.Items.Count - 1
If lsttest.GetSelected(i) Then
lst20.Items.Add(lsttest.Items(i))
lsttest.Items.RemoveAt(i)
End If
Next
End Sub

Private Sub btncopy4_Click(sender As Object, e As EventArgs) Handles btncopy4.Click


Dim i As Integer
For i = 0 To lst20.Items.Count - 1
If lst20.GetSelected(i) Then
lsttest.Items.Add(lst20.Items(i))
End If
Next
End Sub
Private Sub btnmove4_Click(sender As Object, e As EventArgs) Handles btnmove4.Click
Dim i As Integer
For i = 0 To lst20.Items.Count - 1
If lst20.GetSelected(i) Then
lsttest.Items.Add(lst20.Items(i))
lst20.Items.RemoveAt(i)
End If
Next
End Sub
End Class

7. DIALOG BOX

Public Class dialog


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ColorDialog1.ShowDialog() = DialogResult.OK Then
Me.BackColor = ColorDialog1.Color
rtb1.SelectionColor = ColorDialog1.Color
End If
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


If FontDialog1.ShowDialog() = DialogResult.OK Then
rtb1.SelectionFont = FontDialog1.Font
End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
rtb1.SaveFile(SaveFileDialog1.FileName)
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
rtb1.LoadFile(OpenFileDialog1.FileName)
End If
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
MessageBox.Show("Selected folder name=" & FolderBrowserDialog1.SelectedPath)
End If
End Sub

Private Sub btnreset_Click(sender As Object, e As EventArgs) Handles btnreset.Click


rtb1.Text = ""
End Sub

Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click


End
End Sub

Private Sub dialog_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class

8. MENUSTRIP
Public Class menu
Dim a, b, rs As Integer
Private Sub RedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
RedToolStripMenuItem.Click
lblmsg.BackColor = Color.Red

End Sub

Private Sub GreenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


GreenToolStripMenuItem.Click
lblmsg.BackColor = Color.Green
End Sub

Private Sub BlueToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


BlueToolStripMenuItem.Click
lblmsg.BackColor = Color.Blue
End Sub

Private Sub CyanToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


CyanToolStripMenuItem.Click
lblmsg.BackColor = Color.Cyan
End Sub

Private Sub PinkToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


PinkToolStripMenuItem.Click
lblmsg.ForeColor = Color.Pink

End Sub

Private Sub GoldToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


GoldToolStripMenuItem.Click
lblmsg.ForeColor = Color.Gold
End Sub

Private Sub PurpleToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


PurpleToolStripMenuItem.Click
lblmsg.ForeColor = Color.Purple
End Sub

Private Sub SubtractionToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles SubtractionToolStripMenuItem.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a - b
txtresult.Text = rs
End Sub

Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


FontToolStripMenuItem.Click
If FontDialog1.ShowDialog = DialogResult.OK Then
lblmsg.Font = FontDialog1.Font
End If
End Sub

Private Sub AdditionToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles


AdditionToolStripMenuItem.Click
a = CInt(txtfirst.Text)
b = CInt(txtsecond.Text)
rs = a + b
txtresult.Text = rs
End Sub
End Class

You might also like