0% found this document useful (0 votes)
25 views

126VBDOTNET

1. The document describes 5 programming assignments involving developing GUI applications in .NET. The first assignment involves building a ticket booking application that calculates total tickets booked. The second creates a Gmail registration form. The third implements an enumeration. The fourth builds a Tic-Tac-Toe game. The fifth develops a basic calculator application. Code snippets are provided as solutions for each assignment.

Uploaded by

Shyam Shobhasana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

126VBDOTNET

1. The document describes 5 programming assignments involving developing GUI applications in .NET. The first assignment involves building a ticket booking application that calculates total tickets booked. The second creates a Gmail registration form. The third implements an enumeration. The fourth builds a Tic-Tac-Toe game. The fifth develops a basic calculator application. Code snippets are provided as solutions for each assignment.

Uploaded by

Shyam Shobhasana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

SYBCA DIV – 02 .

NET PROGRAMMING 126

1. Develop GUI application to book a ticket and calculate a total number of booked tickets
without using database.
ANSWER :
Public Class Ass_1

Dim total As Double = 0

Private Sub Total_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btntotal.Click
If Weekdays_50.Checked = True Then
total = total + 50
ElseIf Weekends_100.Checked = True Then
total = total + 100
End If

If Dancing_40.Checked = True Then


total = total + 40
End If
If Singing_50.Checked = True Then
total = total + 50
End If
If Gamezone_80.Checked = True Then
total = total + 80
End If
If Sports_90.Checked = True Then
total = total + 90
End If

Totalans.Text = total * Convert.ToDouble(noofti.Text)

End Sub
End Class
OUTPUT :

1
SYBCA DIV – 02 .NET PROGRAMMING 126

2. Develop a Gmail Registration form and display the data on label.


ANSWER :
Public Class Ass_2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
If tb1.Text = "" Or tb2.Text = "" Or tb3.Text = "" Or tb4.Text = "" Or tb5.Text = "" Then
MessageBox.Show("Enter Register Information", "Warning",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
If tb4.Text = tb5.Text Then
MessageBox.Show("Success Register", "Register", MessageBoxButtons.OK,
MessageBoxIcon.Information)
registration_detail.Show()
Else
MessageBox.Show("Does Not Same Password", "Register", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End If

Assignment_1.registration_detail.Label1.Text = "Your Registration Detail" + vbCrLf + gb1.Text + " : "


+ tb1.Text + vbCrLf + gb2.Text + " : " + tb2.Text + vbCrLf + gb3.Text + " : " + tb3.Text + vbCrLf +
gb4.Text + " : " + tb4.Text + vbCrLf

If lblm.Checked Then
Assignment_1.registration_detail.Label1.Text += lblgender.Text + lblm.Text + vbCrLf +
lblhobbies.Text
Else
Assignment_1.registration_detail.Label1.Text += lblgender.Text + lblf.Text + vbCrLf +
lblhobbies.Text
End If

For Each item In chklist.CheckedItems


Assignment_1.registration_detail.Label1.Text += item + " "
Next
End Sub
End Class

2
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

3. Write practical enumeration.


ANSWER :
Public Class Ass_3
Enum z
a
b = 20
c
d = 40
End Enum

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
TextBox1.Text = z.a
TextBox2.Text = z.b
TextBox3.Text = z.c
TextBox4.Text = z.d
End Sub
End Class

3
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

4. Write a practical of Tic-Tac-Toe game.


ANSWER :
Public Class Ass_4

Private Sub tictac_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Label1.Text = "player 1 : X"
End Sub

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click,Button2.Click, Button3.Click, Button4.Click, Button5.Click,
Button6.Click, Button7.Click, Button8.Click,Button9.Click
Dim btn1 As Button = sender
display(btn1)
End Sub

Sub display(ByVal btn As Button)


If btn.Text = "" Then
If Label1.Text = "player 1 : X" Then
btn.Text = "X"
Label1.Text = "player 2 : O"
Else
btn.Text = "O"
Label1.Text = "player 1 : X"
End If
End If
checkwinner()
End Sub

Sub checkwinner()
If ((Button1.Text = Button2.Text And Button2.Text = Button3.Text And Button1.Text <> ""
And Button2.Text <> "" And Button3.Text <> "") Or _
(Button4.Text = Button5.Text And Button5.Text = Button6.Text And Button4.Text <> "" And
Button5.Text <> "" And Button6.Text <> "") Or _

4
SYBCA DIV – 02 .NET PROGRAMMING 126

(Button7.Text = Button8.Text And Button8.Text = Button9.Text And Button7.Text <> "" And
Button8.Text <> "" And Button9.Text <> "") Or _
(Button1.Text = Button4.Text And Button4.Text = Button7.Text And Button1.Text <> "" And
Button4.Text <> "" And Button7.Text <> "") Or _
(Button2.Text = Button5.Text And Button5.Text = Button8.Text And Button2.Text <> "" And
Button5.Text <> "" And Button8.Text <> "") Or _
(Button3.Text = Button6.Text And Button6.Text = Button9.Text And Button3.Text <> "" And
Button6.Text <> "" And Button9.Text <> "") Or _
(Button1.Text = Button5.Text And Button5.Text = Button9.Text And Button1.Text <> "" And
Button5.Text <> "" And Button9.Text <> "") Or _
(Button3.Text = Button5.Text And Button5.Text = Button7.Text And Button3.Text <> "" And
Button5.Text <> "" And Button7.Text <> "")) Then

If (Label1.Text = "player 1 : X") Then


MessageBox.Show("Player 2 is win", "Result", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("Player 1 is win", "Result", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
clearcontrol()
ElseIf (Button1.Text <> "" And Button2.Text <> "" And Button3.Text <> "" And Button4.Text
<> "" And Button5.Text <> "" And Button6.Text <> "" And Button7.Text <> "" And
Button8.Text <> "" And Button9.Text <> "") Then
MessageBox.Show("No body winner", "Result", MessageBoxButtons.OK,
MessageBoxIcon.Information)
clearcontrol()
End If
End Sub

Sub clearcontrol()
Button1.Text = ""
Button2.Text = ""
Button3.Text = ""
Button4.Text = ""
Button5.Text = ""
Button6.Text = ""
Button7.Text = ""
Button8.Text = ""
Button9.Text = ""
Label1.Text = "player 1 : X"
End Sub
End Class

5
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

5. Write a practical of calculator.


ANSWER :
Imports System.String
Public Class Ass_5

Dim a As Double = 0
Dim sign As String
Dim opt As Integer = 0

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click,Button2.Click, Button3.Click, Button4.Click, Button5.Click,
Button6.Click, Button7.Click, Button8.Click,Button9.Click
Dim btn As Button
btn = sender
gnumber(btn.Text)
End Sub

Sub gnumber(ByVal num As String)


If opt = 0 Then
TextBox1.Text = TextBox1.Text & num
Else
opt = 0
a = Double.Parse(TextBox1.Text)
TextBox1.Text = num
End If
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button16.Click

6
SYBCA DIV – 02 .NET PROGRAMMING 126

TextBox1.Clear()
a=0
sign = ""
opt = 0
End Sub

Sub calculate()
Select Case sign
Case "+"
TextBox1.Text = Convert.ToString(a + Double.Parse(TextBox1.Text))
Case "-"
TextBox1.Text = Convert.ToString(a - Double.Parse(TextBox1.Text))
Case "*"
TextBox1.Text = Convert.ToString(a * Double.Parse(TextBox1.Text))
Case "/"
TextBox1.Text = Convert.ToString(a / Double.Parse(TextBox1.Text))
Case "mod"
TextBox1.Text = Convert.ToString(a Mod Double.Parse(TextBox1.Text))
Case "sqrt"
If TextBox1.Text <> 0 Then
TextBox1.Text =
Convert.ToString(System.Math.Sqrt(Convert.ToDouble(TextBox1.Text)))
End If
End Select
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button11.Click
opt = 1
calculate()
sign = "+"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button10.Click
opt = 1
calculate()
sign = "-"
End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button13.Click
opt = 1
calculate()
sign = "*"

7
SYBCA DIV – 02 .NET PROGRAMMING 126

End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button12.Click
opt = 1
calculate()
sign = "/"
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button19.Click
opt = 1
calculate()
sign = "mod"
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button18.Click
opt = 1
sign = "sqrt"
calculate()
sign = ""
End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button17.Click
If TextBox1.Text <> "" Then
Dim l As Integer = TextBox1.Text.Length
TextBox1.Text = TextBox1.Text.Substring(0, l - 1)
End If
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button14.Click
opt = 1
calculate()
sign = ""
End Sub
End Class

8
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

6. Write a practical of Message box and Input box.


ANSWER :
Public Class Ass6

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
If TextBox1.Text = "" Then
MessageBox.Show("Enter Message", "MessageBOx", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show(TextBox1.Text, "MessageBOx", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Dim a As String = InputBox("Enter Message")
If a = "" Then
a = MessageBox.Show("Enter Message", "MessageBOx",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(a, "MessageBOx", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End Sub
End Class

9
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

7. Write a practical of string function.


ANSWER :
Imports System.IO
Public Class Ass_7
Dim s() As String
Dim sa() As String = {"ccc", "bbb", "aaa"}
Dim parts() As String
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
s = Filter(sa, "bbb", False)
parts = Split("My Name Is Rutvik Tanti", " ")
Label2.Text = ("Asc = " & Asc("A") & vbCrLf &
"Chr = " & Chr(65) & vbCrLf &
"Lcase = " & LCase("RUTVIK") & vbCrLf &
"UCase = " & UCase("rutvik") & vbCrLf &
"Instr = " & InStr(3, "This is VB.Net") & vbCrLf &
"StrComp = " & StrComp("Rutvik", "RUTVIK", CompareMethod.Text) &
vbCrLf &
"Left = " & Microsoft.VisualBasic.Strings.Left("August 28,2012", 3) & vbCrLf
&
"Right = " & Microsoft.VisualBasic.Strings.Right("August 28,2012", 4) &
vbCrLf &
"Mid = " & Mid("08 August,2012", 4.8) & vbCrLf &

10
SYBCA DIV – 02 .NET PROGRAMMING 126

"Len = " & Len("Tanti Rutvik") & vbCrLf &


"StrDup = " & StrDup(5, "* ") & vbCrLf &
"StrConv = " & StrConv("rutvik tanti", VbStrConv.ProperCase) & vbCrLf &
"StrReverse = " & StrReverse("MADAM") & vbCrLf &
"Filter = " & s(0) & vbCrLf &
"Spilt = " & parts(3))
End Sub
End Class
OUTPUT :

8. Write a practical of mathematics function.


ANSWER :
Imports System.Math
Public Class ass_8
Private Sub bround_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles button.Click
Label1.Text = ("Abs = " & Abs(-1.01).ToString & vbCrLf &
"Int = " & Int(-1.01).ToString & vbCrLf &
"Fix = " & Fix(-1.1).ToString & vbCrLf &
"Round = " & Round(3.51, 1).ToString & vbCrLf &
"Oct = " & Oct(47).ToString & vbCrLf &
"Hex = " & Hex(47).ToString & vbCrLf &
"Pow = " & Pow(2, 3).ToString & vbCrLf &
"Sqrt = " & Sqrt(25).ToString)
End Sub
End Class

11
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

9. Write a practical of data type conversion function.


ANSWER :
Public Class Ass_9
Dim dbvar As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim DbVar As Double = 2.7118848418
Dim objVar As Object = CObj(DbVar)
Dim byVar As Byte
byVar = CByte(DbVar)
Dim DbInt As Double = 42.7118848418
Dim strVar As String = "Hello"

Label1.Text = ("CObj = " & objVar.ToString & vbCrLf &


"CByte = " & byVar.ToString & vbCrLf &
"CInt = " & CInt(DbInt).ToString & vbCrLf &
"CSng = " & CSng(DbVar).ToString & vbCrLf &
"CChar = " & CChar(strVar))
End Sub
End Class
OUTPUT :

12
SYBCA DIV – 02 .NET PROGRAMMING 126

10. Write a practical of data type checking function.


ANSWER :
Public Class Ass_10
Dim d1 As Date
Dim o1 As Object = "Visual"
Dim i1 As Integer
Dim db As Double
Dim o2 As Object = "Studio"
Dim testobj As Object = "new"
Dim testnum As Integer = 12
Dim teststr As String = "String"
Dim testvar As Object = System.DBNull.Value
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Label1.Text = ("IsDate(d1) : " & IsDate(d1) & vbCrLf &
"IsDate(1) : " & IsDate(1) & vbCrLf &
"IsNumeric(db) : " & IsNumeric(db) & vbCrLf &
"IsNumeric(2) : " & IsNumeric(2) & vbCrLf &
"IsNumeric(i1) : " & IsNumeric(i1) & vbCrLf &
"IsReference(testobj) : " & IsReference(testobj) & vbCrLf &
"IsReference(testnum) : " & IsReference(testnum) & vbCrLf &
"IsReference(teststr) : " & IsReference(teststr) & vbCrLf &
"IsDBNull(testvar) : " & IsDBNull(testvar) & vbCrLf &
"IsDBNull(testvar) : " & IsDBNull(testvar))
End Sub
End Class
OUTPUT :

11. Write a practical of option statements.


ANSWER :
Option Explicit Off
Public Class Ass_11
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click

13
SYBCA DIV – 02 .NET PROGRAMMING 126

s = "How are you"


MessageBox.Show(s + vbCrLf + "Without dim declare store" + vbCrLf + " 'how are
you' one variable", "Option Statements Example")
End Sub
End Class
OUTPUT :

12. Write a practical of keyboard and mouse event.


ANSWER :
KeyBoard Event

Public Class keyboard_event


Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles
TextBox1.KeyDown
If (e.KeyCode >= Keys.A And e.KeyCode <= Keys.Z) Then
Label2.Text = "Key Down Event"
End If
End Sub

Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


TextBox1.KeyPress
If Not Char.IsLetter(e.KeyChar) AndAlso Not e.KeyChar = ChrW(Keys.Space)
AndAlso Not e.KeyChar = ChrW(Keys.Back) Then e.Handled = True
End If
End Sub

Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles


TextBox1.KeyUp
MessageBox.Show("Key up event execute")
End Sub
End Class

14
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

Mouse Event
Public Class Ass_12

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


MyBase.Load
Label1.Focus()
End Sub

Private Sub Form1(ByVal sender As Object, ByVal e As EventArgs) Handles


Label1.MouseDoubleClick
TextBox1.Text = "Label Double click Event"
Label2.Text = "Mouser Arrow Move to Any side"
End Sub

Private Sub me1(ByVal sender As Object, ByVal e As EventArgs) Handles


Label1.MouseEnter
Label1.ForeColor = Color.Blue
TextBox1.Text = "Label Mouse Enter Event"
Label2.Text = "Label Double click"
End Sub

Private Sub ml(ByVal sender As Object, ByVal e As EventArgs) Handles


Label1.MouseLeave
Label1.ForeColor = Color.Black
MessageBox.Show("Label Mouse Leave Event")
TextBox1.Text = ""
End Sub
End Class

15
SYBCA DIV – 02 .NET PROGRAMMING 126

OUTPUT :

13. Write a practical of exception handling (example structure and unstructured).


ANSWER :
Public Class Ass_13
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim a, b, total As Double
On Error GoTo err
a = TextBox1.Text
b = TextBox2.Text
total = a / b
err:
If (a = 0 Or b = 0) Then
MessageBox.Show("divide by zero error", "Unstructure")
Else
MessageBox.Show(total)
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Dim a1, b1 As Integer
Dim total1 As Integer = 0

Try
a1 = TextBox1.Text
b1 = TextBox2.Text
total1 = a1 / b1
MessageBox.Show(total1)
Catch ex As Exception
MessageBox.Show("divide by zero error", "structure")
End Try

16
SYBCA DIV – 02 .NET PROGRAMMING 126

End Sub
End Class
OUTPUT :

14. Write a practical of Groupbox and Panel.


ANSWER :
Public Class Ass_14
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton1.CheckedChanged
Me.ForeColor = Color.Red
TextBox1.Text = "Red"
End Sub

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


System.EventArgs) Handles RadioButton2.CheckedChanged
Me.ForeColor = Color.Green
TextBox1.Text = "Green"
End Sub

Private Sub Ass_14_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load

17
SYBCA DIV – 02 .NET PROGRAMMING 126

Me.RadioButton3.Checked = True
TextBox1.Text = "Default"
End Sub

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


System.EventArgs) Handles RadioButton3.CheckedChanged
Me.ForeColor = Color.Black
TextBox1.Text = "Default"
End Sub
End Class
OUTPUT :

15. Write a practical of Listbox, Combobox, Checklistbox.


ANSWER :
Public Class Ass_15

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
ListBox1.Items.Add("Earth")
ListBox1.Items.Add("Mercury")
ListBox1.Items.Add("Mars")
ListBox1.Items.Add("Jupiter")
ListBox1.Items.Add("Venus")
ListBox1.Items.Add("Neptune")
ListBox1.Items.Add("Uranus")

ComboBox1.Items.Add("Earth")
ComboBox1.Items.Add("Mercury")
ComboBox1.Items.Add("Mars")
ComboBox1.Items.Add("Jupiter")
ComboBox1.Items.Add("Venus")
ComboBox1.Items.Add("Neptune")
ComboBox1.Items.Add("Uranus")

CheckedListBox1.Items.Add("Earth")
CheckedListBox1.Items.Add("Mercury")

18
SYBCA DIV – 02 .NET PROGRAMMING 126

CheckedListBox1.Items.Add("Mars")
CheckedListBox1.Items.Add("Jupiter")
CheckedListBox1.Items.Add("Venus")
CheckedListBox1.Items.Add("Neptune")
CheckedListBox1.Items.Add("Uranus")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
Label1.Text = "Selected is " + ListBox1.SelectedItem.ToString()
MessageBox.Show(Label1.Text, "Information")
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Label2.Text = "Selected is " + ComboBox1.SelectedItem.ToString()
MessageBox.Show(Label2.Text, "Information")
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Dim a1 As String = ""
For Each item In CheckedListBox1.CheckedItems
a1 = a1 + item + vbCrLf
Next
Label3.Text = "Selected is " + vbCrLf + a1
MessageBox.Show(Label3.Text, "Information")
End Sub
End Class
OUTPUT :

19
SYBCA DIV – 02 .NET PROGRAMMING 126

16. Write a practical of Ritchtextbox.


ANSWER :
Public Class Ass_16
Private Sub Ass_16_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
RichTextBox1.Text = "Hello, world!" + vbCrLf + "RichTextBox Example"
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = 5
RichTextBox1.SelectionColor = Color.Blue
RichTextBox1.SelectionFont = New Font("Arial", 12, FontStyle.Bold)

RichTextBox1.SelectionStart = 14
RichTextBox1.SelectionLength = 19
RichTextBox1.SelectionColor = Color.Blue
RichTextBox1.SelectionFont = New Font("Arial", 12, FontStyle.Bold)
End Sub

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


System.EventArgs) Handles SaveToolStripMenuItem.Click
SaveFileDialog1.Title = "Save"
SaveFileDialog1.Filter = "Rich Text Files(*.rtf)|*.rtf"
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, RichTextBox1.Text,
False)
Me.Text = SaveFileDialog1.FileName
End If
End Sub
End Class
OUTPUT :

17. Write a practical of Picturebox.


ANSWER :
Public Class picturebox
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Image = Image.FromFile("C:\Users\91728\Downloads\R.jpg")

20
SYBCA DIV – 02 .NET PROGRAMMING 126

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
End Class

OUTPUT :

18. Write a practical of Listview.


ANSWER :
Public Class Ass_18

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
Dim ListItem1 As ListViewItem
ListItem1 = ListView1.Items.Add("Android")
Dim ListItem2 As ListViewItem
ListItem2 = ListView1.Items.Add("C")
Dim ListItem3 As ListViewItem
ListItem3 = ListView1.Items.Add("C++")
Dim ListItem4 As ListViewItem
ListItem4 = ListView1.Items.Add("Python")
End Sub
End Class
OUTPUT :

21
SYBCA DIV – 02 .NET PROGRAMMING 126

19. Write a practical of Treeview.


ANSWER :
Public Class Ass_19

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


System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

If TreeView1.Nodes(0).Nodes(0).IsSelected Then
Ass_1.Show()
End If
If TreeView1.Nodes(0).Nodes(1).IsSelected Then
Ass_2.Show()
End If
If TreeView1.Nodes(1).Nodes(0).IsSelected Then
Ass_3.Show()
End If
If TreeView1.Nodes(1).Nodes(1).IsSelected Then
Ass_4.Show()
End If
If TreeView1.Nodes(1).Nodes(2).IsSelected Then
Ass_5.Show()
End If
End Sub
End Class
OUTPUT :

20. Write a practical of button three click event.


ANSWER :
Public Class Ass_20

Dim clickCount As Integer = 0


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
clickCount += 1

If clickCount = 3 Then

22
SYBCA DIV – 02 .NET PROGRAMMING 126

MessageBox.Show("Third button click", "Button 3 click event",


MessageBoxButtons.OK, MessageBoxIcon.Information)
clickCount = 0
End If
End Sub
End Class
OUTPUT :

21. Write a practical of Notepad App.


ANSWER :
Public Class Ass_21
Private Sub NewCtrlNToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NewCtrlNToolStripMenuItem.Click
Dim x As Integer = MessageBox.Show("Do you want to save the modified document ?",
"Notpad", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
If x = vbYes Then
SaveCtrlSToolStripMenuItem.PerformClick()
Me.Text = "Untitled"
TextBox1.Clear()
Else
TextBox1.Clear()
End If
End Sub

Private Sub Ass_21_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Me.Text = "Untitled"
End Sub

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


System.EventArgs) Handles SaveCtrlSToolStripMenuItem.Click
SaveFileDialog1.Title = "Save"
SaveFileDialog1.Filter = "Text Files(*.txt)|*.txt"
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text,

23
SYBCA DIV – 02 .NET PROGRAMMING 126

False)
Me.Text = SaveFileDialog1.FileName
End If
End Sub

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


System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim MyFileOpen As New System.Windows.Forms.OpenFileDialog
MyFileOpen.ShowReadOnly = True
MyFileOpen.Filter = "Text Files(*)|*"
MyFileOpen.Title = "Open"
If MyFileOpen.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text =
My.Computer.FileSystem.ReadAllText(MyFileOpen.FileName)
Me.Text = MyFileOpen.FileName
End If
End Sub

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


System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub

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


System.EventArgs) Handles UndoToolStripMenuItem.Click
TextBox1.SelectedText = ""
End Sub

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


System.EventArgs) Handles CopyToolStripMenuItem.Click
TextBox1.Copy()
End Sub

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


System.EventArgs) Handles CutToolStripMenuItem.Click
TextBox1.Cut()
End Sub

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


System.EventArgs) Handles PasteToolStripMenuItem.Click
TextBox1.Paste()
End Sub

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


System.EventArgs) Handles SelectAllToolStripMenuItem.Click

24
SYBCA DIV – 02 .NET PROGRAMMING 126

TextBox1.SelectAll()
End Sub

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


System.EventArgs) Handles ToolStripMenuItem2.Click
TextBox1.Font = New System.Drawing.Font("", 10)
End Sub

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


System.EventArgs) Handles ToolStripMenuItem3.Click
TextBox1.Font = New System.Drawing.Font("", 12)
End Sub

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


System.EventArgs) Handles ToolStripMenuItem4.Click
TextBox1.Font = New System.Drawing.Font("", 14)
End Sub

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


System.EventArgs) Handles ToolStripMenuItem5.Click
TextBox1.Font = New System.Drawing.Font("", 16)
End Sub

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


System.EventArgs) Handles FontToolStripMenuItem.Click
FontDialog1.ShowDialog()
TextBox1.Font = FontDialog1.Font
End Sub
End Class
OUTPUT :

25
SYBCA DIV – 02 .NET PROGRAMMING 126

22. Develop GUI application which accept for an employee of a company accept personal details,
salary information using separate interactive forms store the information in database provide
save, view, navigation commands also provide search facility based on employee code. Also
display salary information for all departments wise.
ANSWER :
EMP Class
Imports System.Data.OleDb

Public Class Emp


Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;
DataSource=C:\Users\91728\Downloads\Assignment_1\Assignment_1\Emp.accdb")

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

Public Sub IUD(ByVal str As String)


If cn.State = ConnectionState.Closed Then
cn.Open()
End If

cm = New OleDbCommand(str, cn)


cm.ExecuteNonQuery()

cn.Close()
End Sub

Public Function Display(ByVal str As String) As DataSet


'Disconnected Model
da = New OleDbDataAdapter(str, cn)
ds.Tables.Clear()
da.Fill(ds)
Return ds
End Function
End Class

FILE CODING :
Imports System.Data.OleDb

Public Class Ass_22

Dim ds As New DataSet


Dim maxrow, inc As Integer
Dim gender As String = ""
Dim s1 As New Emps

26
SYBCA DIV – 02 .NET PROGRAMMING 126

Dim cm As OleDbCommand

Private Sub Ass_22_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
ds = s1.Display("select * from emp2")
cmbdepart.DataSource = ds.Tables(0)

cmbdepart.DisplayMember = "dname"
cmbdepart.ValueMember = "did"
FillStudentData()
End Sub

Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click


If rbMale.Checked = True Then
gender = "Male"
ElseIf rbFemale.Checked = True Then
gender = "Female"
End If
s1.IUD("Insert into emp1(eid,ename,gender,esalary,eadd,ephone,did) values(" &
teid.Text & ",'" & tename.Text & "','" & gender & "','" & tsalary.Text & "','" &
teadd.Text & "','" & tephone.Text & "'," & cmbdepart.SelectedValue & ")")

FillStudentData()
clearControls()
End Sub

Private Sub FillStudentData()


ds = s1.Display("select s.eid,s.ename,s.gender,s.esalary,s.eadd,s.ephone,c.dname from
emp1 s,emp2 c where c.did=s.did order by eid")
DataGridView1.DataSource = ds.Tables(0)

maxrow = ds.Tables(0).Rows.Count
End Sub

Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click


If rbMale.Checked = True Then
gender = "Male"
ElseIf rbFemale.Checked = True Then
gender = "Female"
End If

s1.IUD("Update emp1 set eadd ='" & teadd.Text & "',esalary ='" & tsalary.Text &
"',ename='" & tename.Text & "',ephone='" & tephone.Text & "',gender='" & gender &
"',did=" & cmbdepart.SelectedValue & " where eid=" & teid.Text)

27
SYBCA DIV – 02 .NET PROGRAMMING 126

FillStudentData()
clearControls()
End Sub

Private Sub clearControls()


teid.Text = ""
tename.Text = ""
teadd.Text = ""
tephone.Text = ""
tsalary.Text = ""
rbMale.Checked = False
rbFemale.Checked = False
cmbdepart.Text = ""
End Sub

Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click


s1.IUD("Delete from emp1 where eid=" & teid.Text)

FillStudentData()
clearControls()
End Sub

Private Sub btnexit_Click_1(sender As Object, e As EventArgs) Handles btnexit.Click


Me.Close()
End Sub

Private Sub btnFilter_Click(sender As Object, e As EventArgs) Handles btnFilter.Click


datafilter.Show()
End Sub

Private Sub DataGridView1_CellClick(sender As Object, e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
inc = e.RowIndex
teid.Enabled = True

teid.Text = DataGridView1.Rows(inc).Cells(0).Value
tename.Text = DataGridView1.Rows(inc).Cells(1).Value
tsalary.Text = DataGridView1.Rows(inc).Cells(3).Value
teadd.Text = DataGridView1.Rows(inc).Cells(4).Value
tephone.Text = DataGridView1.Rows(inc).Cells(5).Value
gender = DataGridView1.Rows(inc).Cells(2).Value
If gender = "Male" Then
rbMale.Checked = True
ElseIf gender = "Female" Then
rbFemale.Checked = True

28
SYBCA DIV – 02 .NET PROGRAMMING 126

End If
cmbdepart.Text = DataGridView1.Rows(inc).Cells(6).Value

End Sub

Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click


If inc = 0 Then
MessageBox.Show("First Rec...")
Else
inc -= 1
DisplayRecord()
End If
End Sub

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click


If inc = maxrow - 1 Then
MessageBox.Show("Last Rec...")
Else
inc += 1
DisplayRecord()
End If
End Sub

Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click


inc = 0
DisplayRecord()
End Sub

Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click


inc = maxrow - 1
DisplayRecord()
End Sub

Private Sub DisplayRecord()


teid.Text = ds.Tables(0).Rows(inc).Item(0)
tename.Text = ds.Tables(0).Rows(inc).Item(1)
teadd.Text = ds.Tables(0).Rows(inc).Item(4)
tephone.Text = ds.Tables(0).Rows(inc).Item(5)
tsalary.Text = ds.Tables(0).Rows(inc).Item(3)
Dim gender As String = ds.Tables(0).Rows(inc).Item(2)
If gender = "Male" Then
rbMale.Checked = True
ElseIf gender = "Female" Then
rbFemale.Checked = True
End If

29
SYBCA DIV – 02 .NET PROGRAMMING 126

cmbdepart.Text = ds.Tables(0).Rows(inc).Item(6)
End Sub

End Class

DataFilter

Public Class datafilter

Dim s1 As New Emp


Dim ds As New DataSet

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

ds = s1.Display("select s.eid,s.ename,s.gender,s.esalary,s.eadd,s.ephone,c.dname from


emp1 s,emp2 c where c.did=s.did and ename like '" & tename.Text & "%' and c.did = "
& cmbdepart.SelectedValue & " order by eid")
DataGridView1.DataSource = ds.Tables(0)
End Sub

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


ds = s1.Display("select * from emp2")
cmbdepart.DataSource = ds.Tables(0)

cmbdepart.DisplayMember = "dname"
cmbdepart.ValueMember = "did"
End Sub
End Class
OUTPUT :

30
SYBCA DIV – 02 .NET PROGRAMMING 126

INSERT :

UPDATE :

DELETE :

31
SYBCA DIV – 02 .NET PROGRAMMING 126

FILTER :

23. Write practical Library Project.


ANSWER :
CLASS FILE :
Imports System.Data.OleDb
Public Class Book
Dim cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\library.accdb")
Dim cm As OleDbCommand
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Public Sub IUD(ByVal str As String)
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
cm = NewOleDbCommand(str, cn)
cm.ExecuteNonQuery()
cn.Close()
End Sub
Public Function Display(ByVal str As String) As DataSet
da = New OleDbDataAdapter(str, cn)
ds.Tables.Clear()
da.Fill(ds)
Return ds
End Function
End Class

32
SYBCA DIV – 02 .NET PROGRAMMING 126

mports System.Data.OleDb
Public Class Form1
Dim ds As New DataSet
Dim maxrow, inc As Integer
Dim cm As OleDbCommand
Dim lb As New Library
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles
MyBase.Load
ds = lb.Display("select * from Book")
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "bname"
ComboBox1.ValueMember = "bid"
FillStudentData()
End Sub
Private Sub FillStudentData()
ds = lb.Display("selects.sid,s.rno,s.sname,s.class,s.div,s.idate,s.rdate,b.bname from
Student s,Book b where s.sid=b.sid order by rno")
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.Columns(0).Visible = False
maxrow = ds.Tables(0).Rows.Count
End Sub
Private Sub ClearControl()
tbrno.Text = ""
tbrno.Enabled = True
tbname.Text = ""
tbclass.Text = ""
tbdiv.Text = ""
tbidate.Text = ""
tbrdate.Text = ""
ComboBox1.Text = ""
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e
AsSystem.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
inc = e.RowIndex tbrno.Enabled = False
tbsid.Text = DataGridView1.Rows(inc).Cells(0).Value
tbrno.Text = DataGridView1.Rows(inc).Cells(1).Value
tbname.Text = DataGridView1.Rows(inc).Cells(2).Value
tbclass.Text = DataGridView1.Rows(inc).Cells(3).Value
tbdiv.Text = DataGridView1.Rows(inc).Cells(4).Value
tbidate.Text = DataGridView1.Rows(inc).Cells(5).Value
tbrdate.Text = DataGridView1.Rows(inc).Cells(6).Value
End Sub
Private Sub btninsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btninsert.Click
lb.IUD("Insert into Student (rno,sname,class,div,idate,rdate) values (" & tbrno.Text &

33
SYBCA DIV – 02 .NET PROGRAMMING 126

",'" & tbname.Text & "','" & tbclass.Text & "','" & tbdiv.Text & "','" & tbidate.Text &
"','" & tbrdate.Text & "')")
FillStudentData()
ClearControl()
End Sub
Private Sub btnupdate_Click(sender As System.Object, e As System.EventArgs) Handles
btnupdate.Click
lb.IUD("Update Student set sname='" & tbname.Text & "',class='" & tbclass.Text &
"',div=" & tbdiv.Text & ",idate='" & tbidate.Text & "',rdate='" & tbrdate.Text &
"',book=" & ComboBox1.SelectedValue & " where rno=" & tbrno.Text)
FillStudentData()
ClearControl()
End Sub
Private Sub btndelete_Click(sender As System.Object, e As System.EventArgs) Handles
btndelete.Click
lb.IUD("delete * from Student where rno=" & tbrno.Text)
FillStudentData()
ClearControl()
End Sub
Private Sub btnsearch_Click(sender As System.Object, e As System.EventArgs) Handles
btnsearch.Click
Search.Show()
End Sub
Private Sub btnexit_Click(sender As System.Object, e As System.EventArgs) Handles
btnexit.Click
Me.Close()
End Sub
Private Sub btnacs_Click(sender As System.Object, e As System.EventArgs) Handles
btnacs.Click
Dim oview As New DataView(ds.Tables(0))
oview.Sort = "rno Asc"
DataGridView1.DataSource = oview
End Sub
Private Sub btndesc_Click(sender As System.Object, e As System.EventArgs) Handles
btndesc.Click
Dim oview As New DataView(ds.Tables(0))
oview.Sort = "rno Desc"
DataGridView1.DataSource = oview
End Sub
Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnfirst.Click
inc = 0
DisplayRecord()
End Sub
Private Sub btnprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

34
SYBCA DIV – 02 .NET PROGRAMMING 126

Handles btnprev.Click
If inc = 0 Then
MessageBox.Show("First Record...!!!")
Else
inc -= 1
DisplayRecord()
End If
End Sub
Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnnext.Click
If inc = maxrow - 1 Then
MessageBox.Show("Last Record...!!!")
Else
inc += 1
DisplayRecord()
End If
End Sub
Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnlast.Click
inc = maxrow - 1
DisplayRecord()
End Sub
Private Sub DisplayRecord()
tbsid.Text = ds.Tables(0).Rows(inc).Item(0)
tbrno.Text = ds.Tables(0).Rows(inc).Item(1)
tbname.Text = ds.Tables(0).Rows(inc).Item(2)
tbclass.Text = ds.Tables(0).Rows(inc).Item(3)
tbdiv.Text = ds.Tables(0).Rows(inc).Item(4)
tbidate.Text = ds.Tables(0).Rows(inc).Item(5)
tbrdate.Text = ds.Tables(0).Rows(inc).Item(6)
ComboBox1.Text = ds.Tables(0).Rows(inc).Item(7)
End Sub
End Class

Public Class Search


Dim ds As New DataSet
Dim lb As New Library
Private Sub Search_Load(sender As System.Object, e As System.EventArgs) Handles
MyBase.Load
ds = lb.Display("select * from Book") ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "bname"
ComboBox1.ValueMember = "bid"
End Sub
Private Sub btnsearch_Click(sender As System.Object, e As System.EventArgs)
Handlesbtnsearch.Click

35
SYBCA DIV – 02 .NET PROGRAMMING 126

ds = lb.Display("select s.sid,s.rno,s.sname,s.class,s.div,s.idate,s.rdate,b.bname from


Student s,Book b where b.bid=s.book and sname like '" & tbname.Text & "%' and
book=" & ComboBox1.SelectedValue)
DataGridView1.DataSource = ds.Tables(0)
End Sub
End Class

OUTPUT :
ASCENDING :

DECENDING :

36
SYBCA DIV – 02 .NET PROGRAMMING 126

SEARCH :

37
SYBCA DIV – 02 .NET PROGRAMMING 126

38

You might also like