You are on page 1of 86

Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

Practical No: 03

VIII. Resources required (Additional)


- If any web reference is required.

X. Resources required (Actual)


(1) https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features
/operators-and-expressions/arithmetic-operators
(2) https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox?View=
netframework-4.7.2

XI. Program Code:


Write a program using MessageBox and Arithmetic Expressions –

Module Module1
Dim i, j, r As Integer

Sub Main()
Console.WriteLine("Enter First Value=")
i = Console.ReadLine()
Console.WriteLine("Enter Second Value=")
j = Console.ReadLine()
Console.ReadLine()
MsgBox("Addition =" & (i + j))
MsgBox("Substraction =" & (i - j))
MsgBox("Multiplication =" & (i * j))
MsgBox("Division =" & (i / j))
End Sub
End Module
Results (Output of the Program)
Enter First Value=
10
Enter Second Value=
5
---------------------------
MessageBoxPractical3
---------------------------
Addition =15
---------------------------
OK
---------------------------

GUI Application Development using VB.Net (22034) Page 1


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

XIII. Practical Related Questions


1. Write the difference between MessageBox() and ErrorProvider Control –
- Displays a message window, also known as a dialog box, which presents a message to the
user. It is a modal window, blocking other actions in the application until the user closes it.
A MessageBox can contain text, buttons, and symbols that inform and instruct the user.
- Sets the error description string for the specified control. When an error occurs for the value
in associated control, then a small red color icon is displayed and when we hover the mouse
on icon it displays an error message.

2. Describe any four types of MessageBox() Window –


In Visual Basic, MessageBox has Show() method and it is overloaded to create various
types of MessgeBoxes and various programming situations –

It has prototype –
DialogResult Show(String text, String caption, MessageBoxButtons buttons,
MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
This method is static and doesn’t required and object reference. The parameters and return
values are explained below –

Parameters
1. text As String - The text to display in the message box.
2. caption As String - The text to display in the title bar of the message box.
3. buttons As MessageBoxButtons - One of the MessageBoxButtons values that
specifies which buttons to display in the message box.
4. icon As MessageBoxIcon - One of the MessageBoxIcon values that specifies which
icon to display in the message box.
5. defaultButton As MessageBoxDefaultButton - One of the
MessageBoxDefaultButton values that specifies the default button for the message
box.

Returns
DialogResult - One of the DialogResult values.

GUI Application Development using VB.Net (22034) Page 2


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

XIV. Exercise
1. Implement the program to generate result of any arithmetic operation using
MessageBox().

Public Class Form1


Dim n As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
n = Val(TextBox1.Text) + Val(TextBox2.Text)
MsgBox("Addition=" & n)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
n = Val(TextBox1.Text) - Val(TextBox2.Text)
MsgBox("Substraction=" & n)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
n = Val(TextBox1.Text) * Val(TextBox2.Text)
MsgBox("Multiplication=" & n)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
n = Val(TextBox1.Text) / Val(TextBox2.Text)
MsgBox("Division=" & n)
End Sub
End Class

-Arithmetic Operation using msgbox


---------------------------
Addition=60
---------------------------
OK
GUI Application Development using VB.Net (22034) Page 3
Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

2. Write a program using InputBox(), MessageBox() & perform various Arithmetic


expressions.

Public Class Form1


Dim i, j, r As Integer

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


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) - Val(j)
MsgBox("Substract = " & r)
End Sub

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


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) / Val(j)
MsgBox("Divide = " & r)
End Sub

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


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) * Val(j)
MsgBox("Multiply = " & r)
End Sub

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


i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) + Val(j)
MsgBox("Addition = " & r)

End Sub
End Class

GUI Application Development using VB.Net (22034) Page 4


Practical No. 3: Implement a Message Box program & Arithmetic Expressions.

Output:

---------------------------
Inputbox_Msgbox
---------------------------
Addition = 68
---------------------------
OK
---------------------------
---------------------------

GUI Application Development using VB.Net (22034) Page 5


Practical No. 4: Implement a program for If-else control structures in VB.NET.

Practical No: 04

VIII. Resources required (Additional)


- If any web reference is required.

X. Resources required (Actual)


(1) https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/if-then-
else-statement
(2) https://www.tutorialspoint.com/vb.net/vb.net_if_else_statements.htm

XI. Program Code:


Write a program using if-else statement –
 Module Module1
Sub Main()
Dim n As Integer
Console.WriteLine("Enter a Number")
n = Console.ReadLine()
If (n > 0) Then
Console.WriteLine("Number is Positive")
Else
Console.WriteLine("Number is Negative")
End If
Console.ReadLine()
End Sub
End Module

Results (Output of the Program)


Enter a number:
9
Number is Positive

XIII. Practical Related Questions


1. Write program for finding greatest among three numbers –
 Module Module1
Sub Main()
Dim a, b, c As Integer
Console.Write("Enter the values of a, b and c:")
a = Val(Console.ReadLine())
b = Val(Console.ReadLine())
c = Val(Console.ReadLine())
If (a > b) Then
If (a > c) Then
Console.WriteLine("Greatest Number is:" & a)
Else
Console.WriteLine("Greatest Number is:" & c)

End If
Else
If (b > c) Then

GUI Application Development using VB.Net (22034) Page 1


Practical No. 4: Implement a program for If-else control structures in VB.NET.

Console.WriteLine("Greatest Number is:" & b)


Else
Console.WriteLine("Greatest Number is:" & c)
End If
End If
Console.ReadLine()
End Sub
End Module
Results (Output of the Program)
Enter the values of a, b and c:23
65
12
Greatest Number is:65

2. Implement the program using if-else statement to find the number is even or odd –
 Module Module1
Dim i As Integer

Sub Main()
Console.WriteLine("Enter Number")
i = Console.ReadLine()
If ((i Mod 2) = 0) Then
Console.WriteLine("Number is Even")
Else
Console.WriteLine("Number is Odd")
End If
Console.ReadLine()
End Sub
End Module

Results (Output of the Program)


Enter a number:
9
Number is Odd

XIV. Exercise
1. Write the program using if-else statement for following output.
Result Percentage Criteria
Fail perc < 40
Second Class perc > 40 AND perc < 60
First Class perc > 60 AND perc < 75
Distinction perc > 75

 Module Module1

Sub Main()
Dim perc As Integer
Console.Write("Enter Percentage:")
perc = Val(Console.ReadLine())
GUI Application Development using VB.Net (22034) Page 2
Practical No. 4: Implement a program for If-else control structures in VB.NET.

If (perc < 40) Then


Console.WriteLine("Fail")
ElseIf ((perc > 40) And (perc < 60)) Then
Console.WriteLine("Pass Class")
ElseIf ((perc >= 60) And (perc < 75)) Then
Console.WriteLine("First Class")
ElseIf (perc >= 75) Then
Console.WriteLine("Distinction")
End If
Console.ReadLine()
End Sub

End Module

Results (Output of the Program)


Enter Percentage:85
Distinction

2. Write output of following code.


 Module Module1

Sub Main()
Dim i As Integer
i=4
Dim a As Double
a = -1.0

If (i > 0) Then
If (a > 0) Then
Console.WriteLine("Here I am !!!!")
Else
Console.WriteLine("No here I am ??")
Console.WriteLine("Actually here I am ??")
End If
End If

Console.ReadKey()
End Sub

End Module

Results (Output of the Program)


No here I am ??
Actually here I am ??

GUI Application Development using VB.Net (22034) Page 3


Practical No. 5: Implement a program for Select case control structures in VB.NET.

Practical No: 05

VIII. Resources required (Additional)


- if any web references are required.

X. Resources used (Additional)


(1) https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-
case-statement
(2) https://www.tutorialspoint.com/vb.net/vb.net_select_case_statements.htm

XI. Program Code:


Write a Program using select case statement in VB.NET

Module Module1

Sub Main()
Dim grade As String
Console.WriteLine("Enter Your grade")
grade = Console.ReadLine()
Select Case grade
Case "A"
Console.WriteLine("High Distinction")
Case "A-"
Console.WriteLine("Distinction")
Case "B"
Console.WriteLine("Credit")
Case "C"
Console.WriteLine("Pass")
Case Else
Console.WriteLine("Fail")
End Select
Console.ReadLine()
End Sub

End Module
XII. Results (Output of the Program)
Enter Your grade
A
High Distinction
XIII. Practical Related Questions
1. Write the use of Select Case statement –
- A Select Case statement allows a variable to be tested for equality against a list of
values.
- Each value is called a case, and the variable being switched on is checked for each
select case.

GUI Application Development using VB.Net (22034) Page 1


Practical No. 5: Implement a program for Select case control structures in VB.NET.

2. Flowchart for nested Select Case statement –

XIV. Exercise

1. Implement the program using Select Case statement to count the number of Vowels in
A to Z alphabets.
 Module Module1
Sub Main()
Dim str As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim numberOfVowels As Integer = 0

For Each c As Char In str


Select Case c
Case "A"c, "E"c, "I"c, "O"c, "U"c
numberOfVowels = numberOfVowels + 1
End Select
Next

Console.WriteLine("Number of vowels: " & numberOfVowels)


Console.ReadKey()
End Sub
End Module
Output:
Number of vowels: 5

GUI Application Development using VB.Net (22034) Page 2


Practical No. 5: Implement a program for Select case control structures in VB.NET.

2. Develop a program for performing arithmetic operations –


Module Module1
Sub Main()
Dim N1, N2, Result, choice As Integer
Do
Console.WriteLine("Menu:-\n1.Add\n2.Subtract" & _
"\n3.Multiply\n4.Divide\n5.Exit.")
Console.WriteLine("Enter choice: ")
choice = Console.ReadLine()
Console.WriteLine("Enter number 1: ")
N1 = Console.ReadLine()
Console.WriteLine("Enter number 2: ")
N2 = Console.ReadLine()
Select Case choice
Case 1
Result = N1 + N2
Console.WriteLine("Sum = " & Result)
Case 2
Result = N1 - N2
Console.WriteLine("Difference = " & Result)
Case 3
Result = N1 * N2
Console.WriteLine("Product = " & Result)
Case 4
Result = N1 \ N2
Console.WriteLine("Quotient = " & Result)
Result = N1 Mod N2
Console.WriteLine("Remainder = " & Result)
Case 5
Exit Sub
Case Else
Console.WriteLine("Wrong option ...")
End Select
Loop While choice <> 5
End Sub
End Module
Output:
Menu:-\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Exit.
Enter choice: 1
Enter number 1: 57
Enter number 2: 87
Sum = 144
Menu:-\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Exit.
Enter choice: 5

GUI Application Development using VB.Net (22034) Page 3


Practical No. 6: Implement a program for While, Do Loops in VB.NET.

Practical No 06

VIII. Resources required (Additional)


- If any web references are required.

X. Resources used (Additional)


- https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/while-
end-while-statement
- https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/do-
loop-statement

XI. Program Code


Write a program using While & Do loop in VB.Net
 For while loop.
Module Module1

Sub Main()
Dim a As Integer = 1
While (a < 10)
Console.WriteLine(a)
a = a + 1
End While
Console.ReadLine()
End Sub

End Module
Output:
1
2
3
4
5
6
7
8
9
 For Do loop.
Module Module1

Sub Main()
Dim a As Integer = 1
Do
Console.WriteLine(a)
a = a + 1
Loop While (a<10)
Console.ReadLine()
End Sub

End Module

GUI Application Development using VB.Net (22034) Page 1


Practical No. 6: Implement a program for While, Do Loops in VB.NET.

Output:
1
2
3
4
5
6
7
8
9

XIII. Practical Related Questions


1. Differentiate between Do & While Loop statements in VB.Net
No Do Loop No While Loop
In Do loop, the condition can be tested
In While loop, the condition can be
1 at starting or ending as per 1
tested at starting only.
requirement.
For Do Loop two variation available For While loop no such variations are
2 2
Do While Loop & Do Until Loop available.
Do While Loop statement can execute
for finite number of iterations as long
While loop can execute for finite
as condition of loop is true while Do
3 3 number of iterations as long as
Until Loop statement can execute for
condition of loop is true.
finite number of iterations as long as
condition of loop is false.
Loop keyword is used as termination End keyword is used as termination
4 4
statement for Do loops. statement for While loop.
Dim index As Integer = 0 Dim index As Integer = 0
Do While index <= 10
Debug.Write(index & " ") Debug.Write(index & " ")
index += 1 index += 1
5 5
Loop Until index > 10 End While

Debug.WriteLine("") Debug.WriteLine("")
' Output: 0 1 2 3 4 5 6 7 8 9 10 ' Output: 0 1 2 3 4 5 6 7 8 9 10

2. Give the syntax of While & Do loop statements in VB.NET.


 While Loop:
It executes a series of statements as long as a given condition is True.
Syntax:
While condition
[ statements ]
[ Continue While ]
[ statements ]
[ Exit While ]
[ statements ]
End While

GUI Application Development using VB.Net (22034) Page 2


Practical No. 6: Implement a program for While, Do Loops in VB.NET.

Do Loop:
It repeats the enclosed block of statements while a Boolean condition is True or until the
condition becomes True. It could be terminated at any time with the Exit Do statement.
Syntax:
Do
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop { While | Until } condition

XIV. Exercise
1. Write a program using While statement to print the prime numbers between 1 to 100.
Module Module1
Sub Main()
Dim i, j, c As Integer
c=0
i=2
While (i <= 100)
j=2
While (j < i)
If (i Mod j = 0) Then
Exit While
ElseIf (i = j + 1) Then
Console.WriteLine(i)
End If
j=j+1
End While
i=i+1
End While
Console.ReadLine()
End Sub
End Module

OUTPUT:

GUI Application Development using VB.Net (22034) Page 3


Practical No. 6: Implement a program for While, Do Loops in VB.NET.

2. Write a program using While statement to print even-odd numbers between 1 to 50.
 Module Module1

Sub Main()
Dim i As Integer = 1
While (i <= 50)
If ((i Mod 2) = 0) Then
Console.WriteLine(i & " Even")
Else
Console.WriteLine(i & " Odd")
End If
i=i+1
End While
Console.ReadLine()
End Sub

End Module
Output:

GUI Application Development using VB.Net (22034) Page 4


Practical No. 7: Implement a program to demonstrate the use of For, For-each Loops in
VB.NET.

Practical No 07

VIII. Resources required (Additional)


- If any web references are required.

X. Resources used (Additional)


- https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-
next-statement
- https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-
each-next-statement

XI. Program Code


Write a program using For & For Each loop in VB.Net
Program – Program to calculate search the element in an array using linear search.

Module Module1

Sub Main()
Dim Array() As Integer = {12, 34, 56, 37, 78, 53, _
98, 22, 19, 68}
Dim Key As Integer
Dim IsKeyFoundFlag As Boolean = False

Console.WriteLine("Enter element to search: ")


Key = Console.ReadLine()

For i As Integer = 1 To Array.Length() - 1


If Array(i) = Key Then
IsKeyFoundFlag = True
End If
Next

If IsKeyFoundFlag = True Then


Console.WriteLine("Element present.")
Else
Console.WriteLine("Element absent.")
End If

Console.ReadKey()
End Sub

End Module

XII. Results (output of the program)


Enter element to search:
53
Element present

GUI Application Development using VB.Net (22034) Page 1


Practical No. 7: Implement a program to demonstrate the use of For, For-each Loops in
VB.NET.

XIII. Practical Related Questions


1. Write the output of the following code?
Module Module1

Sub Main()
For i As Integer = 0 To -10 Step -1
Console.WriteLine(i)
Next
Console.ReadKey()
End Sub

End Module

Output :
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10

2. Write the program to generate the following output –


Module Module1

Sub Main()
Dim i As Single

For i = 3.5F To 8.5F Step 0.5F


Console.WriteLine(i)
Next
Console.ReadKey()
End Sub

End Module

XIV. Exercise
1. Write the situation where for each loop statements can be implemented.
 Use a For Each...Next loop when you want to repeat a set of statements for each element of
a collection or array.

GUI Application Development using VB.Net (22034) Page 2


Practical No. 7: Implement a program to demonstrate the use of For, For-each Loops in
VB.NET.

2. Write program using For Next loop statement tot find the Armstrong numbers
between 1 to 500. (153 is Armstrong Number – 13 + 53 + 33 = 153)
 Module Module1

Sub Main()
Dim i As Integer

Console.Write("Armstrong Numbers between 1 to 500: ")


For i = 1 To 500 Step 1
Dim sum, num, digit As Integer
sum = 0
num = i

While (num > 0)


digit = num Mod 10
sum += (digit * digit * digit)
num = num \ 10
End While

If (sum = i) Then
Console.WriteLine(i)
End If
Next
Console.ReadLine()
End Sub

End Module
Output:
1
153
370
371
407

GUI Application Development using VB.Net (22034) Page 3


Practical No. 8: Design windows application using Text Box, Label & Button

Practical No 08
VIII. Resources required (Additional)
 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.textbox?view=netframework-4.7.2
 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.label?view=netframework-4.7.2
 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.button?view=netframework-4.7.2

XI. Program Code


Write a program to demonstrate the use of Button, Textbox and Label.

Public Class Form1


Private Function Factorial(ByVal num As Integer) As Long
Dim fact As Long = 1
Dim i As Integer

For i = 1 To num
fact *= i
Next
Factorial = fact
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fact As Long
fact = Factorial(TextBox1.Text)
MessageBox.Show("Factorial of " & TextBox1.Text &
" is " & fact, "Factorial", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No. 8: Design windows application using Text Box, Label & Button

XII. Results (output of the program)

XIII. Practical related Questions


1. Write the use of Tab Index property of the control.
 The following example uses the TabIndex property to display and set the tab order for
individual controls. The user can press Tab to reach the next control in the tab order and to
display the TabIndex of that control.

2. Write the code to generate button at runtime in VB.Net.


 Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim b As New Button
b.Text = "Click"
Me.Controls.Add(b)
End Sub
End Class
Output:

GUI Application Development using VB.Net (22034) Page 2


Practical No. 8: Design windows application using Text Box, Label & Button

XIV. Exercise
1. Write a program to perform the arithmetic operations using controls Label, Button
and TextBox.

Public Class Form1


Dim n As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
n = Val(TextBox1.Text) + Val(TextBox2.Text)
TextBox3.Text = n
End Sub

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


n = Val(TextBox1.Text) - Val(TextBox2.Text)
TextBox3.Text = n
End Sub

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


n = Val(TextBox1.Text) * Val(TextBox2.Text)
TextBox3.Text = n
End Sub

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


n = Val(TextBox1.Text) / Val(TextBox2.Text)
TextBox3.Text = n
End Sub
End Class
Output:

GUI Application Development using VB.Net (22034) Page 3


Practical No. 8: Design windows application using Text Box, Label & Button

2. Write a program to change the background color of the form when user clicks on
different buttons.

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.BackColor = Color.Red
End Sub

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


Me.BackColor = Color.Green
End Sub

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


Me.BackColor = Color.Yellow
End Sub
End Class

Output:

GUI Application Development using VB.Net (22034) Page 4


Practical No. 9: Design windows application using Radio Button & Check Box.

Practical No 09

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.checkbox?view=netframework-4.7.2
 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.radiobutton?view=netframework-4.7.2

XI. Program Code


Write a program to demonstrate the use of CheckBox and RadioButton.
 Code to check Radio Buttons State

Public Class Form1


Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton1.CheckedChanged
If (RadioButton1.Checked = True) Then
MessageBox.Show("You are Select VB.NET")
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton2.CheckedChanged
If (RadioButton2.Checked = True) Then
MessageBox.Show("You are Select JAVA")
End If
End Sub
End Class
OUTPUT :

GUI Application Development using VB.Net (22034) Page 1


Practical No. 9: Design windows application using Radio Button & Check Box.

Code to display message when the checkbox is checked -

Public Class Form1


Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged
MessageBox.Show("you are select VB.NET")
End Sub

Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles


CheckBox2.CheckedChanged
MessageBox.Show("you are select JAVA")
End Sub
End Class
OUTPUT :

GUI Application Development using VB.Net (22034) Page 2


Practical No. 9: Design windows application using Radio Button & Check Box.

XIII. Practical related Questions


1. Write the program using RadioButton to change the bulb state ON/OFF.

Public Class Form1


Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton1.CheckedChanged
PictureBox2.Show()
PictureBox1.Hide()
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton2.CheckedChanged

PictureBox1.Show()
PictureBox2.Hide()
End Sub
End Class
OUTPUT:

GUI Application Development using VB.Net (22034) Page 3


Practical No. 9: Design windows application using Radio Button & Check Box.

2. Differentiate between RadioButton and CheckBox controls.


- In a checkbox group, a user can select more than one option. Each checkbox operates
individually, so a user can toggle each response "Checked" and "Not Checked."
- Radio buttons, however, operate as a group and provide mutually exclusive selection
values. A user can select only one option in a radio button group.

XIV. Exercise
1. Write a program to change the ForeColor of the text in Label using different
RadioButtons such Red, Green, Blue.

Public Class Form1


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

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton2.CheckedChanged
Label1.ForeColor = Color.Green
End Sub

Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles


RadioButton3.CheckedChanged
Label1.ForeColor = Color.Blue
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 4


Practical No. 10: Design windows application using List Box & Combo Box.

Practical No 10

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.listbox?view=netframework-4.7.2
 https://docs.microsoft.com/en-
us/dotnet/api/system.windows.forms.combobox?view=netframework-4.7.2

XI. Program Code


1. Write a program to demonstrate the use of ListBox and ComboBox.
(Code for Add Items to ListBox & Remove Selected Item from ListBox)

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub

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


ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
End Class
XII. Results (output of the program):

GUI Application Development using VB.Net (22034) Page 1


Practical No. 10: Design windows application using List Box & Combo Box.

XIII. Practical related Questions


1. Write the program to select multiple subjects using ListBox control.

Public Class Form1


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListBox1.SelectionMode = SelectionMode.MultiSimple
ListBox1.Items.Add("C")
ListBox1.Items.Add("C++")
ListBox1.Items.Add("JAVA")
ListBox1.Items.Add(".NET")
ListBox1.Items.Add("PHP")
ListBox1.Items.Add("Python")
End Sub
End Class
OUTPUT:

2. Write the program to select colleges using single ComboBox.


GUI Application Development using VB.Net (22034) Page 2


Practical No. 10: Design windows application using List Box & Combo Box.

Public Class Combo_Box


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("MET")
ComboBox1.Items.Add("GGSP")
ComboBox1.Items.Add("KKW")
ComboBox1.Items.Add("GP")
End Sub

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


Handles ComboBox1.SelectedIndexChanged
MsgBox(ComboBox1.SelectedItem.ToString)
End Sub
End Class
OUTPUT:

XIV. Exercise

1. Differentiate between ListBox and ComboBox.


 The ComboBox allows to select single items from the Collection of Items. The ListBox
allows to select the single of multiple items from the Collection of Items using SelectMode
property.

2. Write a program to select multiple subjects for single semester.


GUI Application Development using VB.Net (22034) Page 3


Practical No. 10: Design windows application using List Box & Combo Box.

Public Class Student_Registration


Private Sub Student_Registration_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
ComboBox1.Items.Add("First Semester")
ComboBox1.Items.Add("Second Semester")
ComboBox1.Items.Add("Third Semester")
ComboBox1.Items.Add("Fourth Semester")
End Sub

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


Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.SelectedIndex = 0) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("Chemistry")
ListBox1.Items.Add("Physics")
ListBox1.Items.Add("Maths")
ListBox1.Items.Add("English")
End If
If (ComboBox1.SelectedIndex = 1) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("PIC")
ListBox1.Items.Add("Maths")
ListBox1.Items.Add("CHM")
ListBox1.Items.Add("WPD")
End If
If (ComboBox1.SelectedIndex = 2) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("DBM")
ListBox1.Items.Add("OOP")
ListBox1.Items.Add("CGR")
ListBox1.Items.Add("DSU")
End If
If (ComboBox1.SelectedIndex = 3) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("JPR")
ListBox1.Items.Add("DCC")
ListBox1.Items.Add("GUI")
ListBox1.Items.Add("SEN")
End If
End Sub
End Class
OUTPUT:

GUI Application Development using VB.Net (22034) Page 4


Practical No. 11: Design windows application using Picture Box & Panel.

Practical No 11

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.toolstrip
 https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.panel
 https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.picturebox

XI. Program Code


1. Write a program using Toolbar, Form and Panel Controls.

Public Class Form1


Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles
ToolStripButton1.Click
Panel1.BackColor = Color.Red
End Sub

Private Sub ToolStripButton2_Click(sender As Object, e As EventArgs) Handles


ToolStripButton2.Click
Panel1.BackColor = Color.Green
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No. 11: Design windows application using Picture Box & Panel.

XII. Results (output of the program)

XIII. Practical related Questions


1. List the controls which is used to set the icons on the Toolbar Control.
 Following Controls Can be added to ToolStrip / Toolbar.
Button, Label, DropDownButton, SplitButton, Separator, ComboBox, TextBox, and
ProgressBar.
2. Difference between Form and Panel.
Windows Forms Panel controls are used to provide an identifiable grouping for other
controls. Typically, you use panels to subdivide a form by function. The Panel control is
similar to the GroupBox control; however, only the Panel control can have scroll bars, and
only the GroupBox control displays a caption.

XIV. Exercise
1. Write program using picture box control to load an image at run time.

Public Class Form1


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.ImageLocation = "E:\www.studyroom.xyz\ON_Bulb.jpg"
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
End Sub
End Class
GUI Application Development using VB.Net (22034) Page 2
Practical No. 11: Design windows application using Picture Box & Panel.

OUTPUT:

2. Write a program to demonstrate the use of Panel Control in VB.Net.

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim dynamicPanel As New Panel()
dynamicPanel.Name = "Panel1"
dynamicPanel.Size = New System.Drawing.Size(228, 200)
dynamicPanel.BackColor = Color.Pink

Dim textBox1 As New TextBox()


textBox1.Location = New Point(10, 10)
textBox1.Text = "Enter Your Name"

Dim checkBox1 As New CheckBox()


checkBox1.Location = New Point(10, 50)
checkBox1.Text = "Male"
checkBox1.Size = New Size(200, 30)

Dim checkBox2 As New CheckBox()


checkBox2.Location = New Point(10, 90)
checkBox2.Text = "Male"
checkBox2.Size = New Size(200, 30)

dynamicPanel.Controls.Add(textBox1)

GUI Application Development using VB.Net (22034) Page 3


Practical No. 11: Design windows application using Picture Box & Panel.

dynamicPanel.Controls.Add(checkBox1)
dynamicPanel.Controls.Add(checkBox2)

Controls.Add(dynamicPanel)
End Sub
End Class
OUTPUT:

GUI Application Development using VB.Net (22034) Page 4


Practical No. 12: Design windows application using Tab Control & Timer.

Practical No 12
VIII. Resources required (Additional)
 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tabcontrol
 https://docs.microsoft.com/en-us/dotnet/api/system.timers.timer

XI. Program Code


1. Write a program using Tab Control.

Public Class Form1

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


Label1.Text = "Button from FY has been Clicked!"
End Sub

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


Label1.Text = "Button from SY has been Clicked!"
End Sub
End Class
XII. Results (output of the program)

GUI Application Development using VB.Net (22034) Page 1


Practical No. 12: Design windows application using Tab Control & Timer.

XIII. Practical related Questions


1. Write a procedure to display the icons on the Toolbar Control.
 ToolBar buttons are able to display icons within them for easy identification by users. This
is achieved through adding images to the ImageList Component component and then
associating the ImageList component with the ToolBar control.

To set an icon for a toolbar button programmatically

1. In a procedure, instantiate an ImageList component and a ToolBar control.


2. In the same procedure, assign an image to the ImageList component.
3. In the same procedure, assign the ImageList control to the ToolBar control and assign
the ImageIndex property of the individual toolbar buttons.

2. Difference between Form and Panel Control in VB.NET


 Windows Forms Panel controls are used to provide an identifiable grouping for other
controls. Typically, you use panels to subdivide a form by function. The Panel control is
similar to the GroupBox control; however, only the Panel control can have scroll bars, and
only the GroupBox control displays a caption.

XIV. Exercise
1. Write a program to display the traffic signal using timer control.

Public Class Form1

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


If PictureBox1.Visible Then
PictureBox1.Visible = False
PictureBox2.Visible = True
PictureBox3.Visible = False
ElseIf PictureBox2.Visible Then
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = True
ElseIf PictureBox3.Visible Then

GUI Application Development using VB.Net (22034) Page 2


Practical No. 12: Design windows application using Tab Control & Timer.

PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Timer1.Enabled = True
Timer1.Interval = 1600
PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
End Sub

Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles


PictureBox2.Click

End Sub
End Class
OUTPUT:

3. Write a program to demonstrate the Tab Control in VB.net.

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


TabPage1.Text = "FY"
TabPage2.Text = "SY"
End Sub

GUI Application Development using VB.Net (22034) Page 3


Practical No. 12: Design windows application using Tab Control & Timer.

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


TabControl1.TabPages.Add("TY")
End Sub
End Class
OUTPUT:

GUI Application Development using VB.Net (22034) Page 4


Practical No. 13 & 14: Implement a Windows application to Perform Validation on various control.

Practical No 13 & 14
VIII. Resources required (Additional)
 If any web resources required.

X. Resources used (Additional)


 https://www.tutorialspoint.com/vb.net/vb.net_regular_expressions.htm
 https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions
 https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.errorprovider

XI. Program Code


1. Write a program using Error Provider and Regular Expression.

Imports System.Text.RegularExpressions
Public Class Form1

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


Dim regex As Regex = New Regex("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-
9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
Dim isValid As Boolean = regex.IsMatch(TextBox1.Text.Trim)
If Not isValid Then
ErrorProvider1.SetError(TextBox1, "Invalid E-mail ID")
Else
MsgBox("Valid E-Mail ID")
End If
End Sub

End Class
XII. Results (Output of the Program)

GUI Application Development using VB.Net (22034) Page 1


Practical No. 13 & 14: Implement a Windows application to Perform Validation on various control.

XIII. Practical related Questions


1. Enlist the different constructs for Regular Expressions.
 Constructs for Defining Regular Expressions
There are various categories of characters, operators, and constructs that lets you to define
regular expressions. Click the following links to find these constructs.
 Character escapes
 Character classes
 Anchors
 Grouping constructs
 Quantifiers
 Backreference constructs
 Alternation constructs
 Substitutions
 Miscellaneous constructs

2. Write the program code to perform validation using ErrorProvider Control.


Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim regex As Regex = New Regex("(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])
\/((19|20)\d\d))$")
Dim b As Boolean = regex.IsMatch(TextBox1.Text.Trim)
If Not b Then
ErrorProvider1.SetError(TextBox1, "Invalid Format")
Else
MsgBox("Valid Format")
ErrorProvider1.SetError(TextBox1, "")
End If
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 2


Practical No. 13 & 14: Implement a Windows application to Perform Validation on various control.

OUTPUT:

XIV. Exercise
1. Write a program using ErrorProvider for username and password authentication.

Public Class Form1

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


If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Please Enter Your Name")
Else
ErrorProvider1.SetError(TextBox1, "")
End If
If TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "Please Enter Your Password")
Else
ErrorProvider1.SetError(TextBox2, "")
End If
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 3


Practical No. 13 & 14: Implement a Windows application to Perform Validation on various control.

OUTPUT:

2. Write a program using ErrorProvider for control to validate Mobile Number and
Email ID in GUI appnlication.

Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim number As New Regex("\d{10}")
If number.IsMatch(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "")
MsgBox("Valid Phone Number")
Else
ErrorProvider1.SetError(TextBox1, "Invalid Phone Number")
End If
Dim regex As Regex = New Regex("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-
9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")
Dim isValid As Boolean = regex.IsMatch(TextBox2.Text.Trim)
If Not isValid Then
ErrorProvider1.SetError(TextBox2, "Invalid E-mail ID")
Else
ErrorProvider1.SetError(TextBox2, "")
MsgBox("Valid E-Mail ID")
End If
End Sub
End Class
GUI Application Development using VB.Net (22034) Page 4
Practical No. 13 & 14: Implement a Windows application to Perform Validation on various control.

OUTPUT:

GUI Application Development using VB.Net (22034) Page 5


Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.

Practical No 15

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-
features/procedures/sub-procedures
 https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-
features/procedures/procedure-parameters-and-arguments

XI. Program Code


1. Write a program using sub procedure and parameterized sub procedure
 Module Module1

Sub Main()
displaymsg()
Dim a, b As Integer
Console.WriteLine("Enter Value")
a = Console.ReadLine()
b = Console.ReadLine()
Add(a, b)
Console.ReadLine()
End Sub
Sub displaymsg()
Console.WriteLine("Use of sub-procedure")
End Sub
Sub Add(ByVal a As Integer, ByVal b As Integer)
Console.WriteLine("Addition = " & a + b)
End Sub

End Module

XII. Results (output of the program)


Use of sub-procedure
Enter Value
10
10
Addition = 20

GUI Application Development using VB.Net (22034) Page 1


Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.

XIII. Practical related Questions


1. Differentiate between ByVal and ByRef keywords in parameter passing of Sub
Procedure.
 ByVal and ByRef in VB .NET. When you pass arguments over to Subs and Function you can
do so either By Value or By Reference. By Value is shortened to ByVal and By Reference is
shortened to ByRef. ByVal means that you are passing a copy of a variable to your
Subroutine.

2. Write the program using Recursion. (Factorial of Number)


 Module Module1

Sub Main()
Dim num As Integer
Console.WriteLine("Enter a Number")
num = Console.ReadLine()
factorial(num)
Console.ReadLine()
End Sub
Sub factorial(ByVal num As Integer)
' local variable declaration */
Dim i, factorial As Integer
factorial = 1
For i = 1 To num
factorial = factorial * i
Next i
Console.WriteLine("Factorial=" & factorial)
Console.ReadLine()
End Sub
End Module
OUTPUT:
Enter a Number
5
Factorial=120

GUI Application Development using VB.Net (22034) Page 2


Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.

XIV. Exercise

1. Develop a program to calculate the Fibonacci Series of Give Number.


 Module Module1

Sub Main()
Fibonacci(10)
Console.ReadLine()
End Sub
Sub Fibonacci(ByVal n As Integer)
Dim a As Integer = 0
Dim b As Integer = 1
Dim i As Integer
For i = 0 To n - 1
Dim temp As Integer
temp = a
a = b
b = temp + b
Console.WriteLine(a)
Next
End Sub
End Module
OUTPUT:
1
1
2
3
5
8
13
21
34
55

2. Develop a program to print the reverse of any number using Sub procedure.
 Module Module1
Sub Main()
Dim num As Integer
Console.WriteLine("Enter Number")
num = Console.ReadLine()
reverse(num)
Console.ReadLine()
End Sub
Sub reverse(ByVal num As Integer)
Dim number = num
Dim result As Integer
While number > 0

GUI Application Development using VB.Net (22034) Page 3


Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.

num = number Mod 10


result = result * 10 + num
number = number \ 10
End While
Console.WriteLine("" & result)
End Sub
End Module
OUTPUT:
Enter Number
123
Reverse Number =321

GUI Application Development using VB.Net (22034) Page 4


Practical No. 16: Write a program to demonstrate use of Simple Function and parameterized
Function.

Practical No 16

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/visual-basic/language-
reference/statements/function-statement
 https://www.tutorialspoint.com/vb.net/vb.net_functions.htm

XI. Program Code


1. Write a program using Simple Function and Parameterized Function.
 Module Module1
Sub Main()
show()
Dim a, b As Integer
Console.WriteLine("Enter Two Numbers")
a = Console.ReadLine()
b = Console.ReadLine()
Add(a, b)
Console.WriteLine("Addition is = " & Add(a, b))
Console.ReadLine()
End Sub
Public Function show()
Console.WriteLine("This is Simple Function")
End Function
Public Function Add(ByVal i As Integer, ByVal j As Integer)
Dim sum As Integer
sum = i + j
Return sum
End Function
End Module

XII. Results (output of the program)


This is Simple Function
Enter Two Numbers
45
65
Addition is = 110

GUI Application Development using VB.Net (22034) Page 1


Practical No. 16: Write a program to demonstrate use of Simple Function and parameterized
Function.

XIII. Practical related Questions


1. Function returns a value (TRUE / FALSE).
 Function returns a value - True

2. Error – ‘Tyep Expected’


 Corrected Code
Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Dim result As Integer
If (num1 > num2) Then
result = num1
Else
result = num2
End If
FindMax = result
End Function

XIV. Exercise
1. Write a program to identify maximum number using parameterized function.
(Use two Textbox for input a integer number and display output in Message Box)

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim a, b As Integer
Dim res As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Call findmax(a, b)
res = findmax(a, b)
MessageBox.Show("Maximum Number is" & res)
Console.ReadLine()
End Sub
Private Function findmax(ByVal num1 As Integer, ByVal num2 As Integer)
Dim result As Integer

If (num1 > num2) Then


result = num1
Else
result = num2
End If
findmax = result
End Function
End Class

GUI Application Development using VB.Net (22034) Page 2


Practical No. 16: Write a program to demonstrate use of Simple Function and parameterized
Function.

OUTPUT:

2. Write a program using recursion(Factorial).


 Module Module1
Sub Main()
Dim n As Integer
Console.WriteLine("Enter Number=")
n = Console.ReadLine()
Console.WriteLine("Result=")
Console.WriteLine(Fact(n))
Console.ReadLine()
End Sub
Function Fact(ByVal n As Integer)
If n = 0 Then
Fact = 1
Else
Fact = n * Fact(n - 1)
End If
End Function
End Module
OUTPUT:
Enter Number=
5
Result=
120

GUI Application Development using VB.Net (22034) Page 3


Practical No. 17: Understand the Concept of Class and Object of Class.

Practical No 17

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/visual-basic/language-
reference/statements/function-statement
 https://www.tutorialspoint.com/vb.net/vb.net_functions.htm

XI. Program Code


1. Write a program using the concept of class & object in VB.Net.
 Module Module1
Sub Main()
Dim obj As New Test 'creating a object obj for Test Class
obj.disp() 'Calling the disp method using obj
Console.ReadLine()
End Sub
End Module
Public Class Test
Sub disp()
Console.WriteLine("Welcome to VB.NET")
End Sub
End Class

XII. Results (output of the program)


Welcome to VB.NET

XIII. Practical related Questions


1. Find output in following code.
 4

2. Find Error in following code.


Module Module1
Sub Main()
Dim b As B = New B(5)
B = Display()

Dim c As C = New C(5)


B = Display()
End Sub
 Compilation error (line 3, col 0): Type 'B' is not defined.
Compilation error (line 4, col 0): 'Display' is not declared. It may be inaccessible due to its protectio
n level.
Compilation error (line 6, col 0): Type 'C' is not defined.
Compilation error (line 7, col 0): 'Display' is not declared. It may be inaccessible due to its protectio
n level.

GUI Application Development using VB.Net (22034) Page 1


Practical No. 17: Understand the Concept of Class and Object of Class.

XIV. Exercise
1. Write a program to identify Volume of Box Class, with three data members, length,
breadth and height.
 Module Module1
Sub Main()
Dim obj As Box = New Box()
Dim vol As Integer
vol = obj.volume(2, 4, 4)
Console.WriteLine("Length =" & obj.l)
Console.WriteLine("Breadth =" & obj.b)
Console.WriteLine("Height =" & obj.h)
Console.WriteLine("Volume =" & vol)
Console.ReadLine()
End Sub
Class Box
Public l, b, h As Integer
Function volume(ByVal i As Integer, ByVal j As Integer,
_ByVal k As Integer)
Dim v As Integer
l = i
b = j
h = k
v = l * b * h
Return v
End Function
End Class
End Module

Output:

2. Implement a program to accept values from Combo Box and Display average of this in
message box using class.

GUI Application Development using VB.Net (22034) Page 2


Practical No. 17: Understand the Concept of Class and Object of Class.

Public Class Form1

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


Handles MyBase.Load
ComboBox1.Items.Add(5)
ComboBox1.Items.Add(8)
ComboBox1.Items.Add(12)
ComboBox1.Items.Add(20)
ComboBox1.Items.Add(32)

ComboBox2.Items.Add(6)
ComboBox2.Items.Add(11)
ComboBox2.Items.Add(17)
ComboBox2.Items.Add(24)
ComboBox2.Items.Add(36)
End Sub

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


Handles Button1.Click
Dim average As Single
average = (Val(ComboBox1.Text) + Val(ComboBox2.Text)) / 2
MsgBox("Average = " & average)
End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 3


Practical No.18: Implement a Program For Class Constructor and Destructor To De-Allocate
Memory.

Practical No 18

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


 https://docs.microsoft.com/en-us/dotnet/visual-basic/language-
reference/statements/function-statement
 https://www.tutorialspoint.com/vb.net/vb.net_functions.htm

XI. Program Code


1. Write a program to demonstrate the use of constructor & destructor.
 A) Constructor-
Module Module1
Sub Main()
Dim obj As New syco
obj.show()
Console.ReadLine()
End Sub
Public Class syco
Public Function show()
Console.WriteLine("This is base class")
End Function
Sub New()
Console.WriteLine("Constructor Executed")
End Sub
End Class
End Module

OUTPUT:
Constructor Executed
This is base class

Module Module1
Sub Main()
Dim obj As New syco
obj.show()
End Sub
End Module
Public Class syco
Public Function show()
Console.WriteLine("This is base Class")
End Function
Protected Overrides Sub Finalize()
Console.WriteLine("Destructor executing here")
Console.ReadLine()
End Sub
End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No.18: Implement a Program For Class Constructor and Destructor To De-Allocate
Memory.

OUTPUT:
This is base class
Destructor executing here

XII. Results (output of the program)


a. Constructor Executed
This is base class
b. This is base class
Destructor executing here

XIII. Practical related Questions


1. Find output in following code.
 40

2. Find Error in following code.


Imports System.Console
Module Module1
Sub Main()
Dim obj As New Destroy()
End Sub
End Module
Public Class Destroy
Protected Overrides Finalize()
Write(“VB.NET”)
Read()
End Sub
End Class
 Error 1 'Overrides' is not valid on a member variable declaration.
Warning 2 variable 'Finalize' conflicts with sub 'Finalize' in the base class 'Object' and
should be declared 'Shadows'.
Error 3 Declaration expected.
Error 4 Declaration expected.
Error 5 'End Sub' must be preceded by a matching 'Sub'.

GUI Application Development using VB.Net (22034) Page 2


Practical No.18: Implement a Program For Class Constructor and Destructor To De-Allocate
Memory.

XIV. Exercise
1. Implement a program to display any message at run time.(Using Constructor).
 Module Module1
Sub Main()
Dim obj As New sample
obj.display()
Console.ReadLine()
End Sub
Class sample
Public Sub New()
Console.WriteLine("This is Constructor")
End Sub
Sub display()
Console.WriteLine("This is Method")
End Sub
End Class
End Module

Output:

2. Implement a program to calculate area of circle using parameterized constructor.


 Module Module1
Sub Main()
Dim obj As New circle(2)
obj.area()
Console.ReadLine()
End Sub
Class circle
Dim p As Double = 3.14
Dim r, a As Double
Public Sub New(ByVal i As Integer)
r = i
End Sub
Sub area()
a = p * r * r
Console.WriteLine("Area of Circle = " & a)
End Sub
End Class
End Module

OUTPUT:
Area of Circle = 12.56

GUI Application Development using VB.Net (22034) Page 3


Practical No.19: Develop a Program For Inheritance.

Practical No 19

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program using concept of Inheritance.
 Module Module1

Sub Main()
Dim obj As New details
obj.show()
Console.ReadLine()
End Sub

End Module

Public Class student 'Base Class


Public branch As String = "Computer"
End Class

Public Class details 'Derived Class


Inherits student
Public Function show()
Console.WriteLine("Branch = " & branch)
Return 0
End Function
End Class

XII. Results (output of the program)


Branch = Computer

GUI Application Development using VB.Net (22034) Page 1


Practical No.19: Develop a Program For Inheritance.

XIII. Practical related Questions


1. Find output in following class.
 My Base Class
My Child Class

2. Find Error in following code.


Public Class Person
Public FirstName As String
Public LastName As String
Public DateOfBirth As Date
Public Gender As String
Public ReadOnly Property FullName() As String
Get
Get
Return FirstName & " " & LastName
End Get
End Property
End Class
Public Class Customer=>Inherits Person
Public CustomerID As String
Public CustomerType As String
End Class
 Error 1 'Sub Main' was not found in 'ConsoleApplication1.Module1'.

Warning2 Property 'FullName' doesn't return a value on all code paths. A null reference
exception could occur at run time when the result is used.

Error 3 Statement cannot appear within a method body. End of method assumed.

Error 4 End of statement expected.

GUI Application Development using VB.Net (22034) Page 2


Practical No.19: Develop a Program For Inheritance.

XIV. Exercise
1. Implement a program for inheritance where Student is Child Class and faculty is Base
class.(Take Appropriate variable in Base and Child class)
 Module Module1

Sub Main()
Dim s As New student
s.branch()
s.year()
Console.ReadLine()
End Sub

Class faculty
Dim b As String = "Computer"
Sub branch()
Console.WriteLine("Branch = " & b)
End Sub
End Class
Class student
Inherits faculty
Dim y As String = "Second Year"
Sub year()
Console.WriteLine("Year = " & y)
End Sub
End Class
End Module

Output:

GUI Application Development using VB.Net (22034) Page 3


Practical No.20 & 21: Implement a Program For Overloading & Overriding.

Practical No 20 & 21

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program to implement the concept of method overloading & overriding.
 Overloading:
Module Module1

Sub Main()
Dim res As New addition
Console.WriteLine("Overloaded Values of Class addition")
Console.WriteLine(res.add(10))
Console.WriteLine(res.add(35, 20))
Console.ReadLine()
End Sub

End Module

Public Class addition


Public i, j As Integer
Public Function add(ByVal i As Integer) As Integer
Return i
End Function

Public Function add(ByVal i As Integer, ByVal j As Integer) As Integer


Return i + j
End Function
End Class

Output:
Overloaded Values of Class addition
10
55

GUI Application Development using VB.Net (22034) Page 1


Practical No.20 & 21: Implement a Program For Overloading & Overriding.

Overriding:
Module Module1

Sub Main()
Dim obj As New child
Dim result As Integer
result = obj.add(10, 5)
Console.WriteLine("Overloaded Values of Class addition")
Console.WriteLine("Result =" & result)
Console.ReadLine()
End Sub
End Module
Public Class parent
Public Overridable Function add(ByVal i As Integer, ByVal j As Integer)
Return (i + j)
End Function
End Class

Public Class child


Inherits parent
Public Overrides Function add(ByVal i As Integer, ByVal j As Integer)
Console.WriteLine("Result of Addition =" & MyBase.add(12, 18))
Return (i + j)
End Function
End Class

Output:
Result of Addition =30
Overloaded Values of Class addition
Result =15

XII. Results (output of the program)


In the above overloading example the same function add is called to perform different
operations based on different arguments.
In the above overriding the parent class function add is overridden in the child class
using the MyBase.add(12, 18) statement. So first the overridden value is displayed, then the value
from child class is display.

GUI Application Development using VB.Net (22034) Page 2


Practical No.20 & 21: Implement a Program For Overloading & Overriding.

XIII. Practical related Questions


1. Find output of following Code.
 Area of the Circle : 31.181246
Area of the Rectangle : 20
2. Implement windows application for employee details using overriding method.
 Module Module1

Sub Main()
Dim obj As New EmpInfo
obj.ShowInfo()
Console.ReadLine()
End Sub

End Module
Public Class EmpPersonalDetails
Dim name As String
Dim address As String
Public Overridable Function ShowInfo()
Console.WriteLine("Employee Name" & name)
Console.WriteLine("Employee Address" & address)
End Function
End Class
Public Class EmpInfo
Inherits EmpPersonalDetails
Dim EmpId As Integer
Dim sallary As Integer
Dim JoinDate As Date
Overloads Function ShowInfo()
MyBase.ShowInfo()
Console.WriteLine("Employee ID" & EmpId)
Console.WriteLine("Employee Sallary" & sallary)
Console.WriteLine("Employee Joining Date" & JoinDate)
End Function
End Class
OUTPUT:
Employee Name
Employee Address
Employee ID0
Employee Sallary0
Employee Joining Date12:00:00 AM

GUI Application Development using VB.Net (22034) Page 3


Practical No.20 & 21: Implement a Program For Overloading & Overriding.

XIV. Exercise
1. Implement a windows application for show string concatenation using overload
method

Public Class Form1

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


Dim str1, str2, str3 As String
str1 = TextBox1.Text
str2 = TextBox2.Text

str3 = str1 + str2


TextBox3.Text = str3
End Sub

End Class

Output:

GUI Application Development using VB.Net (22034) Page 4


Practical No.22: Implement a Program to Demonstrate Shadowing In Inheritance.

Practical No 22

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program to using shadowing in inheritance.
 Module Module1
Sub Main()
Dim p As New parent
Dim c As New child
p.use()
c.use()
Console.WriteLine("________________________________")
p.disp()
c.disp()
Console.ReadLine()
End Sub
Public Class parent
Public Sub disp()
Console.WriteLine("Parent")
End Sub
Public Sub use()
Me.disp()
End Sub
End Class
Public Class child
Inherits parent
Public Shadows Sub disp()
Console.WriteLine("Child")
End Sub
End Class
End Module

Output:
Parent
Parent
________________________________
Parent
Child

GUI Application Development using VB.Net (22034) Page 1


Practical No.22: Implement a Program to Demonstrate Shadowing In Inheritance.

XIII. Practical related Questions


1. Write output of following Code.

Class Shadow
Shared x As Integer = 1
Shared Sub Main()
Dim x As Integer = 10
Console.WriteLine("main:x" & x)
Console.WriteLine("main shadow x:" & Shadow.x)
End Sub
End Class

 Error 1 'Sub Main' was not found in 'ConsoleApplication22.Module1'.


ConsoleApplication22

2. Write output of following Code.

Public Class Form2


Dim x As Integer = 10
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim x As Integer = 30
MsgBox(x)
End Sub
End Class

 Error 1 Handles clause requires a WithEvents variable defined in the containing


type or one of its base types.

GUI Application Development using VB.Net (22034) Page 2


Practical No.22: Implement a Program to Demonstrate Shadowing In Inheritance.

XIV. Exercise
1. Implement the concept of shadowing through inheritance in a console application.
 Module Module1
Dim f As New first
Dim s As New second
Dim t As New third
Sub Main()
f.display()
s.display()
t.display()
Console.ReadLine()
End Sub
End Module
Public Class first
Public Sub display()
Console.WriteLine("This is First Year")
End Sub
End Class
Public Class second
Inherits first
Private Shadows Sub display()
Console.WriteLine("This is Second Year")
End Sub
End Class
Public Class third
Inherits second
Public Shadows Sub display()
Console.WriteLine("This is Third Year")
End Sub
End Class
OUTPUT:
This is First Year
This is First Year
This is Third Year

GUI Application Development using VB.Net (22034) Page 3


Practical No.23: Implement a Program to handle runtime errors using Exception handling.

Practical No 23

VIII. Resources required (Additional)


→ If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write any program using Exception handling.

Public Class Form1

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


Dim num1, num2, div As Integer
num1 = Val(TextBox1.Text)
num2 = Val(TextBox2.Text)
Try
div = num1 / num2
MsgBox("Division is" & div)
Catch ex As OverflowException
Console.WriteLine("Division of {0} by zero", num1)

End Try
End Sub
End Class

Output:

A first chance exception of type 'System.OverflowException' occurred in


WindowsApplication8.exe
Division of 5 by zero

GUI Application Development using VB.Net (22034) Page 1


Practical No.23: Implement a Program to handle runtime errors using Exception handling.

XIII. Practical related Questions


1. Write output of following Code.

Module Module1

Sub Main()
Try
Throw New Exception("Mega-error")
Catch ex As Exception
Console.WriteLine(ex.Message)

End Try
Console.ReadLine()
End Sub

End Module

Output:
Mega-error

2. Write output of following Code.

Module Module1

Sub Main()
Try
'Try to divide by zero.
Dim value As Integer = 1 / Integer.Parse("0")
'This statement is sadly not reached.
Console.WriteLine("Hi")
Catch ex As Exception
'Display the Message.
Console.WriteLine(ex.Message)

End Try
Console.ReadLine()
End Sub

End Module
Output:
Arithmetic operation resulted in an overflow.

GUI Application Development using VB.Net (22034) Page 2


Practical No.23: Implement a Program to handle runtime errors using Exception handling.

XIV. Exercise
1. Write a program for student registration using exception handling.

Public Class Form1

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


Try
If TextBox1.Text = "" Or TextBox2.Text = "" Then
Throw (New Exception("Fill Data"))
Else
MsgBox(TextBox1.Text & TextBox2.Text)
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
MsgBox("Thank You")
End Try
End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 3


Practical No.24: Understand the concept of ADO.Net

Practical No 24

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program using ADO.Net to the database.

Imports System.Data
Imports System.Data.OleDb

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data " &
"Source=C:\Users\Suresh\Documents\Visual Studio 2012 \ Projects \ Datagrid \
stud.mdb")
Conn.Open()
Dim cmd As New OleDbCommand("Select * From Marks", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Marks")
DataGrid1.CaptionText = "marks"
DataGrid1.DataSource = ds
DataGrid1.DataMember = "marks"

End Sub

End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No.24: Understand the concept of ADO.Net

Output:

XIII. Practical related Questions


1. Find error from following code
Dim con As New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0DataSource=D:\mydata.accdb;")

 Error 1 Type expected.


Error 2 'OleDbConnection' is a type and cannot be used as an expression.
Error 3 'Conn' is not declared. It may be inaccessible due to its protection level.

2. Write a connection string with MS-access using any database.


 Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDB.accdb

GUI Application Development using VB.Net (22034) Page 2


Practical No.24: Understand the concept of ADO.Net

XIV. Exercise
1. Design the windows application that will display the content of a table in MS-Access
database on DataGrid control using data adapter.

Imports System.Data
Imports System.Data.OleDb
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data” &
“Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\DataGrid1\student.mdb")
conn.Open()
Dim cmd As New OleDbCommand("Select *From Student", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Roll Call")
DataGrid1.CaptionText = "Student"
DataGrid1.DataSource = ds
DataGrid1.DataMember = "Roll Call"

End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 3


Practical No.25 & 26: Understand the concept of Data Adapter

Practical No 25 & 26

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program using data adapter to connect to the database.

Imports System.Data
Imports System.Data.OleDb

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data " &
"Source=C:\Users\Suresh\Documents\Visual Studio 2012 \ Projects \ Datagrid \
stud.mdb")
Conn.Open()
Dim cmd As New OleDbCommand("Select * From Marks", conn)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Marks")
DataGrid1.CaptionText = "marks"
DataGrid1.DataSource = ds
DataGrid1.DataMember = "marks"

End Sub

End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No.25 & 26: Understand the concept of Data Adapter

Output:

XIII. Practical related Questions


1. Find error from following code
Dim adp As
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0DataSource=D:\mydata.accdb;")

 Error 1 Type expected.


Error 2 'OleDbConnection' is a type and cannot be used as an expression.
Error 3 'Conn' is not declared. It may be inaccessible due to its protection level.

2. Write a data adapter syntax using a MS-access code with a student table.
 Dim da As OleDbDataAdapter
Da=New OleDbDataAdapter(cmd)

GUI Application Development using VB.Net (22034) Page 2


Practical No.25 & 26: Understand the concept of Data Adapter

XIV. Exercise
1. Design the windows application in MS-Access which have navigation (Next, First,
Previous, Last).

Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Db1DataSet.student' table. You can
move, or remove it, as needed.
Me.StudentTableAdapter.Fill(Me.Db1DataSet.student)
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Nav2\db1.mdb")
con.Open()
cmd = New OleDbCommand("Select * From student", con)
da = New OleDbDataAdapter(cmd)
da.Fill(ds, "student")
Me.TextBox1.DataBindings.Add("text", ds, "student.RollNo")
Me.TextBox2.DataBindings.Add("text", ds, "student.Name")
Me.TextBox3.DataBindings.Add("text", ds, "student.Marks")
End Sub

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


Me.BindingContext(ds, "student").Position = 0
End Sub

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


Me.BindingContext(ds, "student").Position = Me.BindingContext(ds,
"student").Position + 1
End Sub

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


Me.BindingContext(ds, "student").Position = Me.BindingContext(ds,
"student").Position - 1

GUI Application Development using VB.Net (22034) Page 3


Practical No.25 & 26: Understand the concept of Data Adapter

End Sub

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


Me.BindingContext(ds, "student").Position=Me.BindingContext(ds,"student").Count-1
End Sub
End Class
OUTPUT:

2. Develop a windows application that will contain multiple tables in a single dataset.

Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter

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


Button1.Click
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Multiple
Table\db1.mdb")
con.Open()

Dim cmd1 As New OleDbCommand("Select * From student", con)

GUI Application Development using VB.Net (22034) Page 4


Practical No.25 & 26: Understand the concept of Data Adapter

Dim cmd2 As New OleDbCommand("Select * From subjects", con)

Dim da1 As New OleDbDataAdapter(cmd1)


Dim da2 As New OleDbDataAdapter(cmd2)

Dim ds As New DataSet

DataGrid1.CaptionText = "Student Record"


DataGrid2.CaptionText = "Subject Details"

da1.Fill(ds, "student")
da2.Fill(ds, "subjects")

DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"

DataGrid2.DataSource = ds
DataGrid2.DataMember = "subjects"
End Sub
End Class
OUTPUT:

GUI Application Development using VB.Net (22034) Page 5


Practical No.27: Understand the concept of select & Insert data in database table.

Practical No 27

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program to insert the data & retrieve the data from database.

Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter

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


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Insert and
Retrieve\db1.mdb")
con.Open()
Dim InsertString As String
InsertString = "Insert into student(RollNo, Name, Marks) values('" + txtRollNo.Text +
"','" + txtName.Text + "' ,'" + txtMarks.Text + "')"
Dim cmd As New OleDbCommand(InsertString, con)
cmd.ExecuteNonQuery()
MsgBox(" Record Successfully Inserted")
con.Close()
End Sub

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


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Insert and
Retrieve\db1.mdb")
con.Open()
Dim cmd As New OleDbCommand("Select * From student", con)

GUI Application Development using VB.Net (22034) Page 1


Practical No.27: Understand the concept of select & Insert data in database table.

Dim da As New OleDbDataAdapter(cmd)


DataGrid1.CaptionText = "Student Marks"
da.Fill(ds, "student")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "student"
con.Close()
End Sub

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


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Insert and
Retrieve\db1.mdb")
con.Open()
Dim DeleteString As String
DeleteString = "Delete From student where RollNo ='" + txtRollNo.Text + "'"
Dim cmd As New OleDbCommand(DeleteString, con)
cmd.ExecuteNonQuery()
MsgBox(" Record Successfully Deleted")
con.Close()
End Sub

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


Close()
End Sub
End Class

Output:

XIII. Practical related Questions


1. Write syntax of command object execute method.

1. ExecuteScaler():
dr = cmd.ExecuteScaler();
2. ExecuteReader():
dr = cmd.ExecuteReader();
3. ExecuteNonQuery():
dr = cmd.ExecuteNonQuery();
GUI Application Development using VB.Net (22034) Page 2
Practical No.27: Understand the concept of select & Insert data in database table.

XIV. Exercise
1. Design a simple Windowsform for accepting the details of Employee. Using the
connected architecture of ADO.NET, perform the following operations:
 Insert Record
 Search Record
 Update Record
 Delete Record

Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private Sub btnIns_Click(sender As Object, e As EventArgs) Handles btnIns.Click
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\Employee\Employee.mdb")
con.Open()
If txtNo.Text = "" Then
MsgBox("Please Enter Employee Number")
Else
Dim InsertString As String
InsertString = "Insert into Employee(Emp_No, Emp_Name, Address,
Date_of_joining) values('" + txtNo.Text + "','" + txtName.Text + "' ,'" + txtAdd.Text + "','"
+ txtDOJ.Text + "')"
Dim cmd As New OleDbCommand(InsertString, con)
cmd.ExecuteNonQuery()
MsgBox(" Record Successfully Inserted")
txtNo.Clear()
txtName.Clear()
txtAdd.Clear()
txtDOJ.Clear()

con.Close()
End If
End Sub

GUI Application Development using VB.Net (22034) Page 3


Practical No.27: Understand the concept of select & Insert data in database table.

Private Sub btnDel_Click(sender As Object, e As EventArgs) Handles btnDel.Click


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\Employee\Employee.mdb")
con.Open()
If txtNo.Text = "" Then
MsgBox("Please Enter Employee Number")
Else
Dim DeleteString As String
DeleteString = "Delete From Employee where Emp_No ='" + txtNo.Text + "'"
Dim cmd As New OleDbCommand(DeleteString, con)
cmd.ExecuteNonQuery()
MsgBox(" Record Successfully Deleted")
txtNo.Clear()
txtNo.Focus()
con.Close()
End If

End Sub

Private Sub btnUpd_Click(sender As Object, e As EventArgs) Handles btnUpd.Click


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\Employee\Employee.mdb")
con.Open()
If txtNo.Text <> "" Then
Dim UpdateString As String
UpdateString = "Update Employee SET Emp_No ='" + txtNo.Text +
"',Emp_Name='" + txtName.Text + "',Address='" + txtAdd.Text + "',Date_of_joining='" +
txtDOJ.Text + "' Where Emp_No ='" + txtNo.Text + "'"
Dim cmd As New OleDbCommand(UpdateString, con)
cmd.ExecuteNonQuery()
MsgBox(" Record Successfully Updated")
txtNo.Clear()
txtName.Clear()
txtAdd.Clear()
txtDOJ.Clear()
con.Close()
Else
MsgBox(" Please Enter Employment Number")
End If
End Sub

Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click


Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\Employee\Employee.mdb")
con.Open()
Dim cmd As New OleDbCommand("Select * From Employee", con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
DataGrid1.CaptionText = "Employee Record"
da.Fill(ds, "Employee")

GUI Application Development using VB.Net (22034) Page 4


Practical No.27: Understand the concept of select & Insert data in database table.

DataGrid1.DataSource = ds
DataGrid1.DataMember = "Employee"
con.Close()
End Sub

Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles


btnSearch.Click
If txtNo.Text = "" Then
MsgBox("Please Enter Employee Number")
Else
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio
2012\Projects\Employee\Employee.mdb")
con.Open()
Dim cmd As New OleDbCommand("Select * From Employee where Emp_No like '" +
txtNo.Text + "'", con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet
DataGrid1.CaptionText = "Employee Record"
da.Fill(ds, "Employee")
DataGrid1.DataSource = ds.Tables("Employee")
da.Dispose()
con.Close()
txtNo.Clear()
txtNo.Focus()
End If
End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 5


Practical No.28, 29 & 30: Understand the concept of data Binding.

Practical No 28, 29 & 30

VIII. Resources required (Additional)


 If any web resources required.

X. Resources used (Additional)


https://www.tutorialspoint.com/vb.net/vb.net

XI. Program Code


1. Write a program using data binding in VB.Net

Imports System.Data.OleDb
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim con As OleDbConnection


Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter

con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data


Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Data
binding\Student.mdb")
con.Open()

cmd = New OleDbCommand("Select * From student", con)


da = New OleDbDataAdapter(cmd)
da.Fill(ds, "student")

TextBox1.DataBindings.Add("Text", ds, "student.Roll_No")


TextBox2.DataBindings.Add("Text", ds, "student.Name")
TextBox3.DataBindings.Add("Text", ds, "student.Marks")

End Sub
End Class

GUI Application Development using VB.Net (22034) Page 1


Practical No.28, 29 & 30: Understand the concept of data Binding.

Output:

XIII. Practical related Questions


1. Write syntax of simple binding for text box.
 TextBox1.DataBindings.Add(“Text”, Dataset11, ”table.empid”)
2. Write a syntax of complex binding for combo box.
 ComboBox1.DataSource=ds.Tables(“table_name”)
ComboBox1.DisplayMember=”field_name”

XIV. Exercise
1. Design a windows application for student name and college name using a simple data
binding use appropriate database.

Imports System.Data.OleDb
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Dim con As OleDbConnection
Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\student data
binding\db1.mdb")
con.Open()

GUI Application Development using VB.Net (22034) Page 2


Practical No.28, 29 & 30: Understand the concept of data Binding.

cmd = New OleDbCommand("Select * From Student", con)


da = New OleDbDataAdapter(cmd)
da.Fill(ds, "Student")
TextBox1.DataBindings.Add("text", ds, "Student.Name")
TextBox2.DataBindings.Add("text", ds, "Student.College")
End Sub
End Class

OUTPUT:

2. Design a windows application for bank customer record & display it using Complex
data binding use appropriate database.

Imports System.Data.OleDb
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim con As OleDbConnection


Dim ds As New DataSet
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter

con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data


Source=C:\Users\Suresh\Documents\Visual Studio 2012\Projects\Bank Customer
Record\db1.mdb")
con.Open()

cmd = New OleDbCommand("Select * From Bank_Details", con)


da = New OleDbDataAdapter(cmd)
da.Fill(ds, "Bank_Details")

ComboBox1.DataSource = ds.Tables("Bank_Details")

GUI Application Development using VB.Net (22034) Page 3


Practical No.28, 29 & 30: Understand the concept of data Binding.

ComboBox2.DataSource = ds.Tables("Bank_Details")
ComboBox3.DataSource = ds.Tables("Bank_Details")

ComboBox1.DisplayMember = "Acc_No"
ComboBox2.DisplayMember = "Balance"
ComboBox3.DisplayMember = "Branch"

End Sub
End Class

OUTPUT:

GUI Application Development using VB.Net (22034) Page 4

You might also like