College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
Vb.net Experiment with Example
1. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
1
EXPERIMENT : 1
Aim: Visual basic an introduction of console and GUI programming technique Explain
new project window , property explorer , output window dynamic help, window
management .
The Visual Basic Express Edition integrated development environment (IDE) makes it easy for
you to create programs for Microsoft Windows. The IDE contains several tools that help you
design your applications and write, edit, and debug your application code. The following links
will help you to familiarize yourself with the Visual Basic Express Edition IDE.
Start Page
The Start Page may be used to select from the recent projects. A New Project may also be
started from the start page by clicking on the New Project Link. This page is useful to
search for help in all the Visual Studio Languages. The start page is displayed in the
browser & its URL is vs:/default.htm
2. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
2
Solution Explorer
Solution Exploreris the solution
directory and helps in managing
the open project files. The files
are displayed in a hierarchical
view. By default, Solution
Explorer is located on the right
side of the IDE. If Solution
Explorer is not visible, it can be
made visible by clicking View
Menu & then clicking the
Solution Explorer.
ToolBox
The Toolbox is a container for all the controls
that can be added to a Windows Forms
application or a Windows Presentation
Foundation (WPF) application. By default,
theToolbox is located on the left side of the
integrated development environment (IDE). If
theToolboxis not visible, it can be made visible
by clicking View and then clicking ToolBox.
The controls in the ToolBox are divided to
various groups according to their functionality &
usability. The controls are not visible in the
ToolBox when you are not in the Code Editor.
The Control can be added to the Window Form
by dragging it to the Application Window.
3. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
3
The various categories in which the controls are grouped are:
Tab name Description
All Windows
Forms
Contains all the standard Windows Forms controls that are
available in theToolbox.
Common Controls Contains the most common controls that are typically used
in Windows-based applications.
Containers Contains controls that hold other controls, such as
GroupBox controls and Panel controls. Containers can help
isolate a set of controls from other controls on the form.
Menus and
ToolBars
Contains controls that enable you to create menus and
toolbars for your application, such as the MenuStrip and
ToolStrip controls.
Data Contains controls that help you easily work with data in
your application, such as the DataGridView control.
Components Contains components that typically do not have a user
interface, such as the Timer and the ErrorProvider.
Printing Contains controls that enable you to provide printing
capabilities to an application.
Dialogs Contains controls that let you use common dialog boxes in
your application, such as the SaveFileDialog,
FolderBrowserDialog and FontDialog controls.
Properties Window
Properties of a form and any controls on the form in
the integrated development environment (IDE) can be
set by using the Properties window or by writing code
in the Code Editor. For example, to display text on a
button, you can set the button's Text property.
4. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
4
EXPERIMENT : 2
AIM: Write a program to find the average total grade of using if statement in console.
Module Module1
Sub Main()
Dim sub1, sub2, sub3 As Integer
Dim average As Integer
Dim name As String
Console.Write("Enter Student Name = > ")
name = Console.ReadLine()
Console.Write("Enter Marks for Subject 1 =>")
sub1 = Console.ReadLine()
sub1 = Convert.ToInt32(sub1)
Console.Write("Enter Marks for Subject 2 =>")
sub2 = Console.ReadLine()
sub2 = Convert.ToInt32(sub2)
Console.Write("Enter Marks for Subject 1 =>")
sub3 = Console.ReadLine()
sub3 = Convert.ToInt32(sub3)
average = (sub1 + sub2 + sub3) / 3
Console.Write("Your Result ")
Console.Write("Avergae Marks ")
Console.Write(average)
Console.Write("")
If average < 35 Then
Console.Write("Grade B")
ElseIf average >= 35 And average < 60 Then
Console.Write("Grade A")
ElseIf average >= 60 Then
Console.Write("Grade A")
End If
Console.ReadLine()
5. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
5
End Sub
End Module
output
6. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
6
EXPERIMENT NUMNER : 3
AIM: WAP TO ENTER ANY NO BETWEEN 1-7 AND PRINT APPROPREATE DAY AND
WEEKS
Module Module1
Sub Main()
Dim NUM As Integer
Console.WriteLine("Enter no between 1-7")
NUM = Console.ReadLine()
NUM = Convert.ToInt32(NUM)
If NUM = 1 Then
Console.Write("Sunday")
ElseIf NUM = 2 Then
Console.Write("Monday")
ElseIf NUM = 3 Then
Console.Write("Tuesday")
ElseIf NUM = 4 Then
Console.Write("Wednesay")
ElseIf NUM = 5 Then
Console.Write("Thursday")
ElseIf NUM = 6 Then
Console.Write("Friday")
ElseIf NUM = 7 Then
Console.Write("Saturday")
Else
Console.Write("Invalid Input")
End If
Console.ReadLine()
End Sub
End Module
7. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
7
OUTPUT
8. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
8
EXPERIMENT-4
Aim: Write a program to print the following Pattern using for loop.
*
* *
* * *
* * * *
* * * * *
Code:
Imports System.Console
Module PatternMod
Sub Main()
Dim n As Integer
Write("Enter the number of Rows for the pattern: ")
n = ReadLine()
For iAs Integer = 0 To n - 1
For j As Integer = 0 To n - i - 1
Write(" ")
Next
For j = 0 Toi
Write("* ")
Next
WriteLine()
Next
ReadKey()
End Sub
End Module
OUTPUT
9. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
9
10. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
10
EXPERIMENT-5
Aim: Write a program to input numbers in 1D Array & print in Ascending & Descending Order.
Code:
Imports System.Console
Module Arr1DMod
Sub Main()
Dim Arr() As Integer
Dim siz As Integer
Write("Enter the size of 1D Array: ")
siz = ReadLine()
ReDimArr(siz)
'Arr = {3, 6, 2, 4, 1}
Dim i, j, choice As Integer
WriteLine("Enter the Elements of the Array")
For i = 0 Tosiz - 1
Arr(i) = ReadLine()
Next
Reselect:
WriteLine("Select The Order To Display The Result")
WriteLine("1. Ascending Order" &vbLf& "2. Descending Order")
choice = ReadLine()
If choice = 1 Then
'Ascending Order
For i = 0 Tosiz - 1
For j = 0 Toi
If Arr(i) <Arr(j) Then
Dim temp As Integer
temp = Arr(i)
Arr(i) = Arr(j)
Arr(j) = temp
End If
Next
Next
ElseIf choice = 2 Then
'Descending Order
For i = 0 Tosiz - 1
For j = 0 Toi
If Arr(i) >Arr(j) Then
Dim temp As Integer
temp = Arr(i)
Arr(i) = Arr(j)
Arr(j) = temp
End If
Next
Next
11. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
11
Else
WriteLine("Wrong Choice!!! Reselect Option!!!")
GoTo Reselect
End If
If choice = 1 Then
WriteLine("The Array in Ascending Order is :")
Else
WriteLine("The Array in Descending Order is :")
End If
'Print list
For i = 0 Tosiz - 1
WriteLine(Arr(i))
Next
ReadKey()
End Sub
End Module
OUTPUT
12. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
12
EXPERIMENT -6
Aim: Write a program to input numbers in a 2D Array & perform the following operations:
i. Sum of all the numbers.
ii. Forward Diagonal & Backward Diagonal Matrix.
iii. Print Upper Triangular & Lower Triangular Matrix.
Code:
Imports System.Console
Module Array2DMod
Dim Arr2D(,) As Integer
Dim sizm, sizn As Integer
Sub Main()
Arr2dEntry()
Clear()
Arr2dDisp()
sumEleArr2D()
Clear()
Arr2dDisp()
FrwdDigArr2D()
Clear()
Arr2dDisp()
BkwdDigArr2D()
Clear()
Arr2dDisp()
LwrTriArr2D()
Clear()
Arr2dDisp()
UprTriArr2D()
End Sub
Public Sub Arr2dEntry()
Dim i, j As Integer
WriteLine("Enter the size for the 2D Array:")
sizm = ReadLine()
13. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
13
sizn = ReadLine()
ReDimArr2D(sizm, sizn)
WriteLine("Enter the " & (sizm * sizn) & " Elements of the Array:")
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
Arr2D(i, j) = ReadLine()
'Integer.Parse(ReadLine())
Next
Next
End Sub
Public Sub Arr2dDisp()
WriteLine("The Entered Matrix Is :")
WriteLine()
Dim i, j As Integer
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
Write(Arr2D(i, j) &vbTab)
Next
WriteLine(vbLf)
Next
ReadLine()
End Sub
Public Sub sumEleArr2D()
Dim i, j As Integer
Dim sum As Integer
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
sum += Arr2D(i, j)
Next
Next
WriteLine("Sum of the Elements of the 2D Array is : {0}", sum)
ReadLine()
End Sub
Public Sub FrwdDigArr2D()
WriteLine("Forward Diagonal Matrix: ")
WriteLine()
Dim i, j As Integer
If sizm = sizn Then
14. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
14
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
If i = j Then
Write(Arr2D(i, j) &vbTab)
Else
Write("0" &vbTab)
End If
Next
WriteLine(vbLf)
Next
Else
WriteLine("Forward Diagonal Matrix can only be printed for a triangular Matrix!!! so the Operation is
not possible!!!")
End If
ReadLine()
End Sub
Public Sub BkwdDigArr2D()
WriteLine("Backward Diagonal Matrix: ")
WriteLine()
Dim i, j As Integer
If sizm = sizn Then
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
If i = sizm - j - 1 Then
Write(Arr2D(i, j) &vbTab)
Else
Write("0" &vbTab)
End If
Next
WriteLine(vbLf)
Next
Else
WriteLine("Backward Diagonal Matrix can only be printed for a triangular Matrix!!! so the Operation is
not possible!!!")
End If
ReadLine()
End Sub
Public Sub LwrTriArr2D()
WriteLine("Lower Triangular Matrix: ")
WriteLine()
Dim i, j As Integer
If sizm = sizn Then
15. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
15
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
If j <= i Then
Write(Arr2D(i, j) &vbTab)
Else
Write("0" &vbTab)
End If
Next
WriteLine(vbLf)
Next
Else
WriteLine("Lower Triangular Matrix can only be printed for a triangular Matrix!!! so the Operation is not
possible!!!")
End If
ReadLine()
End Sub
Public Sub UprTriArr2D()
WriteLine("Upper Triangular Matrix: ")
WriteLine()
Dim i, j As Integer
If sizm = sizn Then
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
If j >= i Then
Write(Arr2D(i, j) &vbTab)
Else
Write("0" &vbTab)
End If
Next
WriteLine(vbLf)
Next
Else
WriteLine("Upper Triangular Matrix can only be printed for a triangular Matrix!!! so the Operation is not
possible!!!")
End If
ReadLine()
End Sub
End Module
OUTPUT
16. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
16
17. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
17
18. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
18
EXPERIMENT-7
Aim: Write a program to input numbers in a 2D Array & perform the following operations:
i. Sum of two matrices.
ii. Multiplication of two Matrices.
Code:
Imports System.Console
Module MatrixMod
Sub Main()
Dim m1(,) As Integer = matInput()
Dim m2(,) As Integer = matInput()
Dim madd(,) As Integer = matAdd(m1, m2)
matOutput(madd)
ReadKey()
Dim mmul(,) As Integer = matMul(m1, m2)
matOutput(mmul)
ReadKey()
End Sub
Public Function matInput()
Dim mat(,) As Integer
Dim sizm, sizn As Integer
WriteLine("Enter the Size of Matrix")
Write("size M :")
sizm = ReadLine()
Write("size N :")
sizn = ReadLine()
ReDimmat(sizm - 1, sizn - 1)
WriteLine("Enter the " &sizm * sizn& " elements of the matrix" &vbLf)
Dim i, j As Integer
For i = 0 Tosizm - 1
For j = 0 Tosizn - 1
mat(i, j) = ReadLine()
Next
Next
Return mat
End Function
19. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
19
Public Sub matOutput(ByVal mat(,) As Integer)
Dim sm, sn As Integer
sm = mat.GetUpperBound(0)
sn = mat.GetUpperBound(1)
WriteLine("The Matrix is ")
Dim i, j As Integer
For i = 0 Tosm
For j = 0 Tosn
Write(mat(i, j) &vbTab)
Next
WriteLine()
Next
End Sub
Public Function matAdd(ByVal m1(,) As Integer, ByVal m2(,) As Integer)
Dim mres(,) As Integer
Dim ubm1, ubm2, ubn1, ubn2 As Integer
ubm1 = m1.GetUpperBound(0)
ubm2 = m2.GetUpperBound(0)
ubn1 = m1.GetUpperBound(1)
ubn2 = m2.GetUpperBound(1)
If ubm1 = ubm2 AndAlso ubn1 = ubn2 Then
WriteLine("Matrix Addition Possible")
ReDimmres(ubm1, ubn1)
Dim i, j As Integer
For i = 0 To ubm1
For j = 0 To ubn1
mres(i, j) = m1(i, j) + m2(i, j)
Next
Next
Else
WriteLine("Addition of Matrix Not Possible!!!")
ReadKey()
End
End If
Return mres
End Function
Public Function matMul(ByVal m1(,) As Integer, ByVal m2(,) As Integer)
Dim mres(,) As Integer
20. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
20
Dim ubm1, ubm2, ubn1, ubn2 As Integer
ubm1 = m1.GetUpperBound(0)
ubm2 = m2.GetUpperBound(0)
ubn1 = m1.GetUpperBound(1)
ubn2 = m2.GetUpperBound(1)
If ubn1 = ubm2 Then
WriteLine("Matrix Multilication Possible")
ReDimmres(ubm1, ubn2)
Dim i, j, k As Integer
For i = 0 To ubm1
For j = 0 To ubn2
For k = 0 To ubn1
mres(i, j) += m1(i, k) * m2(k, j)
Next
Next
Next
Else
WriteLine("Matrix Multiplication Not Possible")
End
End If
Return mres
End Function
End Module
OUTPUT
21. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
21
22. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
22
EXPERIMENT : 8
AIM: WAP TO ENTER NO BETWEEN 1-12 AND DISPLAY APPROPRIAT MONTH NAME.
Module Module1
Sub Main()
Dim NUM As Integer
Console.WriteLine("Enter no between 1-12")
NUM = Console.ReadLine()
NUM = Convert.ToInt32(NUM)
If NUM = 1 Then
Console.Write("Janvery")
ElseIf NUM = 2 Then
Console.Write("Febvary")
ElseIf NUM = 3 Then
Console.Write("March")
ElseIf NUM = 4 Then
Console.Write("April")
ElseIf NUM = 5 Then
Console.Write("May")
ElseIf NUM = 6 Then
Console.Write("June")
ElseIf NUM = 7 Then
Console.Write("July")
ElseIf NUM = 8 Then
Console.Write("Augst")
ElseIf NUM = 9 Then
Console.Write("September")
ElseIf NUM = 10 Then
Console.Write("October")
ElseIf NUM = 11 Then
Console.Write("November")
ElseIf NUM = 12 Then
Console.Write("December")
Else
23. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
23
Console.Write("Invalid Input")
End If
Console.ReadLine()
End Sub
End Module
Output:
24. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
24
25. Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th
/VB.NetLab/PreparedbyVivekKumarSinha
25