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

VB Lab

Uploaded by

fayazahamed024
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)
20 views

VB Lab

Uploaded by

fayazahamed024
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/ 37

1.

SIMPLE CALCULATOR
FORM DESIGN:

CODING:
Dim no1, choice As Integer
Private Sub Command1_Click()
Text1.Text = Text1.Text & 1
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text & 0
End Sub
Private Sub Command11_Click()
Text1.Text = ""
End Sub
Private Sub Command12_Click()
If choice = 1 Then
Text1.Text = no1 + Text1.Text
ElseIf choice = 2 Then
Text1.Text = no1 - Text1.Text
ElseIf choice = 3 Then
Text1.Text = no1 * Text1.Text
ElseIf choice = 4 Then
Text1.Text = no1 / Text1.Text
ElseIf choice = 5 Then
End If
End Sub
Private Sub Command13_Click()
choice = 1
no1 = Val(Text1.Text)
Text1.Text = ""
End Sub
Private Sub Command14_Click()
choice = 2
no1 = Val(Text1.Text)
Text1.Text = ""
End Sub
Private Sub Command15_Click()
choice = 4
no1 = Val(Text1.Text)
Text1.Text = ""
End Sub
Private Sub Command16_Click()
choice = 3
no1 = Val(Text1.Text)
Text1.Text = ""
End Sub
Private Sub Command2_Click()
Text1.Text = Text1.Text & 2
End Sub
Private Sub Command3_Click()
Text1.Text = Text1.Text & 3
End Sub
Private Sub Command4_Click()
Text1.Text = Text1.Text & 4
End Sub
Private Sub Command5_Click()
Text1.Text = Text1.Text & 5
End Sub
Private Sub Command6_Click()
Text1.Text = Text1.Text & 6
End Sub
Private Sub Command7_Click()
Text1.Text = Text1.Text & 7
End Sub
Private Sub Command8_Click()
Text1.Text = Text1.Text & 8
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text & 9
End Sub
OUTPUT:
2.LOOPS AND DECISION MAKING

A) FIBONACCI SERIES
Form Design:

CODING:

Private Sub Command1_Click()


Dim f, s, ans, n As Integer
n = Val(Text1.Text)
ans = 0
f=0
List1.Addition f
List1.Addition s
cnt = 2
While (cnt < n)
ans = f + s
List1.AddItem ans
f=s
s = ans
cnt = cnt + 1
Wend
End Sub
Private Sub Command2_Click()
List1.Clear
Text1 = " "
End Sub
Private Sub Command3_Click()
End
End Sub

OUTPUT:
B) SUM OF N NUMBERS
FORM DESIGN:

CODING:

Private Sub Command1_Click()


Dim i, a As Integer
Cls
Dim n As Integer
n = Val(Text1.Text)
For i = 1 To n
s=s+i
Next i
Print "Sum Of ten serial Number=", s
Text2.Text = s
End Sub
Private Sub Command2_Click()
Text1.Text = " "
Text2.Text = " "
End Sub
Private Sub Command3_Click()
End
End Sub

OUTPUT:
3.MENU AND MDI FORM
Form Design:

Coding:

Private Sub cas_Click()

Form1.Show

Form2.Show

Form3.Show

Me.Arrange vbCascade

End Sub

Private Sub clr_Click()

CommonDialog1.ShowColor

Form1.BackColor = CommonDialog1.Color

End Sub

Private Sub frm1_Click()

Form1.Show
End Sub

Private Sub frm2_Click()

Form2.Show

End Sub

Private Sub frm3_Click()

Form3.Show

End Sub

Output:
4.RICHTEXT BOX
Form Design:

Coding:
Private Sub Dir1_Change()

File1.Path = Dir1.Path

End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1.Drive

End Sub

Private Sub File1_Click()

RichTextBox1.Text = File1.Path + "\" + File1.FileName

Image1.Picture = LoadPicture(RichTextBox1.Text)

End Sub
Output:
5.COMMONDIALOG CONTROL
Form Design:

Coding:

Dim i As Integer

Private Sub Command1_Click()

RichTextBox1.Text = " "

CommonDialog1.Filter = "text(text)text"

CommonDialog1.ShowOpen

Open CommonDialog1.FileName For Input As 1

Do Until EOF(1)

Input #1, Item

RichTextBox1.Text = RichTextBox1 & Item

i=i+1

Loop

Close #1

End Sub
Private Sub Command2_Click()

CommonDialog1.ShowSave

Open CommonDialog1.FileName For Output As #1

Print #1, RichTextBox1.Text

Close #1

End Sub

Private Sub Command3_Click()

CommonDialog1.Flags = edicfboth

CommonDialog1.ShowFont

RichTextBox1.Font.Name = CommonDialog1.FontName

RichTextBox1.Font.Italic = CommonDialog1.FontItalic

End Sub

Output:
6.ANIMATION USING TIMERS
Form Design:

Coding:

Private Sub Timer1_Timer()

If A >= 0 And A < 11130 Then

A = A + 100

Label1.Left = Label1.Left + 100

ElseIf A > 11130 And A < 22260 Then

A = A + 100

Label1.Left = Label1.Left - 100

ElseIf A = 22300 Then

A=0

End If

End Sub
Output:
7.NUMBER CONVERSION
Form Design:

Coding:

Private Sub Command1_Click()

bp = " "

ss = Trim(Text1.Text)

If ss = " " Then

MsgBox "Enter the value", "information"

Text1.SetFocus

Else

num = CInt(ss)

Text1.Enabled = False

Do While (num > 1)

bp = bp & num Mod 2

num = num / 2
Loop

Label2.Caption = "binary equivalent"

Label3.Caption = StrReverse(bp)

End If

End Sub

Private Sub Command2_Click()

bp = " "

ss = Trim(Text1.Text)

If ss = " " Then

MsgBox "Enter the value", vbInformation, "inforamtion"

Text1.SetFocus

Else

num = CInt(ss)

Text1.Enabled = False

Do While (num > 1)

bp = bp & num Mod 8

num = num / 8

Loop

Label2.Caption = "octal equivalent"

Label3.Caption = StrReverse(bp)

End If

End Sub
Private Sub Command3_Click()

Dim r As Integer

bp = " "

ss = Trim(Text1.Text)

If ss = " " Then

MsgBox "Enter the value", vbInformation, "inforamtion"

Text1.SetFocus

Else

num = CInt(ss)

Text1.Enabled = True

Do While (num > 1)

bp = bp & num Mod 16

Select Case r

Case 10

bp = bp & A

Case 11

bp = bp & B

Case 12

bp = bp & C

Case 13

bp = bp & D

Case 14
bp = bp & E

Case 15

bp = bp & F

Case Else

bp = bp & num Mod 16

End Select

num = num / 16

Loop

Label2.Caption = "Hexadecimal equivalent"

Label3.Caption = StrReverse(bp)

End If

End Sub

Private Sub Command4_Click()

Text1.Enabled = True

Text1.Text = " "

Text1.SetFocus

Label2.Caption = " "

Label3.Caption = " "

End Sub

Private Sub Command5_Click()

End

End Sub
Output:
8.EMPLOYEE DETAILS
SQL> create table emp(ename varchar(20),eno number(6)primary key,desg
varchar(6),gender char(2),age number(5),doj date,salary number(12));

Table created.

SQL> desc emp;

Name Null? Type

----------------------------------------- -------- -------------------------

ENAME VARCHAR2(20)

ENO NOT NULL NUMBER(6)

DESG VARCHAR2(6)

GENDER CHAR(2)

AGE NUMBER(5)

DOJ DATE

SALARY NUMBER(12)

SQL> insert into emp


values('&name','&eno','&desg','&gender','&age','&doj','&salary');

Enter value for name: kutta

Enter value for eno: 5

Enter value for desg: gm

Enter value for gender: f

Enter value for age: 20

Enter value for doj: 17/june/2016


Enter value for salary: 45000

old 1: insert into emp


values('&name','&eno','&desg','&gender','&age','&doj' ,&salary')

new 1: insert into emp


values('kutta','5','gm','f','20','17/june/2016','45000’)

1 row created.

SQL> /

Enter value for name: sofiya

Enter value for eno: 6

Enter value for desg: bca

Enter value for gender: f

Enter value for age: 19

Enter value for doj: 22/oct/2017

Enter value for salary: 30000

old 1: insert into emp


values('&name','&eno','&desg','&gender','&age','&doj',’&salary')

new 1: insert into emp


values('sofiya','6','bca','f','19','22/oct/2017','30000’)

1 row created
SQL> select*from emp;

ENAME ENO DESG GE AGE DOJ SALARY

-------------------- ---------- ------ -- ---------- --------- ----------

kutta 5 gm f 20 17-JUN-16 45000

priya 4 bca f 20 21-OCT-19 35000

sofiya 6 bca f 19 22-OCT-17 30000

SQL> select*from emp where salary=(select max(salary)from emp);

ENAME ENO DESG GE AGE DOJ SALARY

-------------------- ---------- ------ -- ---------- --------- ----------

kutta 5 bca f 20 17-JUN-16 45000

SQL> select*from emp where salary=(select min(salary)from emp);

ENA ENO DESG GE AGE DOJ SALARY

-------------------- ---------- ------ -- ---------- --------- ----------

sofiya 6 bca f 19 22-OCT-17 30000

SQL> commit;

Commit complete.
9.INVENTORY
SQL>create table inventory(productno number(5),productname
varchar(20),rate number(5));

Table created.

SQL> insert into inventory values('201','TV','15000');

1 row created.

SQL> insert into inventory values('202','Washing Machine','20000');

1 row created.

SQL> insert into inventory values('203','Radio','500');

1 row created.

SQL> select*from inventory;

PRODUCTNO PRODUCTNAME RATE

---------- -------------------- ----------

201 TV 15000

202 Washing Machine 20000

203 Radio 500

204 CD 250

205 AC 650

SQL> begin

2 update inventory set rate=rate+rate*(20/100);

3 commit;

4 end;
5 /

PL/SQL procedure successfully completed.

SQL> select*from inventory;

PRODUCTNO PRODUCTNAME RATE

---------- -------------------- ----------

201 TV 18000

202 Washing Machine 24000

203 Radio 600

204 CD 300

205 AC 780

SQL> alter table inventory add count number(4);

Table altered.

SQL> alter table inventory add place varchar(20);

Table altered.

SQL> update inventory set count=10,place='Coimbatore'where


productno=201;

1 row updated.

SQL> update inventory set count=12,place='OOty'where productno=202;

1 row updated.

SQL> update inventory set count=30,place='Trichy'where productno=203;

1 row updated.
SQL> update inventory set count=30,place='Madurai'where
productno=204;

1 row updated.

SQL> update inventory set count=35,place='Chennai'where productno=205

1 row updated.

SQL> select*from inventory;

PRODUCTNO PRODUCTNAME RATE COUNT PLACE

---------- -------------------- ---------- ---------- --------------------

201 TV 18000 10 Coimbatore

202 Washing Machine 24000 12 OOty

203 Radio 600 30 Trichy

204 CD 300 30 Madurai

205 AC 780 35 Chennai

SQL> create table inv_msc(itemno number(10)primary key,itemname


varchar(50),itemprice number(5));

Table created.
10.TRIGGERS
SQL> insert into inv_msc values(&itemno,'&itemname',&itemprice);

Enter value for itemno: 1001

Enter value for itemname: apple

Enter value for itemprice: 100

old 1: insert into inv_msc values(&itemno,'&itemname',&itemprice)

new 1: insert into inv_msc values(1001,'apple',100)

1 row created.

SQL> /

Enter value for itemno: 1002

Enter value for itemname: orange

Enter value for itemprice: 200

old 1: insert into inv_msc values(&itemno,'&itemname',&itemprice)

new 1: insert into inv_msc values(1002,'orange',200)

1 row created.

SQL> /

SQL> select*from inv_msc;

ITEMNO ITEMNAME ITEMPRICE

---------- -------------------------------------------------- ----------

1001 apple 100

1002 orange 200


SQL> create table inv_trs(itemno number(10)references
inv_msc(itemno),it_pdate date,it_sdate date,cust_name varchar(30));

Table created.

SQL> create or replace trigger inv_trigg_ins_trs

2 before insert on inv_trs for each row

3 declare

4 begin

5 if :new.it_sdate> :new.it_pdate+30 then

6 raise_application_error(-20000,'invalid period;validity of item is over');

7 end if;

8 end;

9 /

Trigger created.

SQL> insert into inv_trs


values(&itemno,'&it_pdate','&it_sdate','&custname');

Enter value for itemno: 1001

Enter value for it_pdate: 12/dec/12

Enter value for it_sdate: 16/dec/12

Enter value for custname: anu

old 1: insert into inv_trs


values(&itemno,'&it_pdate','&it_sdate','&custname')

new 1: insert into inv_trs values(1001,'12/dec/12','16/dec/12','anu')

1 row created.
SQL> insert into inv_trs
values(&itemno,'&it_pdate','&it_sdate','&custname');

Enter value for itemno: 1002

Enter value for it_pdate: 18/oct/15

Enter value for it_sdate: 22/oct/15

Enter value for custname: priya

old 1: insert into inv_trs


values(&itemno,'&it_pdate','&it_sdate','&custname')

new 1: insert into inv_trs values(1002,'18/oct/15','22/oct/15','priya')

1 row created.

SQL> desc inv_trs;

Name Null? Type

----------------------------------------- -------- ------------------------

ITEMNO NUMBER(10)

IT_PDATE DATE

IT_SDATE DATE

CUST_NAME VARCHAR2(30)

SQL> select*from inv_trs;

ITEMNO IT_PDATE IT_SDATE CUST_NAME

---------- --------- --------- ------------------------------

1001 12-DEC-12 16-DEC-12 anu

1002 18-OCT-15 22-OCT-15 priya


11.PROCEDURES
SQL> create table std1(sno number(20)primary

key,sname,varchar(20),smark number(10),sresult varchar(10));

Table created.

SQL> desc std1;

Name Null? Type

----------------------------------------- -------- -------------------------

SNO NOT NULL NUMBER(20)

SNAME VARCHAR2(20)

SMARK NUMBER(10)

SRESULT VARCHAR2(10)

SQL> insert into std1 values(1,'mithran',25,'f');

1 row created.

SQL> insert into std1 values(2,'arun',86,'p');

1 row created.

SQL> insert into std1 values(3,'sam',78,'p');

1 row created.

SQL> select*from std1;

SNO SNAME SMARK SRESULT

---------- -------------------- ---------- ----------

1 mithran 25 f

2 arun 86 p
3 sam 78 p

SQL> create table std1_fail(sno number(20)primary key,sname


varchar(20),smark nu

mber(10),sresult varchar(10));

Table created.

SQL> create table std1_pass(sno number(20)primary key,sname


varchar(20),smark number(10),sresult varchar(10));

Table created.

SQL> declare

2 v_no std1.sno%type;

3 v_name std1.sname%type;

4 v_mark std1.smark%type;

5 v_result std1.sresult%type;

6 cursor curs_std1 is

7 select sno,sname,smark,sresult from std1;

8 begin

9 open curs_std1;

10 fetch curs_std1 into v_no,v_name,v_mark,v_result;

11 loop

12 if v_result='p'then

13 insert into std1_pass values(v_no,v_name,v_mark,v_result);

14 else
15 insert into std1_fail values(v_no,v_name,v_mark,v_result);

16 end if;

17 fetch curs_std1 into v_no,v_name,v_mark,v_result;

18 exit when curs_std1%notfound;

19 end loop;

20 close curs_std1;

21 end;

22 /

PL/SQL procedure successfully completed.

SQL> select*from std1_fail;

SNO SNAME SMARK SRESULT

---------- -------------------- ---------- ----------

1 mithran 25 f

SQL> select*from std1_pass;

SNO SNAME SMARK SRESULT

---------- -------------------- ---------- ----------

2 arun 86 p

3 sam 78 p
12.STUDENT MARKLIST
Form Design:

Coding:

Dim adodc As Recordset

Private Sub Command1_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

Text6.Text = ""

Text7.Text = ""

Adodc1.Recordset.AddNew

MsgBox "Now you can add the records"

Text1.SetFocus

End Sub
Private Sub Command2_Click()

End

End Sub

Private Sub Command3_Click()

Adodc1.Recordset.Save

MsgBox " Record saved"

End Sub

Private Sub Command4_Click()

Adodc1.Recordset.Update

End Sub

Private Sub Command5_Click()

Adodc1.Recordset.Delete

MsgBox "Record deleted"

End Sub

Private Sub Command6_Click()

Text7.Text = Val(Text4.Text) + Val(Text6.Text)

End Sub

Private Sub Command7_Click()

Text8.Text = Text7.Text / 3

End Sub

SQL Coding:
SQL> create table stud(rollno number(10),name varchar(20),course
varchar(10),mark1 number(10),mark2 number(10),mark3 number(10),total
number(10),average number 10));

Table created.

SQL> desc stud;

Name Null? Type

----------------------------------------- -------- -------------------------

ROLLNO NUMBER(10)

NAME VARCHAR2(20)

COURSE VARCHAR2(10)

MARK1 NUMBER(10)

MARK2 NUMBER(10)

MARK3 NUMBER(10)

TOTAL NUMBER(10)

AVERAGE NUMBER(10)

SQL> select*from stud;

ROLLNO NAME COURSE MARK1 MARK2 MARK3

---------- -------------------- ---------- ---------- ---------- ----------

TOTAL AVERAGE

---------- ----------

Saji BCA 78 87 80

158 52
OUTPUT:

You might also like