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

VB Mayank

The document contains the code and output for 13 practical programming exercises in Visual Basic. The exercises cover basics of the Visual Basic programming language including: printing text on mouse click; message boxes; calculators; string concatenation; calculating string length; grade calculation; combo boxes; radio buttons; check boxes; displaying date and time; lists; linking forms; and creating a phonebook application using a database. The exercises demonstrate core Visual Basic concepts and how to create basic graphical user interfaces and connect to databases.

Uploaded by

Gagan Sardana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

VB Mayank

The document contains the code and output for 13 practical programming exercises in Visual Basic. The exercises cover basics of the Visual Basic programming language including: printing text on mouse click; message boxes; calculators; string concatenation; calculating string length; grade calculation; combo boxes; radio buttons; check boxes; displaying date and time; lists; linking forms; and creating a phonebook application using a database. The exercises demonstrate core Visual Basic concepts and how to create basic graphical user interfaces and connect to databases.

Uploaded by

Gagan Sardana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

PRACTICAL -1

Aim :- Write a program in Visual Basic to print a desired text in text


box on mouse clicking event.

Design View

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = "WELCOME TO VISUAL BASIC"
End Sub
End Class

Gagan

Page 1

Output

Gagan

Page 2

PRACTICAL -2
Aim:- Write a program in Visual Basic for implementation of Mouse
Clicking Event.

Design View

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim a As String
a = TextBox1.Text
MsgBox(a)
End Sub
End Class

Gagan

Page 3

Output

Gagan

Page 4

PRACTICAL -3
Aim:- Write a program in Visual Basic to make a Calculator.
Design View

Coding
Public Class Form1
Dim
Dim
Dim
Dim

firstnum As Decimal
secondnum As Decimal
operations As Integer
operator_selector As Boolean = False

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


As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If

Gagan

Page 5

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else

Gagan

Page 6

TextBox1.Text = "8"
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button10.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button16.Click
TextBox1.Text = "0"
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button11.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button12.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 1 ' = +
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button13.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 2 ' = End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button14.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"
operator_selector = True
operations = 3 ' = *
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button15.Click
firstnum = TextBox1.Text
TextBox1.Text = "0"

Gagan

Page 7

operator_selector = True
operations = 4 ' /
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button17.Click
If operator_selector = True Then
secondnum = TextBox1.Text
If operations = 1 Then
TextBox1.Text = firstnum + secondnum
ElseIf operations = 2 Then
TextBox1.Text = firstnum - secondnum
ElseIf operations = 3 Then
TextBox1.Text = firstnum * secondnum
Else
If secondnum = 0 Then
TextBox1.Text = "error!!"
Else
TextBox1.Text = firstnum / secondnum
End If
End If
operator_selector = False
End If
End Sub
End Class

Gagan

Page 8

Gagan

Page 9

Gagan

Page 10

Output
Step 1:-

Gagan

Step 2:-

Page 11

Step 3:-

Gagan

Step 4:-

Page 12

PRACTICAL -4
Aim :- Write a program in Visual Basic to concatenate two different
entered strings.
Design View

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strFirst As String
Dim strSecond As String
Dim strOutput As String
strFirst = TextBox1.Text
strSecond = TextBox2.Text
strOutput = strFirst & strSecond
TextBox3.Text = strOutput
End Sub

Gagan

Page 13

Output

Gagan

Page 14

PRACTICAL -5
Aim :- Write a program in Visual Basic to calculate the length of
entered string.
Design View

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim strOutput As String
strOutput = TextBox1.Text
MessageBox.Show(strOutput.Length)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
End Class

Gagan

Page 15

Output

Gagan

Page 16

PRACTICAL -6
Aim :- Write a program in Visual Basic to calculate grade of student.
Design View

Coding
Public Class Form1
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label3.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim a As Integer
Dim b As String
a = Val(TextBox3.Text)
If (a >= 90 And a <= 100) Then
b = "A"
ElseIf (a > 80 And a <= 90) Then
b = "B"
ElseIf (a > 70 And a < 80) Then
b = "C"
ElseIf (a > 60 And a < 70) Then
b = "D"
ElseIf (a > 50 And a <= 60) Then
b = "E"
Else

Gagan

Page 17

b = "fail"
End If
TextBox4.Text = b
End Sub
End Class

Output

Gagan

Page 18

PRACTICAL -7
Aim :- Write a program in Visual Basic about Combo Box.
Design View

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)
End Sub
End Class

Gagan

Page 19

Output

Gagan

Page 20

Gagan

Page 21

PRACTICAL -8
Aim :- Write a program in Visual Basic to implement Radio Button.
Design View

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True Then
MessageBox.Show("hobby is singing!!!")
ElseIf CheckBox2.Checked = True Then
MessageBox.Show("hobby is dancing!!!")
ElseIf CheckBox3.Checked = True Then
MessageBox.Show("hobby is playing!!!")
ElseIf CheckBox4.Checked = True Then
MessageBox.Show("hobby is watching t.v. !!!")
End If
End Sub
End Class

Gagan

Page 22

Output

Gagan

Page 23

PRACTICAL -9
Aim :- Write a program in Visual Basic to implement Check Box.
Design View

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles
Button1.Click
If CheckBox1.Checked = True Then
MessageBox.Show(hobby is singing!!!)
ElseIf CheckBox1.Checked = True Then
MessageBox.Show(hobby is dancining!!!)
ElseIf CheckBox1.Checked = True Then
MessageBox.Show(hobby is playinging!!!)
ElseIf CheckBox1.Checked = True Then
MessageBox.Show(hobby is watching T.V.!!!)
End If
End Sub
End Class

Gagan

Page 24

Output

Gagan

Page 25

Practical:-10
Aim:- Write a program to find the date and time in visual basic language.
Design view:-

Coding:Private Sub Timer1_Time()


Text1.Text=DateTime.Time
Text1.Text=DateTime.Date

Gagan

Page 26

Output:This shown the current date & time in textbox

Gagan

Page 27

PRACTICAL -11
Aim :- Write a program in Visual Basic to implement List.
Design View

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
End Sub
End Class

Gagan

Page 28

Output

Gagan

Page 29

Gagan

Page 30

PRACTICAL:-12
Aim:- Write a program to link the form in visual basic

Design View:-

Coding:Private Sub command_click()


Form2.Show
Unload Me
End Sub

Gagan

Page 31

Output:This is output of form 1

Gagan

Page 32

When we click on command button ,then shown the form2

Gagan

Page 33

Practical: - 13
Aim: To create Phonebook System using visual programming and
Database.

Design View :

Gagan

Page 34

Database View:

Coding:

Gagan

Page 35

Output :

Gagan

Page 36

You might also like