Sei sulla pagina 1di 42

Programming Using VB.

net

A Practical File
Submitted by
Ankit Sharma
(MU16BCA027)
Under the guidance of

MR. AMIT SAHU


In partial fulfilment for the award of the degree
Of
BACHELORS OF COMPUTER APPLICATION
SCHOOL OF INFORMATION TECHNOLOGY
MATS UNIVERSITY
RAIPUR (C.G)
2017-18
ACKNOWLEDGEMENT

I convey my sincere gratitude to MR AMIT SAHU for giving me

the opportunity to prepare my practical assignment. I express my

sincere thanks to my mentors and friends for helping me to complete

this.

I express my sincere obligation and thanks to all the Faculties of

School of Information Technology, MATS University, Raipur for

their valuable advice in guiding me at every stage in assignment.

Name: Ankit Sharma


Enrolment ID: MU16BCA027
DECLARATION

This is to certify that this Practical Assignment which is submitted by

me in partial fulfilment of the requirement for the completion of

Bachelors of Computer Application, to MATS School of Information

Technology, MATS University, Raipur, comprises my original work

and due acknowledgement has been made in the text to all other

material and resources used.

Name of the student: Ankit Sharma

Signature: …………
CERTIFICATE OF COMPLETION

This is to certify that I, Ankit Sharma have completed the Practical

Assignment based on “Programming Using VB.net”. The practical

assignment has been written according to the guidelines given by the

MATS School of Information Technology, MATS University, and

Raipur.

Signature of the Head of Institution: Date:

Name of the Head of Institution: Place:


CERTIFICATE OF EVALUATION

This is to certify that the undersigned have assessed and evaluated


the Practical Assignment Based on “Programming Using VB.net” by
Ankit Sharma.

The Practical Assignment has been accepted for the partial fulfilment
of BCA program.

Signature of the External Signature of the Internal


Examiner

Name of the Examiner Name of the Examiner

Stamp of the Institution


INDEX
Seri Name of Topics Page Remark Sign.
al No. s
No.
1. Develop a windows application to view data in data

grid view

2. Develop a windows program to implement timer

3. Develop a windows application to change foreground

and background colour using radio button

4. Develop a windows application to add

DateTimePicker control and show date, month and

year in separate textbox

5. Develop a windows applications to edit and modify

data in data grid view

6. Develop a windows application to read pdf file

7. Develop a windows program to implement calculator.

8. Develop a database application to register a user.

After registration user can login in the application and

show details of user

9. Develop a windows program of book management

system

10. Write a console program to implement call by value

and call by reference


11. Write a console program to implement constructor

and destructor

12. Write a console program to demonstrate the use of

run time and compile time polymorphism

13. write a program to implement abstract method

14. Write a console program to implement interface X

15. Write a program to implement inheritance

16. Write a program to implement access specifiers

17. Write a program to demonstrate use of My Base and

My Class keyword
1. Develop a windows application to view data in data grid
view

Imports System.Data.OleDb

Public Class Form1

Public my_conn As OleDbConnection = New OleDbConnection

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


Handles Button1.Click

Dim conn_string As String


conn_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Desktop\updatedatatainvb\Database2.mdb"
my_conn.ConnectionString = conn_string
my_conn.Open()
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [userData]",
my_conn)
da.Fill(ds, "userData")
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
my_conn.Close()
End Sub

End Class
2.Develop a windows program to implement timer

Public Class Form1

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = Now.ToLocalTime
End Sub

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


Handles Button1.Click
Timer1.Start()
End Sub

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


Handles Button2.Click
Timer1.Stop()
End Sub
End Class
3.Develop a windows application to change foreground and
background colour using radio button

Public Class Form1


Private Sub RadioButton1_CheckedChanged(sender As Object, e As
EventArgs) Handles RadioButton1.CheckedChanged
ForeColor = Color.Red
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton2.CheckedChanged
ForeColor = Color.Blue
End Sub

Private Sub RadioButton3_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton3.CheckedChanged
ForeColor = Color.Green
End Sub

Private Sub RadioButton4_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton4.CheckedChanged
ForeColor = Color.Yellow
End Sub

Private Sub RadioButton5_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton5.CheckedChanged
ForeColor = Color.Orange
End Sub

Private Sub RadioButton10_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton10.CheckedChanged
BackColor = Color.Red
End Sub

Private Sub RadioButton9_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton9.CheckedChanged
BackColor = Color.Blue
End Sub

Private Sub RadioButton8_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton8.CheckedChanged
BackColor = Color.Green
End Sub

Private Sub RadioButton7_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton7.CheckedChanged
BackColor = Color.Yellow
End Sub

Private Sub RadioButton6_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton6.CheckedChanged
BackColor = Color.Orange
End Sub
End Class
4.Develop a windows application to add DateTimePicker
control and show date, month and year in separate textbox

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
TextBox1.Text = DateTimePicker1.Value.Day
TextBox2.Text = DateTimePicker1.Value.Month
TextBox3.Text = DateTimePicker1.Value.Year
End Sub
End Class
5.Develop a windows applications to edit and modify data
in data grid view

Imports System.Data.OleDb
Public Class Form1
Dim connString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Music\VB.Net\Windows Application\update grid
view\Database3.mdb"
Dim MyConn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
Dim conn_string As String
Dim my_conn As OleDb.OleDbConnection

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


Handles Button1.Click
Try
Dim Conn As New OleDb.OleDbConnection
Dim Query As New OleDb.OleDbCommand
Dim Connstring As String
Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Music\VB.Net\Windows Application\update grid
view\Database3.mdb"
Conn.ConnectionString = Connstring
Query.Connection = Conn
Conn.Open()
Query.CommandText = "insert into data
Values(@ID,@Name,@Contact,@Address)"
'@USERNAME,@PASSWORD)"
Query.Parameters.AddWithValue("@ID", TextBox1.Text)
Query.Parameters.AddWithValue("@Name", TextBox2.Text)
Query.Parameters.AddWithValue("@Contact", TextBox3.Text)
Query.Parameters.AddWithValue("@Address", TextBox4.Text)

Query.ExecuteNonQuery()
MessageBox.Show("Record Inserted")

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button4.Click
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [data]", MyConn)
'Change items to your database name
da.Fill(ds, "data") 'Change items to your database name
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
End Sub

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


Handles Button3.Click
Dim con As OleDbConnection
Dim com As OleDbCommand
con = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Music\VB.Net\Windows Application\update grid
view\Database3.mdb")
com = New OleDbCommand("delete from data where ID =@ID",
con)
con.Open()
com.Parameters.AddWithValue("@sno", TextBox2.Text)
com.ExecuteNonQuery()
MsgBox("Record Deleted")
con.Close()
End Sub

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


Handles Button2.Click
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
dataFile = "C:\Users\Hello\Music\VB.Net\Windows
Application\update grid view\Database3.mdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "update data set Name = '" & TextBox2.Text &
"',Contact = '" & TextBox3.Text & "',Address = '" & TextBox4.Text &
"' Where ID = '" & TextBox1.Text & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str,
myConnection)
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
myConnection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
6.Develop a windows application to read pdf file

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
OpenFileDialog1.Filter = "PDF Files | *.pdf"
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
AxAcroPDF1.src = OpenFileDialog1.FileName
End If
End Sub
End Class
7.Develop a windows program to implement calculator

Public Class Form1

Dim Firstnum As Decimal


Dim Secondnum As Decimal
Dim Operations As Integer
Dim Operator_Selector As Boolean = False

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


Handles Button1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub

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


Handles Button2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub

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


Handles Button3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub

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


Handles Button4.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub

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


Handles Button5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub

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


Handles Button6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub

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


Handles Button7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub

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


Handles Button8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub

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


Handles Button10.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub

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


Handles Button9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs)
Handles Button12.Click
TextBox1.Text = "0"
End Sub

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


Handles Button11.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub

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


Handles Button14.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_Selector = True
Operations = 1
End Sub

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


Handles Button17.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_Selector = True
Operations = 2
End Sub

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


Handles Button16.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_Selector = True
Operations = 3
End Sub

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


Handles Button15.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_Selector = True
Operations = 4
End Sub

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


Handles Button18.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_Selector = True
Operations = 5
End Sub

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


Handles Button13.Click
If Operator_Selector = True Then
Secondnum = TextBox1.Text
If Operations = 1 Then
TextBox1.Text = Firstnum + Secondnum
ElseIf Operations = 2 Then
TextBox1.Text = Firstnum - Secondnum
ElseIf Operations = 3 Then
TextBox1.Text = Firstnum * Secondnum
ElseIf Operations = 5 Then
TextBox1.Text = (Firstnum * Secondnum) / 100
Else
If Secondnum = 0 Then
TextBox1.Text = "Error"
Else
TextBox1.Text = Firstnum / Secondnum
End If
End If
Operator_Selector = False
End If
End Sub
End Class
8. Develop a database application to register a user. After
registration user can login in the application and show
details of user

Registration
Public Class Form2
Private Sub Button2_Click(sender As Object, e As EventArgs)
Handles Button2.Click
Me.Hide()
Form1.Show()

End Sub

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


Handles Button1.Click
Try
Dim Conn As New OleDb.OleDbConnection
Dim Query As New OleDb.OleDbCommand
Dim Connstring As String
Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Documents\Clg project\Quiz_System.mdb"

Conn.ConnectionString = Connstring
Query.Connection = Conn
Conn.Open()
Query.CommandText = "insert into Quiz
Values(@Name,@User_ID,@Password,@Email)"
Query.Parameters.AddWithValue("@Name", TextBox1.Text)
Query.Parameters.AddWithValue("@User_ID", TextBox2.Text)
Query.Parameters.AddWithValue("@Password",
TextBox3.Text)
Query.Parameters.AddWithValue("@Email", TextBox4.Text)

Query.ExecuteNonQuery()
MessageBox.Show("Record Inserted")

Catch ex As Exception
MessageBox.Show(ex.Message)

End Try
Form1.Show()
End Sub
End Class
Login
Imports System.Data.OleDb
Public Class Form1

Dim conn_string As String


Dim myconnection As OleDbConnection = New OleDbConnection

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


Handles Button1.Click
conn_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Documents\Clg project\Quiz_System.mdb"
myconnection.ConnectionString = conn_string
myconnection.Open()

Dim cmd As OleDbCommand = New OleDbCommand("select * from


Quiz where UserID='" & TextBox1.Text & "'and Password='" &
TextBox2.Text & "'", myconnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim userfound As Boolean = False

Dim UserID As String = ""


Dim Password As String = ""

While dr.Read
userfound = True
UserID = dr("UserID")
Password = dr("Password")

End While
If userfound = True Then
Me.Hide()
Form3.Show()

Else
MsgBox("SORRY USER_ID AND PASSWORD NOT FOUND")
End If
End Sub

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


Handles Button2.Click
Me.Hide()
Form2.Show()

End Sub
End Class
SHOW DETAILS
Imports System.Data.OleDb
Public Class Form3
Dim connString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Documents\Clg project\Quiz_System.mdb"
Dim MyConn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
'
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
MyConn = New OleDbConnection
MyConn.ConnectionString = connString
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [Quiz]", MyConn)
'Change items to your database name
da.Fill(ds, "Quiz") 'Change items to your database name
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
End Sub
End Class
9.Develop a windows program of book management system
Imports System.Data.OleDb
Public Class Form1
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Music\VB.Net\Windows Application\Book
Management\BookManagement.mdb"
Dim MyConn As OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As DataSet
Dim tables As DataTableCollection
Dim source1 As New BindingSource
Dim conn_string As String
Dim my_conn As OleDb.OleDbConnection

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


MyConn = New OleDbConnection
MyConn.ConnectionString = connString
ds = New DataSet
tables = ds.Tables
da = New OleDbDataAdapter("Select * from [BOOKDETAILS]", MyConn)
da.Fill(ds, "BOOKDETAILS")
Dim view As New DataView(tables(0))
source1.DataSource = view
DataGridView1.DataSource = view
End Sub

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


Dim con As OleDbConnection
Dim com As OleDbCommand
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Music\VB.Net\Windows Application\Book
Management\BookManagement.mdb")
com = New OleDbCommand("delete from BOOKDETAILS where BookID =@BookID", con)
con.Open()
com.Parameters.AddWithValue("@sno", TextBox1.Text)
com.ExecuteNonQuery()
MsgBox("Record Deleted")
con.Close()
End Sub

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


Dim provider As String
Dim DataFile As String
Dim connection As OleDbConnection = New OleDbConnection
provider = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
DataFile = "C:\Users\Hello\Music\VB.Net\Windows Application\Book
Management\BookManagement.mdb"
connString = provider & DataFile
connection.ConnectionString = connString
connection.Open()
Dim Query As String
Query = "Update [BOOKDETAILS] set [BookName]='" & TextBox2.Text &
"',[BookAuthor]= '" & TextBox3.Text & "', [BookEdition]= '" & TextBox4.Text &
"',[BookPrice]= '" & TextBox5.Text & "' Where BookID = '" & TextBox1.Text & "'"
Dim cmd As OleDbCommand = New OleDbCommand(Query, connection)
Try
cmd.ExecuteNonQuery()
MessageBox.Show("Record Update")
cmd.Dispose()
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click


Try
Dim Conn As New OleDb.OleDbConnection
Dim Query As New OleDb.OleDbCommand
Dim Connstring As String
Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Hello\Music\VB.Net\Windows Application\Book
Management\BookManagement.mdb"
Conn.ConnectionString = Connstring
Query.Connection = Conn
Conn.Open()
Query.CommandText = "insert into BOOKDETAILS
Values(@BookID,@BookName,@BookAuthor,@BookEdition,@BookPrice)"
Query.Parameters.AddWithValue("@BookID", TextBox1.Text)
Query.Parameters.AddWithValue("@BookName", TextBox2.Text)
Query.Parameters.AddWithValue("@BookAuthor", TextBox3.Text)
Query.Parameters.AddWithValue("@BookEdition", TextBox4.Text)
Query.Parameters.AddWithValue("@BookPrice", TextBox5.Text)
Query.ExecuteNonQuery()
MessageBox.Show("Record Inserted")

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
10.Write a console program to implement call by value and
call by reference

Module Module1

Sub change(ByVal n As Integer)


n = n + 20
End Sub

Sub Changes(ByRef n As Integer)


n = n + 200
End Sub

Sub Main()

Dim n As Integer = 9
change(n)
Console.WriteLine(n)
Changes(n)
Console.WriteLine(n)
Console.ReadKey()

End Sub

End Module
11.Write a console program to implement constructor and
destructor
Imports System.Console
Module Module1
Class base
Private a As Integer
Private b As Double
Private c As String
Public Sub New(ByVal x As Integer, ByVal y As Double, ByVal
z As String)
WriteLine("CONSTRUCTOR OF BASE CLASS EXECUTED!!!!!")
a = x
b = y
c = z
WriteLine("a=" & a)
WriteLine("b=" & b)
WriteLine("c=" & c)
End Sub
Protected Overrides Sub finalize()
WriteLine("DESTRUCTOR OF BASE CLASS EXECUTED!!!!")
End Sub
End Class
Class derive : Inherits base
Private d As Integer
Public Sub New(ByVal e As Integer, ByVal x As Integer, ByVal
y As Double, ByVal z As String)
MyBase.New(x, y, z)
WriteLine("CONSTRUCTOR OF DERIVED CLASS EXECUTED!!!!")
d = e
WriteLine("d=" & d)

End Sub

End Class
Sub Main()
WriteLine("WHEN WE DECALRE OBJECT OF BASE CLASSS :-")
WriteLine()
WriteLine()
Dim s2 As derive = New derive(40, 50, 176, "")
Console.ReadKey()

End Sub

End Module
12. Write a console program to demonstrate the use of run
time and compile time polymorphism

Module Module1
Class Person

Private strName As String


Public intAge As Integer

Public Function getName()


Return strName
End Function

Public Function getAge()


Return intAge
End Function

Public Sub setName(ByVal name As String)


strName = name
End Sub

Public Overridable Sub Play()


Console.WriteLine("Compile Time Polymorphism")
End Sub
End Class

Class CricketPlayer

Inherits Person

Public strNationality As String

Function getNationality()
Return strNationality
End Function

Public Overrides Sub Play()


Console.WriteLine("Runtime Polymorphism")
End Sub
End Class

Sub Main()
Console.WriteLine("Polymorphism Example")
Dim Player As New CricketPlayer
Console.WriteLine()
Player.Play()
Dim Person1 As New Person
Console.WriteLine()
Person1.Play()
Dim CricPlayer As New CricketPlayer
Dim person2 As Person
person2 = CricPlayer
Console.WriteLine()
person2.Play()
Console.WriteLine()
Console.ReadKey()
End Sub
End Module
13.write a program to implement abstract method

Module Module1
Public MustInherit Class AbstractClass
Public MustOverride Function Add() As Integer
Public MustOverride Function Mul() As Integer
End Class

Public Class AbstractOne


Inherits AbstractClass
Dim i As Integer = 50
Dim j As Integer = 50

Public Overrides Function Add() As Integer


Return i + j
End Function

Public Overrides Function Mul() As Integer


Return i * j
End Function

End Class

Sub Main()

Dim abs As New AbstractOne()


Console.WriteLine("Sum is {0}", abs.Add())
Console.WriteLine("Multiplication Is {0}", abs.Mul())
Console.ReadKey()

End Sub
End Module
14.Write a console program to implement interface X

Module Module1

Interface operate
Event Calculate(ByVal x As Integer, ByVal y As Integer)
Function Difference(ByVal a As Integer, ByVal b As Integer)
As Integer
Function Product(ByVal a As Integer, ByVal b As Integer) As
Long
End Interface

Class main_operate
Implements operate

Public Event CalculOp(ByVal x As Integer, ByVal y As


Integer) Implements operate.Calculate

Public Function Dif(ByVal a As Integer, ByVal b As Integer)


As Integer Implements operate.Difference
Return a - b
End Function

Public Function Prod(ByVal a As Integer, ByVal b As Integer)


As Long Implements operate.Product
Return a * b
End Function

End Class

Sub Main()
Dim x, y, w As Integer
x = 20
y = 80
Dim z As Long
Dim cal As New main_operate
z = cal.Prod(x, y)
w = cal.Dif(x, y)
Console.WriteLine("Substraction value is: " & w & "
Multiplication value is: " & z)
Console.ReadKey()
End Sub

End Module
15.Write a program to implement inheritance

Module Module1

Sub Main()
Dim Obj As New Subclass()
Console.WriteLine("im from subclass {0}", Obj.sum())
Console.WriteLine("im from baseclass {0}", Obj.add())
Console.ReadKey()
End Sub

End Module

Public Class Superclass

Public X As Integer = 10
Public Y As Integer = 25

Public Function add() As Integer


Return X + Y
End Function

End Class

Public Class Subclass

Inherits Superclass
Public Z As Integer = 25
Public Function sum() As Integer
Return X + Y + Z
End Function

End Class
16.Write a program to implement access specifiers

Module Module1

Class organisms
Public species As String
Private age As Byte
Protected name As String

Public Function Getage() As Byte


Return Me.age
End Function

Public Function Setage(ByVal age As Byte)


Me.age = age
End Function

End Class

Class animal : Inherits organisms

End Class

Sub Main()
Dim obj As New organisms
obj.species = "Ankit"
obj.Setage(7)
Console.Write("{0} is 20 year old", obj.species,
obj.Getage())
Console.ReadKey()
End Sub
End Module
17. Write a program to demonstrate use of My Base and My
Class keyword

Module Module1

Sub Main()
Dim p As parent
Dim c As child
p = New parent
p.p1()
p.p2()
p = New child
p.p1()
Console.ReadLine()
End Sub

Public Class parent


Public Overridable Sub p1()
Console.WriteLine("parent p1")
End Sub

Public Sub p2()


MyClass.p1()
End Sub
End Class

Public Class child : Inherits parent


Public Overrides Sub p1()
Console.WriteLine("child p1")
MyBase.p1()
End Sub
End Class
End Module

Potrebbero piacerti anche