Visual Basic Lab Manual Code
Visual Basic Lab Manual Code
DATA TYPES:
1. CHAR (Size)
2. VARCHAR (Size) / VARCHAR2 (Size)
3. DATE
4. LONG
5. RAW
The Data Definition Language (DDL) is used to create and destroy databases and
database objects. Four basic DDL commands:
1. CREATE 2. ALTER 3. DROP 4. RENAME
1. CREATE:
a) CREATE TABLE: This is used to create a new relation (table)
Syntax: CREATE TABLE <relation_name/table_name >
(field_1 data_type(size),field_2 data_type(size), .. . );
b) NOT NULL: When a column is defined as NOTNULL, then that column
becomes a mandatory column. It implies that a value must be entered into the
column if the record is to be accepted for storage in the table.
Syntax:
CREATE TABLE Table_Name (column_name data_type (size) NOT NULL, );
c) PRIMARY KEY: A field which is used to identify a record uniquely. A column or
combination of columns can be created as primary key, which can be used as a
reference from other tables. A table contains primary key is known as Master
Table.
Syntax:
CREATE TABLE Table_Name(column_name data_type(size) PRIMARY KEY,….);
Example:
1
2. ALTER:
a) ALTER TABLE ...ADD...:
This is used to add some extra fields into existing relation.
Syntax: ALTER TABLE relation_name ADD (new field_1 data_type(size),
new field_2 data_type(size),..);
b) ALTER TABLE...MODIFY...:
This is used to change the width as well as data type of fields of existing
relations.
Syntax: ALTER TABLE relation_name MODIFY (field_1 newdata_type(Size),
field_2
newdata_type(Size),....field_newdata_type(Size));
c) ALTER TABLE..DROP...:
This is used to remove any field of existing relations.
Syntax: ALTER TABLE relation_name DROP COLUMN (field_name);
d) ALTER TABLE..RENAME...:
This is used to change the name of fields in existing relations.
Syntax: ALTER TABLE relation_name RENAME COLUMN (OLD field_name)
to (NEW field_name);
3. DROP TABLE:
This is used to delete the structure of a relation. It permanently deletes
the records in the table.
Syntax: DROP TABLE relation_name;
1. INSERT INTO:
This is used to add records into a relation. These are three type of INSERT
INTO queries which are as
a) Inserting a single record
Syntax: INSERT INTO < relation/table name>
(field_1,field_2……field_n) VALUES
(data_1,data_2,........data_n);
b) Inserting all records from another relation
Syntax: INSERT INTO relation_name_1 SELECT
Field_1,field_2,field_n FROM relation_name_2 WHERE
field_x=data;
c) Inserting multiple records
Syntax: INSERT INTO relation_name field_1,field_2,.....field_n) VALUES
(&data_1,&data_2,........&data_n);
2
2. UPDATE-SET-WHERE:
This is used to update the content of a record in a relation.
Syntax: SQL>
UPDATE relation name SET Field_name1=data,field_name2=data,
WHERE field_name=data;
3. DELETE-FROM: This is used to delete all the records of a relation but it will
retain the structure of that relation.
b) DELETE -FROM-WHERE:
This is used to delete a selected record from a relation.
Syntax: SQL>DELETE FROM relation_name WHERE condition;
4. TRUNCATE: This command will remove the data permanently. But structure will
not be removed.
Syntax: TRUNCATE TABLE <Table name>
3
(II)Creation of data source connection (DSN)
STEP 1 :
click start buton -> control panel -> administrative tools ->datasource (ODBC) – ODBC
source administrative
Step 2:
select userdsn-> click add button - > select MICROSOFT ODBC FOR ORACLE
STEP 3: give a new data source name and username(SYSTEM) and click ok.
4
(III)Adodc connection
1. Add the Microsoft ADO DataControl 6.0 (OLEDB) from the Project, Components
menu dialog box, as in Figure The ADO Data Control icon should now appear in
the VB toolbox.
3. Change the control's Name and Caption from their default values. (The Caption
is for information only, so you can set it to whatever you think will be most
informative for the user.)
5
4. Click the ellipsis next to the Connection String property in the ADO Data
Control's Properties window to bring up the Property Page dialog box for this
property, as shown
6
7. Click test connection and ok button
9. Setting data source and corresponding datafields for all the textbox in the form
7
(IV) ADDING Data report
From the Project menu in the VBE, select Add Data Report in the dropdown menu.
Now, to connect to the database, right-click connection1 and select Microsoft OLE
DB Provider for Oracle (as we are using Oracle database) from the Data Link
Properties dialog , then click next.
8
Click test connection and ok button
9
Step 4: Adding Data Report
To add data to your report, you need to drag the fields from Command1 in
DataEnvironment1 into DataReport, as shown
Customize a few properties of your data report so that it can connect to the database.
The first property to set is the DataSource, set it to DataEnvironment1
10
Next, you need to set the DataMember property to Command1,as shown
The Final step is to set dataReport1 as the Startup form from the Project menu, then
run the program
11
EX.NO: 1 employee payroll processing
DATE :
AIM:
To develop the project for the Employee Payroll Processing by
using Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about Allowance, Deduction and
Net Pay Calculations of an Employee.
12
ENTITY – DIAGRAM
empname
phone
empid dept
dob
dateofsalary
doj
netpay
employee
deduction design
s
lic
basicpay
pf hra
totalallowance da ta
13
FORM DESIGN
14
CONTROLS
txtdob cmdsearchempid
txtdoj searchempid
txtdesign cmdallsearch
txtbasicpay searchdept
txtlic
15
VB CODING
GENERAL
ADDING,SAVING,MODIFYING,DELETING A RECORD
16
CALCULATION
Private Sub cmdcalculate_Click()
txthra.Text = Val(txtbasicpay.Text) * 12 / 100
txtda.Text = Val(txtbasicpay.Text) * 10 / 100
txtta.Text = Val(txtbasicpay.Text) * 11 / 100
txttotallowance.Text = Val(txthra.Text) + Val(txtda.Text) + Val(txtta.Text)
SEARCH
REPORT
17
DATA ENVIRONMENT-EMPLOYEE PAYROLL
18
DATA REPORT-EMPLOYEE PAYROLL
19
EX.NO: 2 mark sheet processing system
DATE :
AIM:
To develop the project for the Student Mark sheet Processing
using Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about Total marks, Percentage,
Class and Result Calculations of an Student.
20
ENTITY – DIAGRAM
name
phone
dept
regno dob
addres
s
semester
studentmark
result
class m1
percentage m2
total m4 m3
m5
21
FORM DESIGN
22
CONTROLS
CALCULATE
INPUTS & COMMAND Adodc DATAGRID
OUTPUT BUTTON control control
textbox
txtphone cmdsearchregno
txtsem cmdallsearch.
txtdept cmdsearchresult
cmdsearchdept
txtm1
txtm2
txtm3
txtm4
txtm5
txtsearchdept
txtsearchresult
txtsearchregno
23
VB CODING
GENERAL
CALCULATION
SEARCH
Private Sub cmdsearchregno_Click()
txtsearchregno.Text = Trim(txtsearchregno.Text)
adodcmark.RecordSource = "SELECT * FROM studentmark WHERE
regno=' " + (txtsearchregno.Text) + " ' "
adodcmark.Refresh
End Sub
REPORT
Private Sub cmdreport_Click()
DataReport1.Show
End Sub
25
DATA ENVIRONMENT-STUDENTMARKSHEET
26
DATA REPORT- STUDENT MARKSHEET
27
EX.NO: 3 SAVINGS BANK ACCOUNT FOR BANKING
DATE :
AIM:
To develop the project for Opening Savings bank account using
Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about Cash Withdraw and Deposit
by Updating Balance amount after each Transaction of a
Customer.
28
ENTITY – DIAGRAM-BANKING
dateobirth
gender
homeaddress phone
accountnum
offaddress
acctype
customer
name
bank
transmode
balance
transdate
dateopened
transid
29
FORM DESIGN
30
CONTROLS
CALCULATE &
INPUTS OUTPUT COMMAND Adodc DATAGRID
BUTTON control control
textbox
adodcbank
txtcusname txtamount cmdadd Datagrid1
txtcurrbal
txtoffaddr cmdmod
txthomeaddr cmddel
txtdob cmdexit
cmd
cmbgender
DEP/WITHD
txtphone cmdsearchacctno
txtaccno searchaccno
cmbacctype cmdallsearch
txtbalance
txtdateopen
txttransid
cmbtransmode
txttransdate
31
VB CODING
GENERAL
Dim cn As New ADODB.Connection
Dim bankrs As New ADODB.Recordset
ADDING,SAVING,MODIFYING,DELETING A RECORD
Private Sub cmdadd_Click()
adodcbank.Recordset.AddNew
End Sub
SEARCH
Private Sub cmdsearchacctno_Click()
searchaccno.Text = Trim(searchaccno.Text)
adodcbank.RecordSource = "SELECT * FROM bank WHERE
accountnum=' " + (searchaccno.Text) + " ' "
adodcbank.Refresh
End Sub
REPORT
33
DATA ENVIRONMENT-BANKING
34
DATA REPORT-BANKING
35
EX.NO: 4 inventory system
DATE :
AIM:
To develop the project for the Inventory System using Visual
Basic 6.0.
PROJECT PLANNING:
The application should be developed using the VB controls.
This project should describe about stockin, stockout of the
products in stock table and updation of stock in an inventory
table.
SOFTWARE REQUIREMENT ANALYSIS:
The basic requirements for the project includes,
Microsoft visual basic 6.0
Windows OS
Oracle 9i
36
ENTITY RELATIONSHIP – DIAGRAM
stockin
invt stockout stock
totalcost stockin
unitcost
stockout
37
FORM DESIGN
38
CONTROLS
cmbcatg searchbrand
cmdbrand allsearch
cmdcateg stocknew
cmdstockin
cmdstockout
cmdupdate
39
VB CODING
FORM LOAD
Private Sub Form_Load()
'combo box items for brands
cmbbrand.Text = "ALL BRANDS"
cmbbrand.AddItem "ALL BRANDS"
cmbbrand.AddItem "SAMSUNG"
cmbbrand.AddItem "LG"
cmbbrand.AddItem "MOTOROLO"
cmbbrand.AddItem "HAIER"
40
Private Sub gridstock_Click()
Dim totcoststk As Integer
If adostock.Recordset.Fields("stockin") <> " " Then
totcoststk = Val(adostock.Recordset.Fields("unitcost")) *
Val(adostock.Recordset.Fields("stockin"))
adostock.Recordset.Fields("totalcost") = Str(totcoststk)
ElseIf adostock.Recordset.Fields("stockout") <> " " Then
totcoststk = Val(adostock.Recordset.Fields("unitcost")) *
Val(adostock.Recordset.Fields("stockout"))
adostock.Recordset.Fields("totalcost") = Str(totcoststk)
End If
End Sub
adoinvt.Recordset.Fields("stock") = Str(stockvalue)
adostock.Recordset.Fields("stock") = Str(stockvalue)
adoinvt.Recordset.Update
adostock.Recordset.Update
End Sub
SEARCH
Private Sub allsearch_Click()
adoinvt.RecordSource = "SELECT * FROM invt"
adoinvt.Refresh
End Sub
REPORT
Private Sub cmdreport_Click()
DataReport1.Show
End Sub
42
DATA ENVIRONMENT- INVENTORY
43
DATA REPORT-INVENTORY
44
EX.NO: 5 INVOICE SYSTEM
DATE :
AIM:
To develop the project for the preparing Invoice using Visual
Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about calculating Invoice Amount,
tax, discount and balance amount of a customer for the items
purchased.
45
ENTITY – DIAGRAM
dateof invoice
membership no
invoicedate
phone
customername address
customerid
invoice
invoiceamt
balam
t
tax
amtpaid
netamt disamt
46
FORM DESIGN
47
CONTROLS
txtneta
txtphoneno cmddel
mt
txtaddress cmdexit
txtdateofmem cmdsearchcusid
txtinvoiceno cmdallsearch
txtinvoicedate
txtinvoiceamt
txtsearchcusid
48
VB CODING
GENERAL
FORM LOAD
ADDING,SAVING,MODIFYING,DELETING A RECORD
CALCULATION
49
Private Sub txtnetamt_Click()
txtnetamt.Text = Round(Val(txtinvoiceamt.Text) - Val(txtdisamt.Text)
+ Val(txttax.Text))
End Sub
Private Sub txtbalamt_Click()
txtbalamt.Text = Round(Val(txtamtpaid.Text) - Val(txtnetamt.Text))
End Sub
SEARCH
REPORT
50
DATA ENVIRONMENT- INVOICE
51
DATA REPORT-INVOICE
52
EX.NO: 6 Library information system
DATE :
AIM:
To develop the project for the Library Information System using
Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about Book Issue , Return and No.
of copies of book updation Calculations of an Library Memeber.
53
TABLE NAME : libmem
54
ENTITY RELATIONSHIP – DIAGRAM
author dateof
memname mem
bookname
publisher
bookid memid
address
supplier
book
libbook issue/ libmem
return
edition no.ofcopies
dor phone
renewdat
cost transdate
e
55
FORM DESIGN
56
CONTROLS
CALCULATE
INPUTS & COMMAND Adodc DATAGRID
OUTPUT BUTTON control control
textbox & combo box
txtmemid txttransdate cmdaddmem adodclibbk DataGrid1BOO
txtcpret
txtphone cmdissue
txtfine
cmbtrans cmdreturn
txtbkiddis cmdreport
txtbknamedis cmdbook
txtauthdis
txtcopdis
txtcopissu
57
VB CODING
GENERAL
Dim cn As New ADODB.Connection
Dim memrs As New ADODB.Recordset
Dim bkrs As New ADODB.Recordset
ADDING,SAVING,MODIFYING,DELETING A RECORD
58
CALCULATION
txtmemretdate.Text = Date
a = DateDiff("d", txtbkissuedt.Text, txtmemretdate.Text)
If (a <= 10) Then
txtfine.Text = 0
Else
b = a - 10
c = (b * 2)
txtfine.Text = Val(c)
End If
59
Dim copystk
copystk = Val(adodclibbk.Recordset.Fields("noofcopies"))
+ Val(txtcpret.Text)
adodclibbk.Recordset.Fields("noofcopies") = Str(copystk)
adodclibbk.Recordset.Update
MsgBox "book returned"
MsgBox "No.of copies after RETURN"
txtcopdis.Text = adodclibbk.Recordset.Fields("noofcopies")
adodclibmem.Recordset.Update
adodclibmem.Refresh
End Sub
REPORT
60
DATA ENVIRONMENT-LIBRARY SYSTEM
61
DATA REPORT-LIBRARY SYSTEM
62
EX.NO: 7 STUDENT INFORMATION SYSTEM
DATE :
AIM:
To develop the project for the Student Information System
using Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about personal details update of a
Student.
63
ENTITY – DIAGRAM
name
phone
dept
regno dob
addres
s
semester
studentdetails
64
FORM DESIGN
65
CONTROLS
txtname cmdmod
txtdob cmddel
txtaddress cmdexit
txtphone cmdsearchregno
txtsem cmdallsearch
cmdsearchdept
txtdept
txtsearchregno
txtsearchdept
66
VB CODING
GENERAL
ADDING,SAVING,MODIFYING,DELETING A RECORD
67
SEARCH
REPORT
68
DATA ENVIRONMENT
STUDENT INFORMATION SYSTEM
69
DATA REPORT- STUDENT INFORMATION
70
EX.NO: 8 INCOME TAX processing SYSTEM
DATE :
AIM:
To develop the project for the Income Tax Processing System
using Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about Annual Income, Tax amount
and Deductions Calculations of an Employee for Tax payment.
71
ENTITY – DIAGRAM
empname
phone
empid dept
dob
basicpay
doj
design
incometax
deduction dateoftaxge
s n
lastdaytopay
tax amount annual
income
72
FORM DESIGN
73
CONTROLS
txtlast
txtempname txtdateoftaxgen cmdmod
datepay
txtphone cmddel
txtdept cmdexit
txtdob cmdsearchempid
txtdoj cmdallsearch
txtdesign
txtbasicpay
txtdeductions
txtsearch
empid
74
VB CODING
GENERAL
ADDING,SAVING,MODIFYING,DELETING A RECORD
75
CALCULATION
76
DATA ENVIRONMENT- INCOME TAX
77
DATA REPORT-INCOME TAX
78
EX.NO: 9 Electricity bill preparation system
DATE :
AIM:
To develop the project for the Electricity Bill Preparation
System using Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about Current Meter Readings,
Number of Units consumed and Bill amount Calculations of
an Customer.
79
ENTITY – DIAGRAM
phoneno
address
customername
dateofmembership
customerid
prevmtread
ebcustomer
amount
currentmtreading
units
80
FORM DESIGN
81
CONTROLS
CALCUL DATAGRI
INPUTS OUTPUT COMMAND Adodc
ATE D
BUTTON control
textbox control
txtphoneno cmddel
txtaddress cmdexit
txtdateofmem cmdcalculate
txtprevmtread cmdreport
txtcurrread
cmdsearchcusid
cmdallsearch
82
VB CODING
GENERAL
ADDING,SAVING,MODIFYING,DELETING A RECORD
83
CALCULATION
SEARCH
REPORT
84
DATA ENVIRONMENT-ELECTRICITY BILL
85
DATA REPORT-ELECTRICITY BILL
86
EX.NO: 10 TELEPHONE DIRECTORY MAINTENANCE
DATE :
AIM:
To develop the project for the Telephone Directory Maintenance
Using Visual Basic 6.0.
PROJECT PLANNING:
The application should be developed by using the controls.
This project should describe about customer telephone
directory Maintenance.
87
ENTITY – DIAGRAM
phoneno dateofmem
address type
customername
facilities
areacode
customerid
telephone
88
FORM DESIGN
89
CONTROLS
INPUTS DATAGRI
COMMAND Adodc
D
textbox BUTTON control
control
txtcustomername cmdmod
txtaddress cmddel
txtdateofmem cmdexit
cmbtype cmdsearchtelephone
cmbfacilities txtsearchphone
cmbareacode
txtphoneno
90
VB CODING
GENERAL
cmbtype.AddItem "MOBILE"
cmbtype.AddItem "lANDLINE"
cmbfacilities.AddItem "LOCAL"
cmbfacilities.AddItem "LOCAL +STD"
cmbfacilities.AddItem "LOCAL + STD + ISD"
cmbareacode.AddItem "044"
cmbareacode.AddItem "+91"
End Sub
ADDING,SAVING,MODIFYING,DELETING A RECORD
REPORT
92
DATA ENVIRONMENT-TELEPHONE DIRECTORY
93
DATA REPORT-TELEPHONE DIRECTORY
94