Vb.net Experiment with Example
-
Upload
vivek-kumar-sinha -
Category
Engineering
-
view
52 -
download
7
Transcript of Vb.net Experiment with Example
Shri Rawatpura Sarkar Institute of Technology-II
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
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
1
Shri Rawatpura Sarkar Institute of Technology-II
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.
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
2
Shri Rawatpura Sarkar Institute of Technology-II
The various categories in which the controls are grouped are:
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
3
Shri Rawatpura Sarkar Institute of Technology-II
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.
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
4
Shri Rawatpura Sarkar Institute of Technology-II
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()
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
5
Shri Rawatpura Sarkar Institute of Technology-II
End Sub
End Module
output
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
6
Shri Rawatpura Sarkar Institute of Technology-II
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
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
7
Shri Rawatpura Sarkar Institute of Technology-II
OUTPUT
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
8
Shri Rawatpura Sarkar Institute of Technology-II
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 - 1Write(" ") Next
For j = 0 ToiWrite("* ") Next
WriteLine() Next
ReadKey()
End Sub
End Module
OUTPUT
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
9
Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
10
Shri Rawatpura Sarkar Institute of Technology-II
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 IntegerWrite("Enter the size of 1D Array: ")siz = ReadLine()ReDimArr(siz)
'Arr = {3, 6, 2, 4, 1}
Dim i, j, choice As IntegerWriteLine("Enter the Elements of the Array") For i = 0 Tosiz - 1Arr(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 Integertemp = Arr(i)Arr(i) = Arr(j)Arr(j) = temp End If Next NextElseIf choice = 2 Then 'Descending Order For i = 0 Tosiz - 1
For j = 0 Toi If Arr(i) >Arr(j) Then Dim temp As Integertemp = Arr(i)Arr(i) = Arr(j)Arr(j) = temp End If
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
11
Shri Rawatpura Sarkar Institute of Technology-II
Next Next ElseWriteLine("Wrong Choice!!! Reselect Option!!!")GoTo Reselect End If
If choice = 1 ThenWriteLine("The Array in Ascending Order is :") ElseWriteLine("The Array in Descending Order is :") End If 'Print list For i = 0 Tosiz - 1WriteLine(Arr(i)) NextReadKey() End Sub
End Module
OUTPUT
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
12
Shri Rawatpura Sarkar Institute of Technology-II
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()
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
13
Shri Rawatpura Sarkar Institute of Technology-II
Dim i, j As IntegerWriteLine("Enter the size for the 2D Array:")sizm = ReadLine()sizn = ReadLine()
ReDimArr2D(sizm, sizn)
WriteLine("Enter the " & (sizm * sizn) & " Elements of the Array:") For i = 0 Tosizm - 1 For j = 0 Tosizn - 1Arr2D(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 - 1Write(Arr2D(i, j) &vbTab) NextWriteLine(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 - 1sum += 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()
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
14
Shri Rawatpura Sarkar Institute of Technology-II
Dim i, j As Integer If sizm = sizn Then For i = 0 Tosizm - 1 For j = 0 Tosizn - 1 If i = j ThenWrite(Arr2D(i, j) &vbTab) ElseWrite("0" &vbTab) End If
NextWriteLine(vbLf) Next ElseWriteLine("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 ThenWrite(Arr2D(i, j) &vbTab) ElseWrite("0" &vbTab) End If
NextWriteLine(vbLf) Next ElseWriteLine("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()
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
15
Shri Rawatpura Sarkar Institute of Technology-II
Dim i, j As Integer If sizm = sizn Then For i = 0 Tosizm - 1 For j = 0 Tosizn - 1 If j <= i ThenWrite(Arr2D(i, j) &vbTab) ElseWrite("0" &vbTab) End If
NextWriteLine(vbLf) Next ElseWriteLine("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 ThenWrite(Arr2D(i, j) &vbTab) ElseWrite("0" &vbTab) End If
NextWriteLine(vbLf) Next ElseWriteLine("Upper Triangular Matrix can only be printed for a triangular Matrix!!! so the Operation is not possible!!!") End If
ReadLine() End Sub
End ModuleOUTPUT
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
16
Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
17
Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
18
Shri Rawatpura Sarkar Institute of Technology-II
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 - 1mat(i, j) = ReadLine() Next Next
Return mat
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
19
Shri Rawatpura Sarkar Institute of Technology-II
End Function
Public Sub matOutput(ByVal mat(,) As Integer) Dim sm, sn As Integersm = mat.GetUpperBound(0)sn = mat.GetUpperBound(1)
WriteLine("The Matrix is ")
Dim i, j As Integer For i = 0 Tosm For j = 0 TosnWrite(mat(i, j) &vbTab) NextWriteLine() 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 ThenWriteLine("Matrix Addition Possible")ReDimmres(ubm1, ubn1)
Dim i, j As Integer
For i = 0 To ubm1 For j = 0 To ubn1mres(i, j) = m1(i, j) + m2(i, j) Next Next ElseWriteLine("Addition of Matrix Not Possible!!!")ReadKey() End End If
Return mres
End Function
Public Function matMul(ByVal m1(,) As Integer, ByVal m2(,) As Integer)
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
20
Shri Rawatpura Sarkar Institute of Technology-II
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 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 ubn1mres(i, j) += m1(i, k) * m2(k, j) Next Next Next ElseWriteLine("Matrix Multiplication Not Possible") End End If Return mres
End Function
End ModuleOUTPUT
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
21
Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
22
Shri Rawatpura Sarkar Institute of Technology-II
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")
ElseCSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
23
Shri Rawatpura Sarkar Institute of Technology-II
Console.Write("Invalid Input")
End If
Console.ReadLine()
End Sub
End Module
Output:
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
24
Shri Rawatpura Sarkar Institute of Technology-II
CSE/7th/VB.Net Lab/Prepared by Vivek Kumar Sinha
25