Visual Basics and Oracle Programs-1 - 240919 - 101202
Visual Basics and Oracle Programs-1 - 240919 - 101202
7. NUMBER CONVERSION 36
ORACLE
8. EMPLOYEE DETAILS 41
1
VISUAL BASIC
2
EX.NO : 01
CALCULATOR
DATE :
AIM:
To create a simple Visual Basic calculator program which include the basic mathematic function
like addition, subtraction, multiplication and division.
ALGORITHM:
Step 3 : Place the appropriate controls on the form (1 Frame,1 text box, 16 command buttons and
Step 4 : Set the property for all the controls in the form.
3
PROPERTY SETTING:
4
Caption *
Command13 Name Command1
Caption 0
Index 9
Command14 Name Command14
Caption AC
Command15 Name Command15
Caption =
Command16 Name Command16
Caption /
FORM DESIGN:
5
CODING:
curval = Val(Text1.Text)
End Sub
Text1.Text = ""
preval = curval
curval = 0
choice = "*"
End Sub
preval = curval = 0
Text1.Text = ""
End Sub
Case "+"
6
result = preval + curval
Text1.Text = Str(result)
Case "-"
Text1.Text = Str(result)
Case "*"
Text1.Text = Str(result)
Case "/"
Text1.Text = Str(result)
End Select
curval = result
End Sub
Text1.Text = ""
preval = curval
curval = 0
choice = "/"
End Sub
Text1.Text = ""
preval = curval
curval = 0
choice = "+"
7
End Sub
Text1.Text = ""
preval = curval
curval = 0
choice = "-"
End Sub
8
OUTPUT:
Result:
9
EX.NO : 02
FIBONACCI SERIES AND SUM OF DIGITS
DATE :
AIM:
To write a simple Visual Basic program to generate Fibonacci Series and Sum of n-numbers.
ALGORITHM:
Step 3 : Draw a textbox for accepting the number from the user and draw one listbox for displaying
Step 4 : Draw a button for performing the Fibonacci operation and another button for performing
the sum operation, you can use more buttons for performing the multiple operation like
Step 5 : Double click on the button which you want to perform the Fibonacci operation, then type
Step 6 : Double click on the button which you want to perform the sum operation, then type the
10
PROPERTY SETTING:
11
CODING:
n = Val(Text1.Text)
ans = 0
f=0
s=1
List1.AddItem f
List1.AddItem s
cnt = 2
ans = f + s
List1.AddItem ans
f=s
s = ans
cnt = cnt + 1
Wend
End Sub
n = Val(Text1.Text)
sum = 0
While (n > 0)
n = n \ 10
12
Wend
List1.AddItem sum
End Sub
List1.Clear
Text1.Text = ""
End Sub
End
End Sub
13
OUTPUT:
Result:
14
EX.NO : 03
MENU DRIVEN PROGRAM USING MDI WINDOW
DATE :
AIM:
To write a Visual Basic program to develop a menu driven program using mdi window to display
cascade and horizontal style and change the color form.
ALGORITHM:
Step 3 : Open a mdi form and make it as a child of form1, form2, form3.
Step 4 : In mdi form using menu editor window create menu’s and sub menu’s.
Step 5 : Menu as file and sun menu as new, cascade, horizontal an exit.
Step 6 : Other menu as color and sub menu as red, green and blue.
15
PROPERTY SETTING:
16
CODING:
Form1.BackColor = vbBlue
End Sub
End
End Sub
Form2.BackColor = vbGreen
End Sub
MDIForm1.Arrange vbHorizontal
End Sub
newform.Show
End Sub
Form3.BackColor = vbRed
End Sub
17
Private Sub mnucascade_Click()
MDIForm1.Arrange vbVertical
End Sub
OUTPUT:
Result:
18
EX.NO : 04
DISPLAY FILES USING LISTBOXES
DATE :
AIM:
ALGORITHM:
Step 3 : Place four labels, two command buttons, one CommonDialog, one DriveListbox, one
DirectoryListBox, one FileListBox and one RichTextBox in the form and change their
corresponding properties.
Step 4 : Double click on the buttons and then type the corresponding coding of the buttons.
19
PROPERTY SETTING:
20
CODING:
Option Explicit
CommonDialog1.ShowSave
CommonDialog1.Filter = ".txt"
txtFileContent.SaveFile (CommonDialog1.FileName)
txtFileContent.Text = ""
End Sub
End
End Sub
File1.Path = Dir1.Path
CurrentDir.Caption = Dir1.Path
File1.ListIndex = 0
Else
SelectedFileName.Caption = "(None)"
txtFileContent.Text = ""
End If
End Sub
21
With Dir1.Path = .List(.ListIndex)
End With
End Sub
Dir1.Path = Drive1.Drive
Drive1.Drive = mstrDrive
Else
mstrDrive = Drive1.Drive
End If
End Sub
With File1
& .List(.ListIndex)
22
End With
SelectedFileName.Caption = strCurrFile
lngFileLen = FileLen(strCurrFile)
Else
intFreeFile = FreeFile
Close #intFreeFile
blnIsTextFile = True
Case 0 To 8, 11 To 12, 14 To 31
blnIsTextFile = False
Exit For
End Select
Next
If blnIsTextFile Then
txtFileContent.Text = strFileContent
Else
End If
End If
End Sub
23
Private Sub Form_Load()
Drive1.Drive = "C:"
mstrDrive = "C:"
Dir1.Path = "C:\"
End Sub
OUTPUT:
Result:
24
EX.NO : 05 ACCESSING FILES USING COMMON DIALOG
DATE : BOX
AIM:
To design a form using common Dialog Control to display the open, save, color and font dialog
box without using the action control property.
ALGORITHM:
Step 3 : Design the form by placing Common Dialog Control and RichTextBox.
Step 4 : Open the Project Components Microsoft Common Dialog 6.0 apply menu editor
window and then create required menu is file and sub menu’s as open, font, color and exit.
Step 5 : In the code editor window write code for accessing files using Common Dialog Control
25
PROPERTY SETTING:
FORM DESIGN:
26
CODING:
Private Sub mnucolor_Click()
CommonDialog1.ShowColor
RichTextBox1.BackColor = CommonDialog1.Color
End Sub
End
End Sub
CommonDialog1.ShowFont
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
RichTextBox1.Font.Size = CommonDialog1.FontSize
cancel:
End Sub
CommonDialog1.Filter = ".txt"
CommonDialog1.ShowOpen
27
RichTextBox1.FileName = CommonDialog1.FileName
End Sub
CommonDialog1.ShowSave
CommonDialog1.Filter = ".txt"
RichTextBox1.SaveFile (CommonDialog1.FileName)
RichTextBox1.Text = ""
End Sub
28
OUTPUT:
29
Result:
30
EX.NO : 06
ANIMATION USING TIMER
DATE :
AIM:
ALGORITHM:
Step 3 : Place one command button, eight image box and one timer in the form.
Step 4 : Insert a group of eight images of a flapping butterfly its wings at different stages in the
image box.
Step 5 : Set the timer properties and then type the corresponding coding of the buttons.
31
PROPERTY SETTING:
FORM DESIGN:
32
CODING:
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Image1.Visible = True
X=0
End Sub
Image1.Visible = False
Image2.Visible = True
Image2.Visible = False
Image3.Visible = True
Image3.Visible = False
Image4.Visible = True
Image4.Visible = False
Image5.Visible = True
Image5.Visible = False
Image6.Visible = True
33
Image6.Visible = False
Image7.Visible = True
Image7.Visible = False
Image8.Visible = True
Image8.Visible = False
Image1.Visible = True
End If
End Sub
34
OUTPUT:
Result:
35
EX.NO : 07
NUMBER CONVERSION
DATE :
AIM:
To write a Visual Basic Program to accept a number as input and convert them into Binary, Octal
and hexadecimal.
ALGORITHM:
Step 3 : Place four label boxes, four text boxes and two command buttons in the form.
36
PROPERTY SETTING:
37
CODING:
Private Sub Command1_Click()
Text2.Text = ""
num = Val(Text1.Text)
i=0
i=i+1
num = (num / 2)
Wend
Text3.Text = Oct(Text1.Text)
Text4.Text = Hex(Text1.Text)
End Sub
End
End Sub
38
OUTPUT:
Result:
39
ORACLE
40
EX.NO : 08
EMPLOYEE DETAILS
DATE :
AIM:
To create a table for employee details with employee number as primary key and following fields
Name, Designation, Gender, Age, Date of Joining and Salary. Insert at least ten rows and perform various
queries using any one comparison, logical, set, sorting and grouping operation.
ALGORITHM:
Step 4 : This table contains as Empno, Name, Designation, Gender, Age, DOJ, Salary with their
Step 6 : Then perform operation like comparison, logical, set, sorting and grouping – average, sum,
41
QUERIES:
MYSQL > create database empl;
Query OK
Database changed
Query OK
7 rows in set
Query OK.
Query OK.
Query OK.
Query OK.
42
Query OK.
Query OK.
6 rows in set
43
---------- --------------- ------------------ ----- ------
5 PM MD M 35
10 SWETHA SECRETARY F 39
13 SWATHI INCHARGE F 25
3 rows in set
MYSQL >select Name from empl where Name between 'S' and 'U';
Name
---------------
SURYA
SOFI
SWETHA
SWATHI
4 rows in set
Query OK.
Query OK.
Query OK.
Union
Empno Name
---------- ---------------
2 SURYA
5 PM
6 SOFI
10 SWETHA
13 SWATHI
44
20 RAM
1 KRISHNA
7 PRIYA
8 rows in set
Result:
45
EX.NO : 09
UPDATE AND ALTER THE TABLE USING PL/SQL
DATE :
AIM:
To write a PL/SQL to update the fieldscreate fields by 20% more than the current rate in inventory
table which has the following fields Prono, Proname and Rate after updating the table anew fields(after)
called for number of item and place for value for the new field without using PL/SQL blocks.
ALGORITHM:
Step 3 : Create a table as Prono, Proname and Rate by using the table.
Step 4 : PL/SQL to update the rate field by 20% more than the current rate in inventory table.
Step 5 : Alter the table into adding the no of item and place for values.
46
QUERIES:
MYSQL > create database employees;
Query OK.
Database Changed.
MYSQL > create table inventry(ProdNo int(5),primary key(ProdNo),ProdName varchar(20) not null,Rate
int(10));
Query OK.
Query OK.
Query OK.
Query OK.
3 rows in set
Query OK.
47
ProdNo ProdName Rate
--------------- ------------------ -----------
1 Clothes 60
2 Dal 108
3 Oil 120
3 rows in set
Query OK.
Query OK.
3 rows in set
Result:
48
EX.NO : 10
IMPLEMENTING THE CONCEPT OF TRIGGERS
DATE :
AIM:
ALGORITHM:
Step 4 : This table contains column as a1, a2, a3, a4 and b4.
49
QUERIES:
MYSQL > create database list;
Query OK.
Database Changed.
Query OK.
Query OK.
MYSQL > create table test3(a3 int not null auto_increment primary key);
Query OK.
MYSQL > create table test4(a4 int not null auto_increment primary key,
Query OK.
begin
end;
MYSQL > insert into test3 (a3) values (null), (null), (null), (null), (null),
50
Query OK.
MYSQL > insert into test4 (a4) values (0), (0), (0), (0), (0), (0), (0), (0), (0), (0);
Query OK.
MYSQL > insert into test1 values (1), (3), (1), (7), (1), (8), (4), (4);
Query OK.
a1
------
1
3
1
7
1
8
4
4
8 rows in set
a2
------
1
3
1
7
1
8
4
4
8 rows in set
51
a3
------
2
5
6
9
10
5 rows in set
a4 b4
------ ------
1 3
2 0
3 1
4 2
5 0
6 0
7 1
8 1
9 0
10 0
10 rows in set
Result:
52
EX.NO : 11 IMPLEMENTING THE CONCEPT OF
DATE : PROCEDURES
AIM:
ALGORITHM:
Step 3 : Create a table employees with the fields employee_id, employee_name and salary.
53
QUERIES:
MYSQL > create database details;
Query OK.
Database Changed.
MYSQL > create table employees (employee_id int auto_increment primary key, employee_name
varchar(255) not null, salary decimal(10, 2) not null);
Query OK.
MYSQL > create procedure insertemployee(in emp_name varchar(255), in emp_salary decimal(10, 2))
begin
end;
//
Query OK.
1 row in set
MYSQL >delimiter //
54
//
MYSQL >delimiter ;
MYSQL >call updatesalary(1, 65000.00);
Query OK.
1 row in set
Result:
55
EX.NO : 12
STUDENT MARKLIST
DATE :
AIM:
To create a simple Visual Basic project for student marklist using VB as front-end and MYSQL as
back-end.
ALGORITHM:
Step 3 : The student table is created using create table student query with Student_Name,
Step 4 : The values are inserted in student table using INSERT command.
Step 5 : In order to view the student record select * from student query is used.
Step 6 : To use the Visual basic as front end, click on Start → All Programs → Microsoft Visual
Step 7 : Draw three labels, three textboxes, five command button and one ADODC Control.
Step 8 : Change the caption for the controls using properties window.
56
Step 9 : To connect ADODC Control to MYSQL database, Right click on the ADODC and select
ADODC properties, Select on Use Connection String and Click Build, Select the Microsoft
OLE DB Provider for ODBC Drivers. Then Enter the Data Source Name, Username and
Step 10 : Create a new form and Place One ADODC Control and One DataGrid Control, Connect
Step 11 : Connect DataGrid Control to ADODC Control and Right click on ADODC and Set
Step 12 : Open the code editor window and write appropriate coding.
57
PROPERTY SETTING:
58
FORM DESIGN:
59
MYSQL QUERIES:
MYSQL >create database student_marklist;
Query OK.
Database Changed.
MYSQL >create table student (Student_Name varchar(50), Student_Dept varchar(10), Marks int(3));
Query OK.
Query OK.
1 row in set
60
Private Sub Form_Load()
conn.ConnectionString = "DSN=sql;"
conn.Open
End Sub
studentName = txtStudentName.Text
studentDept = txtDept.Text
marks = Val(txtMarks.Text)
conn.Execute "INSERT INTO student (Student_Name,Student_Dept,Marks) VALUES ('" & studentName
& "','" & studentDept & "', '" & marks & "')"
MsgBox "Student added successfully!", vbInformation, "Success"
txtStudentName.Text = ""
txtDept.Text = ""
txtMarks.Text = ""
End Sub
studentName = txtStudentName.Text
studentDept = txtDept.Text
newMarks = Val(txtMarks.Text)
61
conn.Execute "UPDATE student SET Marks = " & newMarks & " WHERE Student_Name = '" &
studentName & "'and Student_Dept = '" & studentDept & "'"
MsgBox "Marks updated successfully!", vbInformation, "Success"
txtStudentName.Text = ""
txtDept.Text = ""
txtMarks.Text = ""
End Sub
studentName = txtStudentName.Text
studentDept = txtDept.Text
conn.Execute "DELETE FROM student WHERE Student_Name = '" & studentName & "' and
Student_Dept = '" & studentDept & "' "
MsgBox "Student deleted successfully!", vbInformation, "Success"
txtStudentName.Text = ""
txtDept.Text = ""
End Sub
62
OUTPUT:
63
Result:
Thus the Visual Basic and MYSQL program has been executed successfully.
64