Notes
Notes
SXC Ranchi.
VB.Net notes:1.
-------------------------------------------------------------------------------------------------------------------------------
VB.NET
It is a simple, high-level, object-oriented programming language developed by Microsoft
in 2002.
It is a successor of Visual Basic 6.0, that is implemented on the Microsoft . NET
framework.
It supports the OOPs concept, such as abstraction, encapsulation, inheritance, and
polymorphism.
It's also possible to run VB.NET programs on Mono, the open-source alternative
to .NET, not only under Windows, but even Linux or Mac OSX.
1.
MCA Sem V.
SXC Ranchi.
Versions of .NET:
NET Framework.
Software developers use . NET Framework to build many different types of applications—
websites, services, desktop apps, and more with Visual Studio.
The .Net framework consists of developer tools, programming languages, and libraries to build
desktop and web applications. It is also used to build websites, web services, and games.
Interoperability
Portability
Security
Memory management
Simplified deployment
VS
Visual Studio, also known as Microsoft Visual Studio and VS, is an integrated
development environment for Microsoft Windows.
It is a tool for writing computer programs, websites, web apps, and web services.
It includes
a code editor
debugger
GUI design tool
database schema designer
2.
MCA Sem V.
SXC Ranchi.
*It is not backwards-compatible with VB6, and any code written in the old
version does not compile under VB.NET.
Types of application in VB.net
Console applications.
Windows forms applications.
Web forms
Class library.
Windows control library.
Windows services.
Net website.
Net web services.
Definition:
Console Applications allow us to write data to the console read data from the console,
and run in within a DOS Shell. They do not support Windows GUI's. Console Applications are
supported by the System.
Definition:
Windows Forms is a set of managed libraries in . NET Framework designed to develop rich
client applications. It is a graphical API to display data and manage user interactions with easier
deployment and better security in client applications.
Definition:
ASP.NET Web Forms is a web application framework and one of several programming models
supported by the Microsoft ASP.NET technology. Web Forms applications can be written in
any programming language which supports the Common Language Runtime, such
as C# or Visual Basic.
Definition:Web Forms was included in the original .NET Framework 1.0 release in 2002 as the
first programming model available in ASP.NET
* Unlike newer ASP.NET components, Web Forms is not supported by ASP.NET Core.
Definition:
NET Framework Class Library is the collection of classes, namespaces, interfaces
and value types that are used for . NET applications. It contains thousands of classes
that supports the following functions. Base and user-defined data types. Support for
exceptions handling.
3.
MCA Sem V.
SXC Ranchi.
IDE
(IDE), also known as integrated design environment and integrated debugging environment, is a
type of computer software that assists computer programmers to develop software.
4.
MCA Sem V.
SXC Ranchi.
1.0 Visual Studio .NET Contained the first version of the CLR & base class libraries
1.1 Visual Studio .NET 2003
2.0 Visual Studio 2005
3.0 Visual Studio 2005
3.5 Visual Studio 2008
4 Visual Studio 2010
4.5 Visual Studio 2012
4.5.1 Visual Studio 2013
4.6.1 Visual Studio 2015
4.7.2 Visual Studio 2017
4.8 Visual Studio 2019
4.8 Visual Studio 2022
1- GUI interface:- VB.NET is a graphical user interface (GUI) language. This means that
users can interact and interact with the screen.
5.
MCA Sem V.
SXC Ranchi.
4- Windows form designer:- VB.net has windows form designer. By which the form can
be designed.
7:- Namespaces:- The namespace that is there organizes the objects present in the
assembly. An assembly can have more than one namespace.
8:- Attributes:- attributes which are tags are those which provide additional information
about the elements.
The attributes are most commonly used to explain the COM property of classes, interface,
and methods, to explain assemblies, and to specify the security of methods.
9- Inheritance:- Through inheritance, we can create such a class as derived from the base
class.
The advantage of inheritance is that we have to design only one bar in the class.
10- Multithreading:- Through multithreading, the application can handle many abstract
tasks simultaneously.
Variable means the name of the storage area that our program can use. VB.Net has a
specific type of all Variable, which determines the size and memory layout of Variable.
6.
MCA Sem V.
SXC Ranchi.
Arrays in VB.net
o An array is a linear data structure that is a collection of data elements of the
same type stored on a contiguous memory location.
o Each data item is called an element of the array.
o It is a fixed size of sequentially arranged elements in computer memory with
the first element being at index 0 and the last element at index n -
1, where n represents the total number of elements in the array.
IDE has more features such as through this we can store the code online, format the code
and optimize the code and it has a lot of plugins and extensions which is very helpful in
creating a rich application.
The IDE's toolbar looks like a word processor. This is called IDE because we can access
the necessary tools to develop the software application.
IDE components
7.
MCA Sem V.
SXC Ranchi.
2- Toolbar
It provides quick access to most commonly used commands while programming, that is, we
can quickly access such commands which are used most often.
We can perform a task related to it by clicking a button in the toolbar. We can change the
settings of the toolbar from the View menu.
3- Form designer:- For a software application, form objects are like building blocks. This is
the window from which the user interacts at the beginning of the application. Forms have
their own properties, events, and methods that we can control. The form window is a
window where we draw our application.
4- Toolbox (toolbox):- The toolbox is a very large box with many different icons in it. This
is the selection menu for controls. These controls are used to customize forms.
Some of its controls are as follows:-
5- Property window
The property window which displays properties for forms or controls is properties attributes
like size, position, etc.
Like form, control also has its own unique properties. Some properties like width and height
are similar in both, but apart from this other properties are different.
6- Menu bar:- menu bar displays the commands that are required to create applications. It
is a horizontal strip that appears on top of the screen and it contains the names of menus.
o file- It contains options to open, close, print, etc. of the project.
o edit- It contains the options of cut, paste, undo, delete, find, etc.
8.
MCA Sem V.
SXC Ranchi.
o view- This IDE displays the options to display Windows and toolbar.
o project- It displays the options to add features to the project.
o format- It contains the options to align and lock the control of the form.
o debug - This includes debugging options.
o run- It contains options to execute, stop the program.
o diagram- It contains options to edit and view the design of the database.
o tools– It contains options for IDE tools.
o Add-ins- It contains the options to use, install, remove add-ins.
o windows- It contains options to arrange and display the windows.
o help- It contains options for taking the help.
Do Loop
Do While
For...Next
For Each...Next
While... End While
Nested loops
9.
MCA Sem V.
SXC Ranchi.
Do Loop example.
Imports System
Module Do_loop
Sub Main()
' Initializatio and Declaration of variable i
Dim i As Integer = 1
Do
' Executes the following Statement
Console.WriteLine(" Value of variable I is : {0}", i)
i = i + 1 'Increment the variable i by 1
Loop While i <= 10 ' Define the While Condition
10.
MCA Sem V.
SXC Ranchi.
Module Number
Sub Main()
For i As Integer = 1 To 10 Step 1
Console.WriteLine(" Number is {0} ", i)
' after completion of each iteration, next will update the variable co
unter
Next
Console.WriteLine(" Press any key to exit... ")
Console.ReadKey()
End Sub
End Module
You can use one or more loops inside any another While, For or Do loop.
Exit Statement
In VB.NET, the Exit statement is used to terminate the loop (for, while, do, select case, etc.) or
exit the loop and pass control immediately to the next statement of the termination loop.
Furthermore, the Exit statement can also be used in the nested loop to stop or terminate the
execution of the inner or outer loop at any time, depending on our requirements.
Continue Statement
In VB.NET, the continue statement is used to skip the particular iteration of the loop and
continue with the next iteration.
Generally, the continue Statement is written inside the body of the For, While and Do While loop
with a condition.
11.
MCA Sem V.
SXC Ranchi.
OOP is a philosophy and a way of thinking, designing and implementing solutions that focuses
on reusability. This approach is inspired by the industrial revolution - the invention of basic
components. For example, when we build our house, we don't burn our own bricks and forge
nails, we order them.
Attributes
Object attributes are properties or data that it stores, e.g. the human's name and age.
For the database object it could be the password or whatever the objects requires to
work.
Attributes are just like ordinary variables with which we've worked a hundred times.
Sometimes they're called the "object's internal state"
Methods
Methods are abilities that the object can perform. Human, for example, could have the methods
GoToWork(), Greet() or Blink().
Class
o We have already encountered the term "class".A class is a pattern that we use
to create objects. It defines their properties and abilities.
Objects
o Objects are instances of classes; you can create as many objects you need once
you have defined a class. ... The class is used to create objects.
12.
MCA Sem V.
SXC Ranchi.
Interface
o In visual basic, Interface is same as a class but the only difference is class can
contain both declarations and implementation of methods, properties, and events
but Interface will contain only the declarations of methods, properties, and events
that a class or structure can implement.
Inheritance
o is the idea that one class, called a subclass, can be based on another class,
called a base class. Inheritance provides a mechanism for creating hierarchies of
objects.
Abstraction
Encapsulation
o is the exposure of properties and methods of an object while hiding the actual
implementation from the outside world. In other words, the object is treated as a
black box—developers who use the object should have no need to understand
how it actually works.
Polymorphism
Module My_program
Sub Main()
Dim rect As Rectangle = New Rectangle() 'create an object
Dim rect2 As Rectangle = New Rectangle() 'create an object
Dim area, para As Integer
rect.setLength = (5)
13.
MCA Sem V.
SXC Ranchi.
rect.setBreadth= (6)
rect2.setLength = (5)
rect2.setBreadth = (10)
'para = rect.GetParameter()
para = 2 (rect2.length + rect.Breadth)
Console.WriteLine(" Parameter of Rectangle is {0}", para)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
Public Class Rectangle
Public length As Integer
Public Breadth As Integer
14.
MCA Sem V.
SXC Ranchi.
Partial: As the name defines, a Partial represents the partial definition of the
class (optional).
Implements: It is used to specify interfaces from which the class inherits
(optional).
Public Class Bird
Public Sub Chirp()
Console.WriteLine("♫ ♫ ♫")
End Sub
Public Sub Peck()
Console.WriteLine("Peck, peck!")
End Sub
End Class
Exception Handling
15.
MCA Sem V.
SXC Ranchi.
Unstructured exception handling involves the use of the On Error statement. When an
exception is raised in a program, control of the program moves to the argument
specified in the On Error statement. You use an On Error statement at the beginning of
a set of statements, such as a procedure. There are four forms of the On Error
statement:
System.IndexOutOfRangeException
16.
MCA Sem V.
SXC Ranchi.
Handles errors generated when a method refers to an array index out of range.
System.ArrayTypeMismatchException
Handles errors generated when type is mismatched with the array type.
System.NullReferenceException
Handles errors generated from deferencing a null object.
System.DivideByZeroException
Handles errors generated from dividing a dividend with zero.
System.InvalidCastException
Handles errors generated during typecasting.
System.OutOfMemoryException
Handles errors generated from insufficient free memory.
System.StackOverflowException
Handles errors generated from stack overflow.
Examples:
End Sub
End Module
17.
MCA Sem V.
SXC Ranchi.
18.
MCA Sem V.
SXC Ranchi.
1. Color Dialog Box: It is used to display the color dialog box that allows
the user to select a color from the predefined colors or specify the
custom colors.
2. Font DialogBox: It is used to create a Font dialog box that allows the
user to select the font, font size, color, and style to be applied to the
current text selection.
3. OpenFile Dialog Box: It is used to create a prompt box that allows the
users to select a file to open and allows the selection of multiple files.
4. Print Dialog Box: It is used to create a print dialog box that allows the
user to print documents by selecting the printer and setting of the
page printed through the Windows application.
19.
MCA Sem V.
SXC Ranchi.
Function Overloading
Allowed :
Public Overloads Function add(ByVal a As Integer, ByVal b As Integer)
Public Overloads Function add(ByVal a As Long, ByVal b As Long)
Not Allowed :
Public Overloads Function add(ByVal a As Integer, ByVal b As Integer)
Public Overloads Sub add(ByVal a As Long, ByVal b As Long)
Don't repeat same parameters with same data types in parameter, it will show an error
Imports System.Console
Module Module1
Public Class demo
Public Overloads Function add(ByVal a As Integer, ByVal b As Integer)
WriteLine("You are in function add(integer, integer)")
Return a + b
End Function
Public Overloads Function add(ByVal a As Long, ByVal b As Long)
WriteLine("You are in function add(long, long)")
Return a + b
End Function
End Class
Sub Main()
Dim obj As New demo
WriteLine(obj.add(2147483640, 4))
WriteLine(obj.add(2147483648, 1))
WriteLine("press return to exit...")
Read()
End Sub
End Module
20.
MCA Sem V.
SXC Ranchi.
MustInherit example.
Module Module1
MustInherit Class Sample1
Sub Fun1()
Console.WriteLine("Fun1() called")
End Sub
End Class
Class Sample2
Inherits Sample1
Sub Fun2()
Console.WriteLine("Fun2() called")
End Sub
End Class
Sub Main()
MustOverride example
Module Module1
MustInherit Class Sample1
MustOverride Sub Fun()
End Class
Class Sample2
Inherits Sample1
'Here we need to override the Fun() method
'otherwise it will generate the error.
Overrides Sub Fun()
Console.WriteLine("Override method Fun() called")
End Sub
End Class
Sub Main()
Dim S As New Sample2()
S.Fun()
End Sub
End Module
Module Module1
21.
MCA Sem V.
SXC Ranchi.
Interface IName
Sub GetName(ByVal x As String)
End Interface
Interface ILocation
Sub GetLocation(ByVal x As String)
End Interface
Interface IAge
Sub GetAge(ByVal x As Integer)
End Interface
Class User
Implements IName, ILocation, IAge
Public Sub GetName(ByVal a As String) Implements IName.GetName
Console.WriteLine("Name: {0}", a)
End Sub
Public Sub GetLocation(ByVal a As String) Implements ILocation.GetLocation
Console.WriteLine("Location: {0}", a)
End Sub
Public Sub GetAge(ByVal a As Integer) Implements IAge.GetAge
Console.WriteLine("Age: {0}", a)
End Sub
End Class
Sub Main(ByVal args As String())
Dim u As User = New User()
u.GetName("Suresh Dasari")
u.GetLocation("Hyderabad")
u.GetAge(32)
Console.WriteLine(vbLf & "Press Enter Key to Exit..")
Console.ReadLine()
End Sub
End Module
22.
MCA Sem V.
SXC Ranchi.
reversedArray = System.Array.Reverse(arrayName)
sourceArray.CopyTo(destinationArray, sourceStart)
System.Array.FindAll(array, match)
23.
MCA Sem V.
SXC Ranchi.
DataSet .
The .Net Framework includes mainly three Data Providers for ADO.NET. The
Microsoft SQL Server , OLEDB and ODBC are the main Data Providers in
the .Net Framework.
24.
MCA Sem V.
SXC Ranchi.
ADO.Net object model is nothing but the structured process flow through
various components. The object model can be pictorially described as:
The data residing in a data store or database is retrieved through the data
provider. Various components of the data provider retrieve data for the
application and update data.
25.
MCA Sem V.
SXC Ranchi.
Data Provider
Connection
1
This component is used to set up a connection with a data source.
Command
2 A command is a SQL statement or a stored procedure used to retrieve, insert, delete or modify data in a data
source.
DataReader
3
Data reader is used to retrieve data from a data source in a read-only and forward-only mode.
DataAdapter
This is integral to the working of ADO.Net since data is transferred to and from a database through a data
4
adapter. It retrieves data from a database into a dataset and updates the database. When changes are made
to the dataset, the changes in the database are actually done by the data adapter.
o The .Net Framework data provider for SQL Server - provides access to
Microsoft SQL Server.
o The .Net Framework data provider for OLE DB - provides access to data
sources exposed by using OLE DB.
o The .Net Framework data provider for ODBC - provides access to data
sources exposed by ODBC.
26.
MCA Sem V.
SXC Ranchi.
DataSet
DataTableCollection
1
It contains all the tables retrieved from the data source.
DataRelationCollection
2
It contains relationships and the links between tables in a data set.
27.
MCA Sem V.
SXC Ranchi.
ExtendedProperties
3
It contains additional information, like the SQL statement for retrieving data, time of retrieval, etc.
DataTable
4 It represents a table in the DataTableCollection of a dataset. It consists of the DataRow and DataColumn
objects. The DataTable objects are case-sensitive.
DataRelation
5 It represents a relationship in the DataRelationshipCollection of the dataset. It is used to relate two DataTable
objects to each other through the DataColumn objects.
DataRowCollection
6
It contains all the rows in a DataTable.
DataView
7
It represents a fixed customized view of a DataTable for sorting, filtering, searching, editing and navigation.
PrimaryKey
8
It represents the column that uniquely identifies a row in a DataTable.
DataRow
It represents a row in the DataTable. The DataRow object and its properties and methods are used to
9
retrieve, evaluate, insert, delete, and update values in the DataTable. The NewRow method is used to create
a new row and the Add method adds a row to the table.
DataColumnCollection
10
It represents all the columns in a DataTable.
DataColumn
11
It consists of the number of columns that comprise a DataTable.
Connecting to a Database
28.
MCA Sem V.
SXC Ranchi.
Example 1
Select a server name and the database name in the Add Connection dialog
box.
29.
MCA Sem V.
SXC Ranchi.
30.
MCA Sem V.
SXC Ranchi.
31.
MCA Sem V.
SXC Ranchi.
32.
MCA Sem V.
SXC Ranchi.
33.
MCA Sem V.
SXC Ranchi.
Choose the database object, Customers table in our example, and click the
Finish button.
Select the Preview Data link to see the data in the Results grid:
34.
MCA Sem V.
SXC Ranchi.
When the application is run using Start button available at the Microsoft Visual Studio tool bar, it will show the
following window:
Example 2
In this example, let us access data in a DataGridView control using code. Take the following steps:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
'TODO: This line of code loads data into the 'TestDBDataSet.CUSTOMERS' table.
You can move, or remove it, as needed.
Me.CUSTOMERSTableAdapter.Fill(Me.TestDBDataSet.CUSTOMERS)
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
35.
MCA Sem V.
SXC Ranchi.
When the above code is executed and run using Start button available at the
Microsoft Visual Studio tool bar, it will show the following window:
Clicking the Fill button displays the table on the data grid view control:
36.
MCA Sem V.
SXC Ranchi.
Example 3
So far, we have used tables and databases already existing in our computer.
In this example, we will create a table, add columns, rows and data into it
and display the table using a DataGridView object.
37.
MCA Sem V.
SXC Ranchi.
38.
MCA Sem V.
SXC Ranchi.
When the above code is executed and run using Start button available at the
Microsoft Visual Studio tool bar,
Clicking the Fill button displays the table on the data grid view control:
39.
MCA Sem V.
SXC Ranchi.
40.
MCA Sem V.
SXC Ranchi.
41.