You are on page 1of 63

1)

Module Module1
Sub Main()
Console.Write("Welcome to vb.net ")
Console.ReadLine()
End Sub
End Module
2)
Module Module1
Sub Main()
Console.WriteLine("Welcome to vb.net ")
Console.WriteLine("Thank you")
Console.ReadLine()
End Sub
End Module
3)
Module Module1
Sub Main()
Dim n As Integer
n = 10
Console.WriteLine("n")
Console.WriteLine(n)
Console.WriteLine("Value of N is " & n)
Console.ReadLine()
End Sub
End Module
4)
Module Module1
Sub Main()
Dim n As Integer
Console.Write("Enter N Value ")
n = Console.ReadLine()
Console.WriteLine("Value of N is " & n)
Console.ReadLine()
End Sub
End Module

5)
Module Module1
Sub Main()
Dim a, b, c As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a + b
Console.WriteLine("C")
Console.WriteLine(c)
Console.WriteLine("Sum of A and B is " & c)
Console.WriteLine("sum of " & a & " and " & b & " is " & c)
Console.WriteLine("Sum of {0} and {1} is {2} ", a, b, c)

Console.ReadLine()
End Sub
End Module
6)
Module Module1
Sub Main()
Dim a, b As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
Console.WriteLine("Sum
Console.WriteLine("Sub
Console.WriteLine("Mul
Console.WriteLine("Rem
Console.WriteLine("Cos
Console.WriteLine("Cos

Console.ReadLine()
End Sub
End Module
7)

of A
of A
of A
of A
/ of
\ of

and B
and B
and B
and B
A and
A and

is "
is "
is "
is "
B is
B is

&
&
&
&
"
"

a
a
a
a
&
&

+ b)
- b)
* b)
Mod b)
a / b)
a \ b)

Module Module1
Sub Main()
Dim sno, m1, m2, tot As Integer
Dim sname As String
Dim avg As Single
Console.Write("Enter Student Number
sno = Console.ReadLine
Console.Write("Enter Student Name
sname = Console.ReadLine
Console.Write("Enter Marks in Paper
m1 = Console.ReadLine
Console.Write("Enter Marks in Paper
m2 = Console.ReadLine

")
")
I ")
II ")

tot = m1 + m2
avg = tot / 2
Console.WriteLine("Total Marks
" & tot)
Console.WriteLine("Average Marks " & avg)
Console.ReadLine()
End Sub
End Module
Conditonal Statmetns
======================
Simple if
-------------if <condi> then
<Statements>
End if
if ... else
----------if <condi> then
<Statements>
else
<Statements>
End if
elseif
--------if <condi> then
<Statements>
elseif <condi> then
<Statements>
. . . .
[ else
<Statements> ]
End if

Nested if
------------if <condi> then
<Statements>
if <condi> then
<Statmetns>
else
<Statements>
End if
else
<Statements>
End if
1)
Module Module1
Sub Main()
Dim a, b As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
If a > b Then
Console.WriteLine("A is Big")
End If
Console.ReadLine()
End Sub
End Module
2)
Module Module1
Sub Main()
Dim a, b As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
If a > b Then
Console.WriteLine("A is Big")
Else
Console.WriteLine("B is Big")
End If
Console.ReadLine()
End Sub

End Module
3)
Module Module1
Sub Main()
Dim a, b As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine

If a = b Then
Console.WriteLine("Both are Equal ")
Else
Console.WriteLine("Both are Not equal")
End If
Console.ReadLine()
End Sub
End Module
4)
Module Module1
Sub Main()
Dim a, b, c As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
Console.Write("Enter Value of C ")
c = Console.ReadLine

If (a = b) And b = c Then
Console.WriteLine("All are Equal ")
Else
Console.WriteLine("Not equal")
End If
Console.ReadLine()
End Sub
End Module
5)
Module Module1
Sub Main()

Dim a, b, c As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
Console.Write("Enter Value of C ")
c = Console.ReadLine

If (a = b) Or b = c Or c = a Then
Console.WriteLine("Two Values are Equal ")
Else
Console.WriteLine("Not equal")
End If
Console.ReadLine()
End Sub
End Module
6)
Module Module1
Sub Main()
Dim a, b As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
If a > b Then
Console.WriteLine("A is Big")
ElseIf b > a Then
Console.WriteLine("B is Big")
Else
Console.WriteLine("Both are Equal")
End If
Console.ReadLine()
End Sub
End Module
7)
Module Module1
Sub Main()
Dim sno, m1, m2, tot As Integer
Dim sname, res, div As String
Dim avg As Single
Console.Write("Enter Student Number ")
sno = Console.ReadLine
Console.Write("Enter Student Name ")
sname = Console.ReadLine

Console.Write("Enter Marks in Paper I ")


m1 = Console.ReadLine
Console.Write("Enter Marks in Paper II ")
m2 = Console.ReadLine
tot = m1 + m2
avg = tot / 2
If m1 >= 35 And m2 >= 35 Then
res = "Pass"
If avg >= 60 Then
div = "First"
ElseIf avg >= 50 Then
div = "Second"
Else
div = "Third"
End If
Else
res = "Fail"
div = "No div"
End If
Console.WriteLine("Total Marks
Console.WriteLine("Average Marks
Console.WriteLine("Result
Console.WriteLine("Division

"
"
"
"

&
&
&
&

tot)
avg)
res)
div)

Console.ReadLine()
End Sub
End Module

=============================================================
Select Case
================
select case <expr>
case <expr>
<Statmetns>
case <expr>
<Statmetns>
case <expr>
<Statmetns>
.....
[ case else
<Statements> ]
End Select
1)
Module Module1
Sub Main()

Dim n As Integer
Console.Write("Enter Any Value between 1 to 5 ")
n = Console.ReadLine
Select Case n
Case 1
Console.WriteLine("One")
Case 2
Console.WriteLine("Two")
Case 3
Console.WriteLine("Three")
Case 4
Console.WriteLine("Four")
Case 5
Console.WriteLine("Five")
Case Else
Console.WriteLine("Out of Range ")
End Select
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Sub Main()
Dim n As Integer
Console.Write("Enter Any Value between 1 to 10 ")
n = Console.ReadLine
Select Case n
Case 1 To 10
Console.WriteLine("With in a Range")
Case Else
Console.WriteLine("Out of Range ")
End Select
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()

Dim n As Integer
Console.Write("Enter Any Value between 1 to 10 ")
n = Console.ReadLine
Select Case n
Case 2, 5, 8, 10
Console.WriteLine("With in a List")
Case Else
Console.WriteLine("Out of List ")
End Select
Console.ReadLine()
End Sub
End Module

4)
Module Module1
Sub Main()
Dim st As String
Console.Write("Enter Course ")
st = Console.ReadLine
Select Case st
Case "dca"
Console.WriteLine("Course
Case "pgdca"
Console.WriteLine("Course
Case "dtp"
Console.WriteLine("Course
Case Else
Console.WriteLine("Course
End Select

is Available ")
is Available ")
is Available ")
is not Available ")

Console.ReadLine()
End Sub
End Module

5)
Module Module1
Sub Main()
Dim st As String
Console.Write("Enter Course ")
st = Console.ReadLine
Select Case st
Case "dca", "pgdca", "dtp"
Console.WriteLine("Course is Available")

Case Else
Console.WriteLine("Course is not Available ")
End Select
Console.ReadLine()
End Sub
End Module

6)
Module Module1
Sub Main()
Dim avg As Single
Console.Write("Enter Average Marks ")
avg = Console.ReadLine
Select Case avg
Case Is >= 60
Console.WriteLine("First Class ")
Case Is >= 50
Console.WriteLine("Second Class ")
Case Is >= 35
Console.WriteLine("Third Class ")
Case Else
Console.WriteLine("No div")
End Select
Console.ReadLine()
End Sub
End Module

loops
========
while

do ..loops

for

=========================================================
while loop
---------------while <expr>
<Statments>
End While
1)
Module Module1
Sub Main()

Dim i As Integer
While i <= 10
Console.WriteLine("Welcome")
i = i + 1
End While
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Sub Main()
Dim i As Integer
i = 1
While i <= 10
Console.Write(i & Space(5))
i = i + 1
End While
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()
Dim i, n As Integer
Console.Write("Enter N Value ")
n = Console.ReadLine
i = 1
While i <= n
If i Mod 2 = 0 Then
Console.Write(i & Space(5))
End If
i = i + 1
End While
Console.ReadLine()
End Sub
End Module

4)
prime Number
---------7 3

Module Module1
Sub Main()
Dim i, n, c As Integer
Console.Write("Enter N Value ")
n = Console.ReadLine
i = 1
While i <= n
If n Mod i = 0 Then
c = c + 1
End If
i = i + 1
End While
If c = 2 Then
Console.WriteLine("It is Prime Number ")
Else
Console.WriteLine("It is not a Prime Number ")
End If
Console.ReadLine()
End Sub
End Module

8)
perfact
Module Module1
Sub Main()
Dim i, n, s As Integer
Console.Write("Enter N Value ")
n = Console.ReadLine
i = 1
While i < n
If n Mod i = 0 Then
s = s + i
End If
i = i + 1
End While
If s = n Then
Console.WriteLine("It is Perfact Number ")
Else
Console.WriteLine("It is not a Perfact Number ")
End If
Console.ReadLine()
End Sub
End Module

do....loops
==============
do while/until <expr>
<Statmets>
[ exit do]
<Stamtents>
loop
1)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do While i <= 10
Console.Write(i & Space(5))
i = i + 1
Loop
Console.ReadLine()
End Sub
End Module
2)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do While i <= 10
Console.Write(i & Space(5))
i = i + 1
If i > 5 Then
Exit Do
End If
Loop
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()
Dim i As Integer
i = 1

Do While i <= 10
Console.Write((i) & Space(5))
i = i + 1
If i > 5 Then
Exit Do
End If
Loop
Console.ReadLine()
End Sub
End Module

4)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do Until i > 10
Console.Write((i) & Space(5))
i = i + 1
Loop
Console.ReadLine()
End Sub
End Module

do
<statemetns>
[ exit do]
<Statments>
loop while/until <expr>
1)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do
Console.Write((i) & Space(5))
i = i + 1
Loop While i <= 10
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do
Console.Write((i) & Space(5))
i = i + 1
Loop While i > 10
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do
Console.Write((i) & Space(5))
i = i + 1
Loop Until i > 10
Console.ReadLine()
End Sub
End Module

4)
Module Module1
Sub Main()
Dim i As Integer
i = 1
Do
Console.Write((i) & Space(5))
i = i + 1
If i > 5 Then
Exit Do
End If
Loop Until i > 10
Console.ReadLine()
End Sub

End Module

for loop
=======
For <Var> As <Data type> = <Start Value > to <End Value> [ step value]
<Statmetns>
[ Exit for ]
<Statements>
Next
1)
Module Module1
Sub Main()
For i As Integer = 1 To 10 Step 1
Console.Write(i & Space(5))
Next
Console.ReadLine()
End Sub
End Module
2)
Module Module1
Sub Main()
Dim i As Integer
For i = 1 To 10
Console.Write(i & Space(5))
Next
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()
Dim i As Integer
For i = 1 To 10 Step 2
Console.Write(i & Space(5))

Next
Console.ReadLine()
End Sub
End Module

4)
Module Module1
Sub Main()
Dim i As Integer
For i = 10 To 1 Step -1
Console.Write(i & Space(5))
Next
Console.ReadLine()
End Sub
End Module

5)
Module Module1
Sub Main()
Dim i, n As Integer
Console.Write("Enter Table Number ")
n = Console.ReadLine
For i = 1 To 20
Console.WriteLine(n & "
Next
Console.ReadLine()
End Sub

End Module

========================================
array function
============
1)
Module Module1
Sub Main()
Dim a(5) As Integer

" & i & " = " & n * i)

Dim i As Integer
Console.WriteLine(" Array Lenght " & a.Length)
Console.WriteLine(" Starting Index " & a.GetLowerBound(0))
Console.WriteLine(" Ending Index " & a.GetUpperBound(0))
For i = 0 To 5
Console.Write("Enter any Value ")
a(i) = Console.ReadLine()
Next
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next
Console.ReadLine()
End Sub

End Module

2)
Module Module1
Sub Main()
Dim a(5) As Integer
Dim i As Integer
For i = 0 To 5
Console.Write("Enter any Value ")
a(i) = Console.ReadLine()
Next
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next
Array.Sort(a)
Console.WriteLine()
Console.WriteLine("After Sorting ")
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next
Console.ReadLine()
End Sub

End Module

3)
Module Module1
Sub Main()
Dim a(5) As Integer
Dim i As Integer
For i = 0 To 5
Console.Write("Enter any Value ")
a(i) = Console.ReadLine()
Next
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next
Array.Reverse(a)
Console.WriteLine()
Console.WriteLine("After Sorting ")
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next
Console.ReadLine()
End Sub

End Module

4)
Module Module1
Sub Main()
Dim a(5) As Integer
Dim i, ser, x As Integer
For i = 0 To 5
Console.Write("Enter any Value ")
a(i) = Console.ReadLine()
Next
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next

Console.WriteLine()
Console.Write("Enter Value for Search ")
ser = Console.ReadLine
x = Array.BinarySearch(a, ser)
If (x < 0) Then
Console.WriteLine(ser & " Vlaue is Not Found ")
Else
Console.WriteLine(ser & " Value is Found at " & x & " Location ")
End If

Console.ReadLine()
End Sub

End Module

5)
Module Module1
Sub Main()
Dim a(5) As Integer
Dim b(10) As Integer
Dim i As Integer
For i = 0 To 5
Console.Write("Enter any Value ")
a(i) = Console.ReadLine()
Next
For i = a.GetLowerBound(0) To a.GetUpperBound(0)
Console.Write(a(i) & Space(5))
Next
'Array.Copy(a, b, 3)
Array.Copy(a, 2, b, 5, 2)
Console.WriteLine()
Console.WriteLine("B Array ")
For i = b.GetLowerBound(0) To b.GetUpperBound(0)
Console.Write(b(i) & Space(5))
Next

Console.ReadLine()
End Sub

End Module
=========================================================
Functions
==========
public/private Function <Fun name>([ Argu List]) As <Return Type>
<Statements>
[ Exit Function ]
<Statements>
End Function

1)
Module Module1
Public Function sum(ByVal a As Integer, ByVal b As Integer) As Integer
Dim c As Integer
c = a + b
Return c
End Function
Sub Main()
Dim a, b, c As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = sum(a, b)
Console.WriteLine("Sum of A and B is

" & c)

Console.ReadLine()
End Sub

End Module

2) Function Overloading
Module Module1
Public Function sum(ByVal a As Integer, ByVal b As Integer) As Integer

Dim c As Integer
c = a + b
Return c
End Function
Public Function sum(ByVal a As Single, ByVal b As Single) As Single
Dim c As Single
c = a + b
Return c
End Function
Sub Main()
Dim a, b, c As Integer
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = sum(a, b)
Console.WriteLine("Sum of A and B is

" & c)

Console.ReadLine()
End Sub

End Module

3)
Module Module1
Sub Main()
Dim n, f As Integer
Console.Write("Enter Any Value ")
n = Console.ReadLine
f = fact(n)
Console.WriteLine(n & " Fact is

" & f)

Console.ReadLine()
End Sub
Public Function fact(ByVal n As Integer) As Integer
Dim f, i As Integer
f = 1
For i = 1 To n
f = f * i
Next
Return f

End Function

End Module

3)
Module Module1
Sub Main()
Dim n As Integer
Dim r As Boolean
Console.Write("Enter Any Value ")
n = Console.ReadLine
r = arm(n)
If r = True Then
Console.WriteLine("It is Armstrong ")
Else
Console.WriteLine("It is NOt an Armstong ")
End If
Console.ReadLine()
End Sub
Public Function arm(ByVal n As Integer) As Boolean
Dim d, r, t As Integer
t = n
While n > 0
d = n Mod 10
r = r + (d * d * d)
n = Int(n / 10)
End While
If t = r Then
Return True
Else
Return False
End If
End Function

End Module

Procedures
===========

public/private

sub <sub Name>( [ Argu List])

<Statements>
[ Exit Sub ]
<Statmetns>
End Sub

1)
Module Module1
Public Sub disp(ByVal st As String)
Console.WriteLine(st)
End Sub
Sub Main()
disp("Welcome")
disp("BDPS")
disp("Thank You")
Console.ReadLine()
End Sub

End Module

2) Call by Value
Module Module1
Public Sub swap(ByVal a As Integer, ByVal b As Integer)
Dim t As Integer
t = a
a = b
b = t
End Sub
Sub Main()
Dim a, b As Integer
a = 10
b = 20
Console.WriteLine("Value of A is " & a)
Console.WriteLine("Value of B is " & b)
swap(a, b)
Console.WriteLine("After Swaping ")
Console.WriteLine("Value of A is " & a)
Console.WriteLine("Value of B is " & b)
Console.ReadLine()
End Sub

End Module

3) Call by Referance
Module Module1
Public Sub swap(ByRef a As Integer, ByRef b As Integer)
Dim t As Integer
t = a
a = b
b = t
End Sub
Sub Main()
Dim a, b As Integer
a = 10
b = 20
Console.WriteLine("Value of A is " & a)
Console.WriteLine("Value of B is " & b)
swap(a, b)
Console.WriteLine("After Swaping ")
Console.WriteLine("Value of A is " & a)
Console.WriteLine("Value of B is " & b)
Console.ReadLine()
End Sub

End Module

=========================================================
String Functions
================
1) Trim Functions
===============
Module Module1
Sub Main()
Dim st1, st2 As String
st1 = "
WELCOME
st2 = "BDPS"

"

Console.WriteLine(st1 + st2)
Console.WriteLine(LTrim(st1) + st2)
Console.WriteLine(RTrim(st1) + st2)
Console.WriteLine(Trim(st1) + st2)

Console.ReadLine()
End Sub
End Module

Case Converseion
===============
Module Module1
Sub Main()
Dim st1, st2 As String
st1 = "welcome"
st2 = "BDPS"
'Console.WriteLine(UCase(st1))
'Console.WriteLine(LCase(st2))
Console.WriteLine(st1.ToUpper)
Console.WriteLine(st2.ToLower)
Console.ReadLine()
End Sub
End Module
3)
Module Module1
Sub Main()
Dim st As String
st = "welcome"
Console.WriteLine(st)
Console.WriteLine(Left(st, 3))
Console.WriteLine(Right(st, 4))
Console.WriteLine(Mid(st, 3))
Console.WriteLine(Mid(st, 3, 3))
Console.ReadLine()
End Sub
End Module

4)
BDPS
B
BD
BDP
BDPS

Module Module1
Sub Main()
Dim st As String
Dim i As Integer
Console.Write("Enter Any String ")
st = Console.ReadLine
For i = 1 To st.Length
Console.WriteLine(Left(st, i))
Next
Console.ReadLine()
End Sub
End Module

5)
BDPS
B
D
P
S
Module Module1
Sub Main()
Dim st As String
Dim i As Integer
Console.Write("Enter Any String ")
st = Console.ReadLine
For i = 1 To st.Length
Console.WriteLine(Mid(st, i, 1))
Next
Console.ReadLine()
End Sub
End Module

5)
BDPS
S
PS
DPS
BDPS
Module Module1
Sub Main()

Dim st As String
Dim i As Integer
Console.Write("Enter Any String ")
st = Console.ReadLine
For i = 1 To st.Length
Console.WriteLine(Right(st, i))
Next
Console.ReadLine()
End Sub
End Module

6)
BDPS
S
SP
SPD
SPDB
Module Module1
Sub Main()
Dim st, st1 As String
Dim i, L As Integer
Console.Write("Enter Any String ")
st = Console.ReadLine
st1 = " "
L = st.Length
For i = 1 To st.Length
st1 = st1 + Mid(st, L, 1)
L = L - 1
Console.WriteLine(Right(st1, i))
Next
Console.ReadLine()
End Sub
End Module

7) Reverse String
Module Module1
Sub Main()
Dim st, st1 As String
Dim i, L As Integer
Console.Write("Enter Any String ")
st = Console.ReadLine
st1 = " "

L = st.Length
For i = 1 To st.Length
st1 = st1 + Mid(st, L, 1)
L = L - 1
Next
Console.WriteLine(Right(st1, i))
Console.ReadLine()
End Sub
End Module

8) Palandrom string
Module Module1
Sub Main()
Dim st, st1 As String
Dim i, L As Integer
Console.Write("Enter Any String ")
st = Console.ReadLine
st1 = " "
L = st.Length
For i = 1 To st.Length
st1 = st1 + Mid(st, L, 1)
L = L - 1
Next
If Trim(st1).ToUpper = Trim(st).ToUpper Then
Console.WriteLine("It is Palandrom ")
Else
Console.WriteLine("It is not a Palanrom ")
End If
Console.ReadLine()
End Sub
End Module

==========================================================
Number Functions
=================
Module Module1
Sub Main()
Console.WriteLine(Math.Abs(-12))
Console.WriteLine(Math.Max(10, 20))
Console.WriteLine(Math.Min(10, 222))
Console.WriteLine(Math.Pow(10, 2))
Console.WriteLine(Math.Floor(10.9))
Console.WriteLine(Math.Ceiling(10.1))
Console.WriteLine(Math.Round(10.5))
Console.WriteLine(Math.Round(10.6))
Console.WriteLine(Math.Sqrt(20))

Console.WriteLine(Math.Cos(0))
Console.WriteLine(Math.Tan(0))
Console.WriteLine(Math.Log(10))
Console.ReadLine()
End Sub
End Module

Date and Time Functions


=====================
Module Module1
Sub Main()
Console.WriteLine(Now)
Console.WriteLine(Now.Date)
Console.WriteLine(Now.ToLongDateString)
Console.WriteLine(Now.ToShortDateString)
Console.WriteLine(Now.Day)
Console.WriteLine(Now.Month)
Console.WriteLine(Now.Year)
Console.WriteLine(Now.ToLongTimeString)
Console.WriteLine(Now.ToShortTimeString)
Console.WriteLine(Now.Hour)
Console.WriteLine(Now.Minute)
Console.WriteLine(Now.Second)

Console.ReadLine()
End Sub
End Module

2)
Module Module1
Sub Main()
Console.WriteLine(Now)
Console.WriteLine(Now.AddDays(10))
Console.WriteLine(Now.AddMonths(5))
Console.WriteLine(Now.AddYears(5))
Console.WriteLine(Now.AddHours(10))
Console.WriteLine(Now.AddMinutes(5))
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()

Console.WriteLine(Format(Now.Date,
Console.WriteLine(Format(Now.Date,
Console.WriteLine(Format(Now.Date,
Console.WriteLine(Format(Now.Date,

"d-MM-yy"))
"dd-MM-yy"))
"ddd-MM-yy"))
"dddd-MM-yy"))

Console.WriteLine(Format(Now.Date, "dd-MMM-yy"))
Console.WriteLine(Format(Now.Date, "dd-MMMM-yy"))
Console.WriteLine(Format(Now.Date, "dd-MM-yyyy"))
Console.WriteLine(Now.ToLongDateString)
Console.WriteLine(Format(Now.Date, "dddd, MMM dd, yyyy"))
Console.ReadLine()
End Sub
End Module

4)
Module Module1
Sub Main()
Dim d1, d2 As Date
d1 = Now.Date
d2 = "10-10-2000"
Console.WriteLine(DateDiff(DateInterval.Year, d2, d1))
Console.WriteLine(DateDiff(DateInterval.Month, d2, d1))
Console.WriteLine(DateDiff(DateInterval.Day, d2, d1))
Console.WriteLine(DateDiff(DateInterval.Hour, d2, d1))
Console.WriteLine(DateDiff(DateInterval.Minute, d2, d1))
Console.WriteLine(DateDiff(DateInterval.Second, d2, d1))
Console.ReadLine()
End Sub
End Module

ooops
=====
1)
Module Module1
Class Emp
Public eno As Integer
Public ename As String
Public esal As Single
End Class
Sub Main()
Dim e As New Emp
e.eno = 111
e.ename = "Nikil"
e.esal = 10000

Console.WriteLine("EMP NUMBER
Console.WriteLine("EMP NAME
Console.WriteLine("EMP SALARY

" & e.eno)


" & e.ename)
" & e.esal)

Console.ReadLine()
End Sub
End Module

2)
Module Module1
Class Emp
Private eno As Integer
Private ename As String
Private esal As Single
Public Sub getEmp()
Console.Write("Enter Emp Number
eno = Console.ReadLine
Console.Write("Enter Emp Name
ename = Console.ReadLine
Console.Write("Enter Emp Salary
esal = Console.ReadLine
End Sub
Public Sub dispEmp()
Console.WriteLine("EMP NUMBER
Console.WriteLine("EMP NAME
Console.WriteLine("EMP SALARY
End Sub
End Class
Sub Main()
Dim e As New Emp
e.getEmp()
e.dispEmp()
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Class Emp
Public eno As Integer
Public ename As String
Private eage As Integer
Private esal As Single

")
")
")

" & eno)


" & ename)
" & esal)

Public Sub
eage =
End Sub
Public Sub
esal =
End Sub

empAge(ByVal age As Integer)


age
empSal(ByVal sal As Single)
sal

Public Sub dispEmp()


Console.WriteLine("EMP
Console.WriteLine("EMP
Console.WriteLine("EMP
Console.WriteLine("EMP

NUMBER
NAME
AGE
SALARY

"
"
"
"

&
&
&
&

eno)
ename)
eage)
esal)

End Sub
End Class
Sub Main()
Dim e As New Emp
e.eno = 111
e.ename = "Nikil"
e.empAge(20)
e.empSal(20000)

e.dispEmp()
Console.ReadLine()
End Sub
End Module

4) Passing the Objects as a Argumnets


Module Module1
Class Test
Private n As Integer
Public Sub getData()
Console.Write("Enter Number ")
n = Console.ReadLine
End Sub
Public Sub dispData()
Console.WriteLine("Value of N is " & n)
End Sub
Public Sub sum(ByVal t1 As Test, ByVal t2 As Test)
n = t1.n + t2.n
End Sub
End Class
Sub Main()
Dim t1 As New Test

Dim t2 As New Test


Dim t3 As New Test
t1.getData()
t2.getData()
t1.dispData()
t2.dispData()
t3.sum(t1, t2)
t3.dispData()

Console.ReadLine()
End Sub
End Module
5) Passing and Returning the Objects
Module Module1
Class Test
Private n As Integer
Public Sub getData()
Console.Write("Enter Number ")
n = Console.ReadLine
End Sub
Public Sub dispData()
Console.WriteLine("Value of N is " & n)
End Sub
Public Function sum(ByVal t2 As Test) As Test
Dim t3 As New Test
t3.n = n + t2.n
Return t3
End Function
End Class
Sub Main()
Dim t1 As New Test
Dim t2 As New Test
Dim t3 As New Test
t1.getData()
t2.getData()
t1.dispData()
t2.dispData()
t3 = t1.sum(t2)

t3.dispData()

Console.ReadLine()
End Sub
End Module

=============================================================
Constructors
===============
It is a Method, but is a special Mehtod because it has some special chararcter
s :
->
The Constructr Name is NEW
Keyword
->
It must be Procedure ( SUB)
->
It must be in Public by default it is in ublic
- >
The arguments are optional
->
It excutes automatically when we allocate the memory to thte Object.
Note : The Constructor usually used for Initialiation purpose
1)
Module Module1
Class Demo
Public n As Integer
Sub New()
n = 100
Console.WriteLine("Value of N is " & n)
End Sub
End Class
Sub Main()
Dim d As New Demo
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Class Emp
Private eno As Integer
Private ename As String
Private esal As Single
Sub New()

eno = 111
ename = "aaa"
esal = 10000
End Sub
Public Sub empData()
Console.WriteLine("Emp Number
Console.WriteLine("Emp Name
Console.WriteLine("Emp Salary
End Sub
End Class
Sub Main()

" & eno)


" & ename)
" & esal)

Dim e As New Emp


e.empData()
Console.ReadLine()
End Sub
End Module

3)
Module Module1
Class Emp
Private eno As Integer
Private ename As String
Private esal As Single
Sub New(ByVal no As Integer, ByVal
eno = no
ename = name
esal = sal
End Sub
Public Sub empData()
Console.WriteLine("Emp Number
Console.WriteLine("Emp Name
Console.WriteLine("Emp Salary
End Sub
End Class
Sub Main()

name As String, ByVal sal As Single)

Dim e1 As New Emp(111, "aaa", 10000)


Dim e2 As New Emp(222, "bbb", 20000)
Dim e3 As New Emp(333, "ccc", 30000)

" & eno)


" & ename)
" & esal)

e1.empData()
e2.empData()
e3.empData()
Console.ReadLine()
End Sub
End Module

4)
Module Module1

Class Emp
Private eno As Integer
Private ename As String
Private esal As Single
Sub New(ByVal eno As Integer, ByVal ename As String, ByVal esal As Singl
e)
Me.eno = eno
Me.ename = ename
Me.esal = esal
End Sub
Public Sub empData()
Console.WriteLine("Emp Number
Console.WriteLine("Emp Name
Console.WriteLine("Emp Salary
End Sub
End Class
Sub Main()

" & eno)


" & ename)
" & esal)

Dim e1 As New Emp(111, "aaa", 10000)


Dim e2 As New Emp(222, "bbb", 20000)
Dim e3 As New Emp(333, "ccc", 30000)
e1.empData()
e2.empData()
e3.empData()
Console.ReadLine()
End Sub
End Module

5)
Module Module1
Class Emp
Private eno As Integer
Private ename As String
Private esal As Single
Public Sub New()
eno = 111
ename = "aaa"
esal = 10000
End Sub
Public Sub New(ByVal no As Integer)
eno = no
ename = "bbb"
esal = 20000
End Sub
Public Sub New(ByVal no As Integer, ByVal name As String)
eno = no
ename = name
esal = 30000
End Sub
Sub New(ByVal eno As Integer, ByVal ename As String, ByVal esal As Singl
e)
Me.eno = eno

Me.ename = ename
Me.esal = esal
End Sub
Public Sub empData()
Console.WriteLine("Emp Number
Console.WriteLine("Emp Name
Console.WriteLine("Emp Salary
End Sub
End Class
Sub Main()
Dim
Dim
Dim
Dim

e1
e2
e3
e4

As
As
As
As

New
New
New
New

" & eno)


" & ename)
" & esal)

Emp()
Emp(222)
Emp(333, "ccc")
Emp(444, "ddd", 4000)

e1.empData()
e2.empData()
e3.empData()
e4.empData()
Console.ReadLine()
End Sub
End Module

Destructor
===============
Module Module1
Class Demo
Private n As Integer
Sub New()
n = 1000
Console.WriteLine("Value of N is " & n)
End Sub
Protected Overrides Sub finalize()
n = 0
Console.WriteLine("Value of N is " & n)
End Sub
End Class
Sub Main()
Dim d As New Demo
Console.ReadLine()
End Sub
End Module

Shared Data members (Static Data Memsbers)


==================================
-> The Shared Data Members can access without an object,thought the class Name

-> The Shard Data members con't be allocate memory to the object, but it alloca
te only one copy of memory to all the object, that memory we can share all the o
bjects.

1)
Module Module1
Class Emp
Public Shared eno As Integer
Public Shared ename As String
Public Shared esal As Single
End Class
Sub Main()
Emp.eno = 111
Emp.ename = "Nikil"
Emp.esal = 10000
Console.WriteLine("Emp Number " & Emp.eno)
Console.WriteLine("Emp Name
" & Emp.ename)
Console.WriteLine("Emp Salary " & Emp.esal)

Console.ReadLine()
End Sub
End Module

2)
Module Module1
Class Test
Private Shared n As Integer
Public Sub getData()
Console.Write("Enter N Vaue ")
n = Console.ReadLine
End Sub
Public Sub dispData()
Console.WriteLine("VALUE OF N IS " & n)
End Sub
End Class
Sub Main()
Dim t1 As New Test
Dim t2 As New Test
Dim t3 As New Test
t1.getData()
t2.getData()
t3.getData()

t1.dispData()
t2.dispData()
t3.dispData()

Console.ReadLine()
End Sub
End Module

3)
Module Module1
Class Emp
Private
Private
Private
Private

eno As Integer
ename As String
esal As Single
Shared rno As Integer

Public Sub getEmp()


rno = rno + 1
Console.WriteLine("Record Number " & rno)
Console.Write("Enter Emp Number ")
eno = Console.ReadLine
Console.Write("Enter Emp Name
")
ename = Console.ReadLine
Console.Write("Enter Emp Salary ")
esal = Console.ReadLine
End Sub
Public Sub dispEmp()
Console.WriteLine("EMP NUMBER " & eno)
Console.WriteLine("EMP NAME
" & ename)
Console.WriteLine("EMP SALARY " & esal)
End Sub
End Class
Sub Main()
Dim e1 As New Emp
Dim e2 As New Emp
Dim e3 As New Emp
e1.getEmp()
e2.getEmp()
e3.getEmp()
e1.dispEmp()
e2.dispEmp()
e3.dispEmp()

Console.ReadLine()
End Sub
End Module
Static Member Functions
=====================
-> The Shared Method can access only those are Shared Fileds.
-> The Shared Method can access without an object through the class Name
-> if we wat to access the non shared fields in shared method the object refera
nce
shoud be needed.
1)
Module Module1
Class Demo
Private Shared x As Integer
Public Shared Sub demoData()
Console.Write("Enter Value of X ")
x = Console.ReadLine
Console.WriteLine("Value of x is " & x)
End Sub
End Class
Sub Main()
Dim d As New Demo
d.demoData()
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Class Demo
Private x As Integer
Public Shared Sub demoData()
Dim d As New Demo
Console.Write("Enter Value of X ")
d.x = Console.ReadLine
Console.WriteLine("Value of x is " & d.x)
End Sub
End Class
Sub Main()
Demo.demoData()
Console.ReadLine()
End Sub

End Module

3)
Module Module1
Class Demo
Private x As Integer
Public Shared Function getData() As Demo
Dim d As New Demo
Console.Write("Enter Value of X ")
d.x = Console.ReadLine
Return d
End Function
Public Shared Sub dispData(ByVal d As Demo)
Console.WriteLine("Value of x is " & d.x)
End Sub
End Class
Sub Main()
Dim d As New Demo
d = Demo.getData()
Demo.dispData(d)
Console.ReadLine()
End Sub
End Module
Inheritance
============
1)
Module Module1
Class Stud
Private sno As Integer
Private sname As String
Public Sub getStud()
Console.Write("Enter Student Number
sno = Console.ReadLine
Console.Write("Enter Sudent Name
sname = Console.ReadLine
End Sub
Public Sub dispStud()
Console.WriteLine("STUDENT NUMBER
Console.WriteLine("STUDENT NAME
End Sub
End Class
Class Marks
Inherits Stud

")
")

" & sno)


" & sname)

Private m1 As Integer
Private m2 As Integer
Public Sub getMarks()
getStud()
Console.Write("Enter Marks in Paper I
m1 = Console.ReadLine
Console.Write("Enter Marks in Paper II
m2 = Console.ReadLine
End Sub
Public Sub dispMarks()
dispStud()
Console.WriteLine("MARKS IN PAPER I "
Console.WriteLine("MARKS IN PAPER II "
End Sub
End Class

")
")

& m1)
& m2)

Sub Main()
Dim M As New Marks
M.getMarks()
M.dispMarks()
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Class Stud
Private sno As Integer
Private sname As String
Public Sub getStud()
Console.Write("Enter Student Number
sno = Console.ReadLine
Console.Write("Enter Sudent Name
sname = Console.ReadLine
End Sub
Public Sub dispStud()
Console.WriteLine("STUDENT NUMBER
Console.WriteLine("STUDENT NAME
End Sub
End Class

")
")

" & sno)


" & sname)

Class Marks
Inherits Stud
Protected m1 As Integer
Protected m2 As Integer
Public Sub getMarks()
getStud()
Console.Write("Enter Marks in Paper I ")
m1 = Console.ReadLine
Console.Write("Enter Marks in Paper II ")
m2 = Console.ReadLine
End Sub
Public Sub dispMarks()

dispStud()
Console.WriteLine("MARKS IN PAPER I " & m1)
Console.WriteLine("MARKS IN PAPER II " & m2)
End Sub
End Class
Class Result
Inherits Marks
Private tot As Integer
Private avg As Single
Public Sub getRes()
getMarks()
tot = m1 + m2
avg = tot / 2
End Sub
Public Sub dispRes()
dispMarks()
Console.WriteLine("TOTAL MARKS " & tot)
Console.WriteLine("AVERAGE MARKS " & avg)
End Sub
End Class
Sub Main()
Dim r As New Result
r.getRes()
r.dispRes()
Console.ReadLine()
End Sub
End Module
3)
Basec class
Stud
Der1
Ec

Der2
Cs

Der3
It

Module Module1
Class Stud
Private sno As Integer
Private sname As String
Public Sub getStud()
Console.Write("Enter Student Number
sno = Console.ReadLine
Console.Write("Enter Sudent Name
sname = Console.ReadLine
End Sub
Public Sub dispStud()
Console.WriteLine("STUDENT NUMBER
Console.WriteLine("STUDENT NAME
End Sub
End Class

")
")

" & sno)


" & sname)

Class Ec
Inherits Stud
Private ec1, ec2 As Integer
Public Sub getEc()
getStud()
Console.Write("Enter Marks in Ec Paper I ")
ec1 = Console.ReadLine
Console.Write("Enter Marks in Ec Paper II ")
ec2 = Console.ReadLine
End Sub
Public Sub dispEc()
dispStud()
Console.WriteLine("MARKS IN EC PAPER I " & ec1)
Console.WriteLine("MARKS IN EC PAPER II " & ec2)
End Sub
End Class
Class Cs
Inherits Stud
Private cs1, cs2 As Integer
Public Sub getCs()
getStud()
Console.Write("Enter Marks in Cs Paper I ")
cs1 = Console.ReadLine
Console.Write("Enter Marks in Cs Paper II ")
cs2 = Console.ReadLine
End Sub
Public Sub dispCs()
dispStud()
Console.WriteLine("MARKS IN CS PAPER I " & cs1)
Console.WriteLine("MARKS IN CS PAPER II " & cs2)
End Sub
End Class
Class It
Inherits Stud
Private it1, it2 As Integer
Public Sub getIt()
getStud()
Console.Write("Enter Marks in It Paper I ")
it1 = Console.ReadLine
Console.Write("Enter Marks in It Paper II ")
it2 = Console.ReadLine
End Sub
Public Sub dispIt()
dispStud()
Console.WriteLine("MARKS IN IT PAPER I " & it1)
Console.WriteLine("MARKS IN IT PAPER II " & it2)
End Sub
End Class
Sub Main()
Dim ch As Integer
Do
Console.Clear()
Console.WriteLine("[1]. EC ")

Console.WriteLine("[2]. CS ")
Console.WriteLine("[3]. IT ")
Console.WriteLine("[4]. EXIT ")
Console.Write("Enter Your Choice..... ")
ch = Console.ReadLine
Select Case ch
Case 1
Dim e As New Ec
e.getEc()
e.dispEc()
Case 2
Dim c As New Cs
c.getCs()
c.dispCs()
Case 3
Dim i As New It
i.getIt()
i.dispIt()
End Select
Console.ReadLine()
Loop While ch <> 4

End Sub
End Module

Constructors Fireing in Inheritance


============================
Module Module1
Class A
Sub New()
Console.WriteLine("This is Class A constructor ")
End Sub
End Class
Class B
Inherits A
Sub New()
Console.WriteLine("This is class B Constructor ")
End Sub
End Class
Class C
Inherits B
Sub New()
Console.WriteLine("This is Class C Constructor ")
End Sub
End Class
Sub Main()
Dim c As New C

Console.ReadLine()
End Sub
End Module

Paramater Passing to the constructor in Inheritance


=========================================
Module Module1
Class A
Dim x As Integer
Sub New(ByVal p As Integer)
x = p
Console.WriteLine("This
End Sub
End Class
Class B
Inherits A
Dim y As Integer
Sub New(ByVal p As Integer,
MyBase.New(p)
y = q
Console.WriteLine("This
End Sub
End Class
Class C
Inherits B
Dim z As Integer
Sub New(ByVal p As Integer,
MyBase.New(p, q)
z = r
Console.WriteLine("This
End Sub
End Class
Sub Main()
Dim c As New C(10, 20, 30)
Console.ReadLine()
End Sub
End Module

Destructrs Firing in Inheritance


=============================
Module Module1
Class A
Dim x As Integer
Sub New(ByVal p As Integer)

is Class A constructor " & x)

ByVal q As Integer)
is class B Constructor " & y)

ByVal q As Integer, ByVal r As Integer)


is Class C Constructor " & z)

x = p
Console.WriteLine("This is Class A
End Sub
Protected Overrides Sub finalize()
Console.WriteLine("This is Class A
End Sub
End Class
Class B
Inherits A
Dim y As Integer
Sub New(ByVal p As Integer, ByVal q As
MyBase.New(p)
y = q
Console.WriteLine("This is class B
End Sub
Protected Overrides Sub finalize()
MyBase.finalize()
Console.WriteLine("This is Class B
End Sub

constructor " & x)


Detructor ")

Integer)
Constructor " & y)

Detructor ")

End Class
Class C
Inherits B
Dim z As Integer
Sub New(ByVal p As Integer, ByVal q As Integer, ByVal r As Integer)
MyBase.New(p, q)
z = r
Console.WriteLine("This is Class C Constructor " & z)
End Sub
Protected Overrides Sub finalize()
MyBase.finalize()
Console.WriteLine("This is Class C Detructor ")
End Sub
End Class
Sub Main()
Dim c As New C(10, 20, 30)
Console.ReadLine()
End Sub
End Module
Creation of the Namespace
=======================
1)
Imports ConsoleApplication1.Collage
Imports ConsoleApplication1.Collage.Staff
Namespace Collage
Class Stud
Public Sub studData()
Console.WriteLine("Student Class Method ")
End Sub
End Class

Class Library
Public Sub libData()
Console.WriteLine("This is Library Class Method ")
End Sub
End Class
Namespace Staff
Class Teaching
Public Sub teachData()
Console.WriteLine("This is Teaching Class Method ")
End Sub
End Class
Class Nonteaching
Public Sub nonteachData()
Console.WriteLine("This is Non teaching Class Method")
End Sub
End Class
End Namespace
End Namespace
Module Module1
Sub Main()
'Dim
'Dim
'Dim
'Dim
Dim
Dim
Dim
Dim

s
l
t
n
s
l
t
n

As
As
As
As
As
As
As
As

New
New
New
New
New
New
New
New

Collage.Stud
Collage.Library
Collage.Staff.Teaching
Collage.Staff.Nonteaching
Stud
Library
Teaching
Nonteaching

s.studData()
l.libData()
t.teachData()
n.nonteachData()

Console.ReadLine()
End Sub
End Module
creation of the Propertys
====================

Module Module1
Class Emp
Public eno As Integer
Public ename As String
Private eage As Integer

Private esal As Single


Public Property empAge()
Get
Return eage
End Get
Set(ByVal value)
eage = value
End Set
End Property
Public Property empSal()
Get
Return esal
End Get
Set(ByVal value)
esal = value
End Set
End Property
Public Sub empData()
Console.WriteLine("EMP NUMBER
Console.WriteLine("EMP NAME
Console.WriteLine("EMP SALARY
End Sub
End Class
Sub Main()
Dim e As New Emp
e.eno = 111
e.ename = "Nikil"
e.empAge = 20
e.empSal = 20000
e.empData()

Console.ReadLine()
End Sub
End Module

Poly
====
Function Overloading
-------------------------Module Module1
Public Sub disp(ByVal a As Integer)
Console.WriteLine(a)
End Sub
Public Sub disp(ByVal a As String)
Console.WriteLine(a)
End Sub
Public Sub disp(ByVal a As Single)
Console.WriteLine(a)
End Sub

" & eno)


" & ename)
" & esal)

Sub Main()
disp(10)
disp("A")
disp(50.5F)
disp("BDPS")
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Class One
Public Sub disp()
Console.WriteLine("This is Class One Disp Method ")
End Sub
End Class
Class Two
Inherits One
Public Sub disp()
MyBase.disp()
Console.WriteLine("This is Class Two Disp Method ")
End Sub
End Class
Sub Main()
Dim t As New Two
t.disp()

Console.ReadLine()
End Sub
End Module
3)
Module Module1
Class Ho
Public Overridable Sub Income()
Console.WriteLine("This is Ho Class Income Method ")
End Sub
End Class
Class Branch1
Inherits Ho
Public Overrides Sub Income()
Console.WriteLine("This is Branch1 Class Income Method ")
End Sub
End Class
Class Branch2
Inherits Ho

Public Overrides Sub Income()


Console.WriteLine("This is Branch2 Class Income Method ")
End Sub
End Class
Class Branch3
Inherits Ho
Public Overrides Sub Income()
Console.WriteLine("This is Branch3 Class Income Method ")
End Sub
End Class
Sub Main()
'Dim
'Dim
'Dim
'Dim

h As New Ho
b1 As New Branch1
b2 As New Branch2
b3 As New Branch3

'h.Income()
'b1.Income()
'b2.Income()
'b3.Income()
Dim
Dim
Dim
Dim
Dim

h As Ho
b1 As New Branch1
b2 As New Branch2
b3 As New Branch3
x As New Ho

x.Income()
h = b1
h.Income()
h = b2
h.Income()
h = b3
h.Income()

Console.ReadLine()
End Sub
End Module

mustInherit
==========
Module Module1
MustInherit Class One
Public Sub oneData()
Console.WriteLine("This is Class One Income Method ")
End Sub

End Class
Class Two
Inherits One
Public Sub twoData()
Console.WriteLine("This is Class Two Income Method ")
End Sub
End Class
Sub Main()
Dim t As New Two
t.oneData()
t.twoData()

Console.ReadLine()
End Sub
End Module

Notinheritable
==============
Module Module1
Class One
Public Sub oneData()
Console.WriteLine("This is Class One Income Method ")
End Sub
End Class
NotInheritable Class Two
Inherits One
Public Sub twoData()
Console.WriteLine("This is Class Two Income Method ")
End Sub
End Class
Class Three
Inherits Two
Public Sub threeData()
Console.WriteLine("This is Class Three Income Method")
End Sub
End Class
Sub Main()
Dim t As New Three
t.oneData()
t.twoData()
t.threeData()
Console.ReadLine()
End Sub
End Module
Error Haindling
=============

On Error ResumeNext
==================
Module Module1
Sub Main()
On Error Resume Next
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result

: " & c)

Console.WriteLine("Thank YOu")
Console.ReadLine()
End Sub
End Module

2)
Module Module1
Sub Main()
On Error GoTo One
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result

: " & c)

Console.WriteLine("Thank YOu")
Console.ReadLine()
Exit Sub
one:
Console.WriteLine(" Error " & Err.Description)

Console.ReadLine()
End Sub

End Module

Exception Handling
=================
Try
<Body of the Program>
Catch <Class Name <Object>
<Exception Statements>
Catch <Class Name <Object>
<Exception Statements>
. . . ..
[ Finally
<Final Statmetns> ]
End Try

1)
Module Module1
Sub Main()
Try
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result

: " & c)

Catch ex As DivideByZeroException
Console.WriteLine(ex.Message)
End Try

Console.ReadLine()
End Sub
End Module

2)

Module Module1
Sub Main()
Try
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result

: " & c)

Catch ex As InvalidCastException
Console.WriteLine(ex.Message)
End Try

Console.ReadLine()
End Sub
End Module

3)
Module Module1
Sub Main()
Try
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result

: " & c)

Catch ex As OverflowException
Console.WriteLine(ex.ToString)

End Try

Console.ReadLine()
End Sub

End Module

4)
Module Module1
Sub Main()
Try
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result

: " & c)

Catch ex As OverflowException
Console.WriteLine(ex.ToString)
Catch ex As DivideByZeroException
Console.WriteLine(ex.Message)
Catch ex As InvalidCastException
Console.WriteLine(ex.Message)
End Try

Console.ReadLine()
End Sub
End Module

5)
Module Module1
Sub Main()
Try
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result
Catch ex As Exception

: " & c)

Console.WriteLine(ex.Message)
End Try

Console.ReadLine()
End Sub
End Module
6)
Module Module1
Sub Main()
Try
Dim a, b, c As Integer
c = 300
Console.Write("Enter Value of A ")
a = Console.ReadLine
Console.Write("Enter Value of B ")
b = Console.ReadLine
c = a \ b
Console.WriteLine("Result : " & c)
Catch ex As OverflowException
Console.WriteLine(ex.ToString)
Catch ex As DivideByZeroException
Console.WriteLine(ex.Message)
Catch ex As InvalidCastException
Console.WriteLine(ex.Message)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
Console.WriteLine("Thank You")
End Try
Console.ReadLine()
End Sub
End Module

User Defined Exception


=======================
Module Module1
Class MyException
Inherits Exception
Sub New(ByVal msg As String)
MyBase.New(msg)
End Sub
End Class
Sub Main()

Try
Dim n As Integer
Console.Write("Enter N Value ")
n = Console.ReadLine
If n > 10000 Then
Throw New MyException("Value must be <=10000")
End If
Console.WriteLine("VALUE OF N IS " & n)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadLine()
End Sub
End Module

Multy threading
=============
1)
Module Module1
Public Sub fun1()
Dim i As Integer
For i = 1 To 250
Console.Write("A")
Next
End Sub
Public Sub fun2()
Dim j As Integer
For j = 1 To 250
Console.Write("B")
Next
End Sub
Public Sub fun3()
Dim k As Integer
For k = 1 To 250
Console.Write("C")
Next
End Sub
Sub Main()
Dim t1 As New System.Threading.Thread(AddressOf fun1)
Dim t2 As New System.Threading.Thread(AddressOf fun2)
Dim t3 As New System.Threading.Thread(AddressOf fun3)
t1.Start()

t2.Start()
t3.Start()
Console.ReadLine()
End Sub
End Module
2) sleep
Imports System.Threading
Module Module1
Dim t1 As Thread
Dim t2 As Thread
Dim t3 As Thread
Public Sub fun1()
Dim i As Integer
t1.Sleep(1000)
For i = 1 To 250
Console.Write("A")
Next
End Sub
Public Sub fun2()
Dim j As Integer
t2.Sleep(500)
For j = 1 To 250
Console.Write("B")
Next
End Sub
Public Sub fun3()
Dim k As Integer
For k = 1 To 250
Console.Write("C")
Next
End Sub
Sub Main()
t1 = New Thread(AddressOf fun1)
t2 = New Thread(AddressOf fun2)
t3 = New Thread(AddressOf fun3)
t1.Start()
t2.Start()
t3.Start()
Console.ReadLine()
End Sub
End Module

3) Join

Imports System.Threading
Module Module1
Dim t1 As Thread
Dim t2 As Thread
Dim t3 As Thread
Public Sub fun1()
Dim i As Integer
For i = 1 To 250
Console.Write("A")
Next
End Sub
Public Sub fun2()
Dim j As Integer
t3.Join()
For j = 1 To 250
Console.Write("B")
Next
End Sub
Public Sub fun3()
Dim k As Integer
For k = 1 To 250
Console.Write("C")
Next
End Sub
Sub Main()
t1 = New Thread(AddressOf fun1)
t2 = New Thread(AddressOf fun2)
t3 = New Thread(AddressOf fun3)
t1.Start()
t2.Start()
t3.Start()
Console.ReadLine()
End Sub
End Module

4)
Imports System.Threading
Module Module1
Dim t1 As Thread
Dim t2 As Thread
Dim t3 As Thread
Public Sub fun1()
Dim i As Integer
For i = 1 To 250

Console.Write("A")
Next
End Sub
Public Sub fun2()
Dim j As Integer
For j = 1 To 250
Console.Write("B")
Next
End Sub
Public Sub fun3()
Dim k As Integer
t2.Abort()
For k = 1 To 250
Console.Write("C")
Next
End Sub
Sub Main()
t1 = New Thread(AddressOf fun1)
t2 = New Thread(AddressOf fun2)
t3 = New Thread(AddressOf fun3)
t2.Start()
t1.Start()
t3.Start()
Console.ReadLine()
End Sub
End Module

5)
Imports System.Threading
Module Module1
Dim t1 As Thread
Dim t2 As Thread
Dim t3 As Thread
Public Sub fun1()
Dim i As Integer
For i = 1 To 250
Console.Write("A")
Next
End Sub
Public Sub fun2()
Dim j As Integer
For j = 1 To 250
Console.Write("B")
Next
End Sub
Public Sub fun3()
Dim k As Integer

t2.Suspend()
For k = 1 To 250
Console.Write("C")
Next
t2.Resume()
End Sub
Sub Main()
t1 = New Thread(AddressOf fun1)
t2 = New Thread(AddressOf fun2)
t3 = New Thread(AddressOf fun3)
t2.Start()
t1.Start()
t3.Start()
Console.ReadLine()
End Sub
End Module

You might also like