visual basic programs
DESCRIPTION
visual basic programsTRANSCRIPT
VISUAL
PROGRAMMING
CALCULATOR
FORM DESIGN
CODING
Private Sub OFF_Click()
End
End Sub
Private Sub plus_Click ()
Text1.Text = " "
preval = curval
curval = 0
choice = "+"
End Sub
Private Sub negative_Click()
curval = -curval
Text1.Text = curval
End Sub
Private Sub mul_Click()
Text1.Text = " "
preval = curval
curval = 0
choice = "*"
End Sub
Private Sub minus_Click()
Text1.Text = " "
preval = curval
curval = 0
choice = "-"
End Sub
Private Sub equal_Click()
Select Case choice
Case "+"
result = preval + curval
Text1.Text = Str(result)
Case "-"
result = preval - curval
Text1.Text = Str(result)
Case "*"
resulty = preval * curval
Text1.Text = Str(result)
Case "/"
result = preval / curval
Text1.Text = Str(result)
End Select
End Sub
Private Sub div_Click()
Text1.Text = " "
preval = curval
curval = 0
choice = "/"
End Sub
OUTPUT
COMMON DIALOG BOX
FORM DESIGN
CODING
Private Sub colorfont_Click()
cmd.ShowColor
rtbx1.SelColor = (cmd.Color)
End Sub
Private Sub fontstyle_Click()
cmd.ShowFont
rtbx1.SelFontName = (cmd.FontBold)
rtbx1.SelFontSize = (cmd.FontSize)
rtbx1.SelItalic = (cmd.FontItalic)
End Sub
Private Sub openfile_Click()
cmd.ShowOpen
rtbx1.LoadFile (cmd.FileName)
End Sub
Private Sub savefile_Click()
cmd.ShowSave
rtbx1.savefile (cmd.FileName)
End Sub
OUTPUT
CAR ANIMATION
FORM DESIGN
CODING
Dim iAs Integer
Dim X As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
Timer2.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub Form_Load()
X = Frame1.Left
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Frame1.Left >= Form1.ScaleWidth Then
Frame1.Left = X
Else
Frame1.Left = Frame1.Left + 100
End If
End Sub
Private Sub Timer2_Timer()
i = i + 1
Select Case i
Case 1
Shape1.FillStyle = 2
Shape2.FillStyle = 2
Case 2
Shape1.FillStyle = 4
Shape2.FillStyle = 4
Case 3
Shape1.FillStyle = 5
Shape2.FillStyle = 5
Case 4
Shape1.FillStyle = 5
Shape2.FillStyle = 5
i = 0
End Select
End Sub
OUTPUT
MSFLEX GRID
FORM DESIGN
CODING
Dim a As Integer
Dim x As Integer
Dim y As Integer
Private Sub ADD_Click()
For x = 1 To 12
MSFlexGrid1.Row = x
For y = 1 To 12
MSFlexGrid1.Col = y
MSFlexGrid1.Text = x + y
Next y
Next x
End Sub
Private Sub DIV_Click()
For x = 1 To 12
MSFlexGrid1.Row = x
For y = 1 To 12
MSFlexGrid1.Col = y
MSFlexGrid1.Text = Round((x / y), 2)
Next y
Next x
End Sub
Private Sub Form_Load()
MSFlexGrid1.Col = 0
For x = 1 To 12
MSFlexGrid1.Row = x
MSFlexGrid1.Text = Str(x)
Next x
MSFlexGrid1.Row = 0
For x = 1 To 12
MSFlexGrid1.Col = x
MSFlexGrid1.Text = Str(x)
Next x
End Sub
Private Sub MUL_Click()
For x = 1 To 12
MSFlexGrid1.Row = x
For y = 1 To 12
MSFlexGrid1.Col = y
MSFlexGrid1.Text = x * y
Next y
Next x
End Sub
Private Sub SUB_Click()
For x = 1 To 12
MSFlexGrid1.Row = x
For y = 1 To 12
MSFlexGrid1.Col = y
MSFlexGrid1.Text = x - y
Next y
Next x
End Sub
OUTPUT
PAYROLL MANAGEMENT SYSTEM
FORM DESIGN
CODING
FORM 1
Private Sub cancel_Click()
End
End Sub
Private Sub submit_Click()
If Text1.Text = "admin" And Text2.Text = "pass" Then
grp.Show
Else
MsgBox "wrong input"
End If
End Sub
FORM 2
Private Sub add_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub calculate_Click()
grp.Text = Val(da.Text) + Val(hra.Text) + Val(prf.Text) + Val(slry.Text)
End Sub
Private Sub delete_Click()
Adodc1.Recordset.delete
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub next_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MoveFirst
End If
End Sub
Private Sub previous_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF = True Then
Adodc1.Recordset.MoveLast
End If
End Sub
Private Sub REPORT_Click()
DataReport1.Show
End Sub
Private Sub update_Click()
Adodc1.Recordset.updat
End sub
OUTPUT
STUDENT DETAILS
FORM 1
FORM 2
FORM 3
CODING
FORM 1
Private Sub MNPLTLN_Click()
Form2.Show
End Sub
Private Sub RPT_Click()
DataReport1.Show
End Sub
Private Sub STD_Click()
Form3.Show
End Sub
FORM 3
Private Sub ADD_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub average_Click()
Text7.Text = Val(text6.Text) / 3
End Sub
Private Sub clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
End Sub
Private Sub delete_Click()
Adodc1.Recordset.delete
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub exit_Click()
End
End Sub
Private Sub menu_Click()
Form1.Show
End Sub
Private Sub next_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MoveFirst
End If
End Sub
Private Sub previous_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MoveFirst
End If
End Sub
Private Sub total_Click()
Text6.Text = Val(text3.Text) + Val(text4.Text) + Val(text5.Text)
End Sub
Private Sub update_Click()
Adodc1.Recordset.update
End Sub
OUTPUT
Creating Window using MFC
#include<afxwin.h>class MyFrame:public CFrameWnd
{public:MyFrame(){Create (0,"My first application");}};
class Myapp:public CWinApp{MyFrame * w;public:
int InitInstance(){w=new MyFrame();m_pMainWnd=w;m_pMainWnd->ShowWindow(1);return 1;}};Myapp a;
OUTPUT
MESSAGE MAP
#include<afxwin.h>class MyFrame:public CFrameWnd{public:
MyFrame(){Create(0,"Message demo");}int OnCreate(){MessageBox("First Message","Hello");return 0;}int OnPaint(){CFrameWnd::OnPaint();MessageBox("Second Message","Hi");return 0;}DECLARE_MESSAGE_MAP()
};BEGIN_MESSAGE_MAP(MyFrame,CFrameWnd)ON_WM_CREATE()ON_WM_PAINT()END_MESSAGE_MAP()class MyApp:public CWinApp{
int InitInstance(){
MyFrame * p;p=new MyFrame();m_pMainWnd = p;p->ShowWindow(1);return 1;
}};MyApp b;
OUTPUT
SHAPE
#include<afxwin.h>class MyFrame:public CFrameWnd{public:MyFrame()
{Create(0,"drawing rectangle, pie");}void OnPaint(){
CPaintDC d(this);CBrush MyBrush(RGB(255,0,0));d.SelectObject(&MyBrush);d.MoveTo(10,10);d.Rectangle(10,20,200,100);d.Ellipse(140,150,230,240);
}DECLARE_MESSAGE_MAP()};BEGIN_MESSAGE_MAP(MyFrame,CFrameWnd)ON_WM_PAINT()END_MESSAGE_MAP()class MyApp:public CWinApp{
int InitInstance() {
MyFrame * p;p=new MyFrame();p->ShowWindow(1);m_pMainWnd=p;return 1;
}};MyApp c;
OUTPUT
RDBMS
SIMPLE QUERIES
CREATING TABLE
SQL> create table product_master
2 (product_no varchar(6),
3 description varchar(15),
4 profitpercent number(6),
5 unitmeasure varchar(5),
6 qty_on_hand number(4),
7 reorder number(3),
8 sell_price number(6),
9 cost_price number(6));
Table created.
Sql> insert into product_master values
('&product_no','&description',&profitpercent,'&unitmeasure',&qty_on_hand,
&reorder,&sell_price);
QUERIES
SQL> select product_no,description from product_master where cost_price>=2000;
PRODUC DESCRIPTION
------ ---------------
P03453 MONITORS
P07868 KEYBOARDS
P07885 CD DRIVE
P07965 540 HDD
SQL> select product_no,description,profitpercent from product_master where profitpercent<5;
PRODUC DESCRIPTION PROFITPERCENT
------ --------------- -------------
P07868 KEYBOARDS 2
P07885 CD DRIVE 3
P07965 540 HDD 4
SQL> select product_no,description,profitpercent,sell_price from product_master where profitpercent>=10 and profitpercent<=20;
no rows selected
SQL> select product_no,description,profitpercent,sell_price from product_master where profitpercent not between 10 and 15;
PRODUC DESCRIPTION PROFITPERCENT SELL_PRICE
------ --------------- ------------- ----------
p00001 1.44 FLOPPIES 5 525
P03453 MONITORS 6 12000
P06734 MOUSE 5 1050
P07865 1.22 FLOPPIES 5 525
P07868 KEYBOARDS 2 3150
P07885 CD DRIVE 3 250
P07965 540 HDD 4 8400
P07975 1.44 DRIVE 5 1050
P08865 1.22 DRIVE 5 1050
9 rows selected.
SQL> select description from product_master order by description;
DESCRIPTION
---------------
1.22 DRIVE
1.22 FLOPPIES
1.44 DRIVE
1.44 FLOPPIES
540 HDD
CD DRIVE
KEYBOARDS
MONITORS
MOUSE
9 rows selected.
SQL> select product_no from product_master order by product_nodesc;
PRODUC
------
p00001
P08865
P07975
P07965
P07885
P07868
P07865
P06734
P03453
9 rows selected.
SQL> select product_no,description,qty_on_hand from product_master where qty_on_hand=200
2 Union
3 selectproduct_no,description,qty_on_hand from product_master where qty_on_hand=300;
no rows selected
SQL> select product_no,description,sell_price,cost_price from product_master
where sell_price<1000
2 intersect
3 selectproduct_no,description,sell_price,cost_price from product_master where sell_price>1000;
no rows selected
SQL> delete from product_master where qty_on_hand=100;
2 rows deleted.
BUILT IN FUNCTIONS
CREATING TABLE
SQL> create table product_master
2 (product_no varchar(6),
3 description varchar(15),
4 profitpercent number(6),
5 unitmeasure varchar(5),
6 qty_on_hand number(4),
7 reorder_ivi number(3),
8 sell_price number(6),
9 cost_price number(6));
Table created.
SQL> insert into product_master values ('&product_no','&description',&profitpercent,'&unitmeasure',&qty_on_hand,&reorder_ivi,&sell_price);
PROD_N DESCRIPTION PROFIT UNIT QTY_ON_HAND RECORDER SELL_PRICE COST_PRICE
------ ---------- -------------- ------ ----------- --------- ---------- ------------------------------------------------------------------
P00001 FLOPPIES 5 PIECE 100 20 525 500
P03453 monitors 6 PIECE 10 3 12000 11280
P06734 mouse 5 PIECE 20 5 1500 1250
P07865 1floppie 5 PIECE 100 20 525 500
P07868 keyboard 2 PIECE 10 3 3150 3050
FROM THE TABLE PRODUCT_MASTER
SQL> select avg(sell_price) from product_master;
AVG(SELL_PRICE)
---------------
4525
SQL> select min(qty_on_hand) from product_master;
MIN(QTY_ON_HAND)
----------------
10
SQL> select count(recorder) from product_master;
COUNT(RECORDER)
---------------
5
SQL> select max(cost_price) from product_master;
M\AX(COST_PRICE)
---------------
11280
SQL> select sum(cost_price) from product_master;
SUM(COST_PRICE)
---------------
12980
FROM THE DUAL
(i)abs(n)
SQL> select abs(-15)from dual;
ABS(-15)
---------
15
(ii)power(m,n)
SQL> select power(2,3)from dual;
POWER(2,3)
----------
8
(iii)round(m,n)
SQL> select round(15.19)from dual;
ROUND(15.19)
------------
15
(iv)sqrt(n)
SQL> select sqrt(25)from dual;
SQRT(25)
---------
5
(v)upper(char)
SQL> select upper('oracle')from dual;
UPPER
------
ORACLE
(vi)substr(char,m,n)
SQL> select substr('secure',3)from dual;
SUBSTR
-----------
Cure
(vii)length(char)
SQL> select length('nisha')from dual;
LENGTH('NISHA')
---------------
5
(viii)Ltrim()
SQL> select ltrim('nisha','n')from dual;
LTRI
----
isha
(ix)Rtrim()
SQL> select rtrim('sunila','a')from dual;
RTRIM
-----
Sunil
(x)Lpad()
SQL> select lpad('page1',10,'*')from dual;
LPAD('PAGE
----------
*****page1
(xi)Rpad()
SQL> select rpad('cms college',10,'*')from dual;
RPAD('CMSC
----------cms college
ELECTRICITY BILL
PL/SQL CODE
1 declare
2 cursoreb is select * from ebill;
3 begin
4 for e in eb
5 loop
6 if(e.unit>=500) then
7 e.amount:=((e.unit-500)*3)+600+100+50;
8 elsif (e.unit>=200) then
9 e.amount:=((e.unit-200)*2)+100+50;
10 elsif(e.unit>=100) then
11 e.amount:=((e.unit-100)*1)+50;
12 else
13 e.amount:=e.unit*0.5;
14 end if;
15 update ebill set amount = e.amount where cuso=e.cuso;
16 end loop;
17* end;
PL/SQL procedure successfully completed
CREATION OF TABLE
SQL> create table ebill
2 (cuso varchar2(6),
3 custname varchar2(10),
4 unit number(4),
5 amount number(8,2));
Table created.
INSERTION
SQL>insert into ebill(cuso,custname,unit)values('e001','anju',200)
1 row created.
SQL>insert into ebill(cuso,custname,uni)values('e002','anju',500)
1 row created.
sQL> insert into ebill(cuso,custname,unit)values('e003','ramu',400);
1row created.
OUTPUT
SQL> select * from ebill;
CUSO CUSTNAME UNIT AMOUNT
----- ---------- --------- ---------------------------
e001 anju 200 150
e002 amu 500 750
e003 ramu 453 550
SPLITTING OF TABLES
PL/SQL CODE
SQL> declare
2 cursor stud is select * from sent;
3 begin
4 for s in stud
5 loop
6 ifs.result='pass' then
7 insert into pas values(s.sid,s.name);
8 else
9 insert into fail values(s.sid,s.name);
10 end if;
11 end loop;
12 end;
13 /
PL/SQL procedure successfully completed.
CREATION OF TABLE
SQL> create table sent
2 (sid varchar2(4),
3 name varchar2(10),
4 result varchar2(6));
Table created.
SQL> create table pass
2 (sid varchar2(10),
3 name varchar2(10));
Table created.
SQL> create table fail
2 (sid varchar2(4),
3 name varchar2(10));
Table created.
INSERTION
SQL> insert into sent values
2 ('&sid','&name','&result');
Enter value for sid: e001
Enter value for name: gibin
Enter value for result: pass
old 2: ('&sid','&name','&result')
new 2: ('e001','gibin','pass')
1 row created.
SQL> /
Enter value for sid: e002
Enter value for name: arun
Enter value for result: fail
old 2: ('&sid','&name','&result')
new 2: ('e002','arun','fail')
1 row created.
SQL> /
Enter value for sid: e003
Enter value for name: renu
Enter value for result: pass
old 2: ('&sid','&name','&result')
new 2: ('e003','renu','pass')
1 row created.
OUTPUT
SQL> select * from pass;
SID NAME
---- ---------- ---
E001 GIBIN
E003 RENU
SQL> select * from fail;
SID NAME
---- ---------- ---
E002 ARUN
JOINING OF TABLES
PL/SQL CODE
1 declare
2 cursorcur_id is select f.sid,f.sname,f.tot,s.addr from ftablef,stable s where f.sid=s.sid;
3 sid ftable.sid%type;
4 sname ftable.sname%type;
5 tot ftable.tot%type;
6 addr stable.addr%type;
7 nodata exception;
8 begin
9 open cur_id;
10 loop
11 fetch cur_id into sid,sname,tot,addr;
12 if(cur_id% notfound)then
13 raise nodata;
14 end if;
15 insert into ttable values(sid,sname,tot,addr);
16 end loop;
17 exception
18 when nodata then
19 if cur_id% rowcount=0 then
20 dbms_output.put_line('there is no more record');
21 else
22 dbms_output.put_line('program executed');
23 end if;
24* end;
SQL> /
PL/SQL procedure successfully completed.
CREATION OF TABLES
SQL> create table ftable
2 (sidvarchar(10)primary key,
3 snamevarchar(20),
4 tot number(4));
Table created.
SQL> create table stable
2 (sidvarchar(10)references ftable(sid),
3 addrvarchar(20));
Table created.
SQL> create table ttable
2 (sidvarchar(10),
3 snamevarchar(20),
4 tot number(4),
5 addrvarchar(20));
Table created.
INSERTION
SQL> insert into ftablevalues('&sid','&sname',&tot);
SQL> insert into stable values('&sid','&addr');
OUTPUT
SQL> select * from ftable;
SID SNAME TOT
---------- -------------------- --------- -
S01 aaa 94
S02 bbb 59
S03 ccc 78
S04 ddd 89
SQL> select * from stable;
SID ADDR
---------- ---------
S01 CBE
S02 BLR
S03 CLT
S04 TCR
SQL> select * from ttable;
SID SNAME TOT ADDR
---------- -------------------- --------- ---------------
S01 aaa 94 CBE
S02 bbb 59 BLR
S03 ccc 78 CLT
S04 ddd 89 TCR
SQL>
TRIGGER
PL/SQL CODE
SQL> create or replace trigger validity
2 before insert on marks
3 for each row
4 begin
5 if :new.mark1>100 or :new.mark2>100
6 or :new.mark3>100 or :new.mark1<0 or
7 :new.mark2<0 or :new.mark3<0 then
8 raise_application_error(-20002,'invalid marks');
9 end if;
10 end;
11 /
Trigger created.
Execution of code:
SQL>z:\fibo.sql
CREATION OF TABLES
SQL> create table marks(mark1 number(3),mark2 number(3),mark3 number(3));
Table created
OUTPUT
SQL> insert into mark values(&mark1,&mark2,&mark3);
Enter value for mark1: 192
Enter value for mark2: 79
Enter value for mark3: 49
old 1: insert into mark values(&mark1,&mark2,&mark3)
new 1: insert into mark values(192,79,49)
ERROR at line 1:
ORA-20002:invalid marks
ORA-06512:at"HR VALIDITY",line1
ORA-04088:error during execution of trigger'HR VALIDITY'
RECURSIVE FUNCTION
A.FACTORIAL
FUNCTION
SQL> create or replace function fact(n in number)
2 return number is num number;
3 begin
4 if n=0 then
5 return 0;
6 elsif n=1 then
7 return 1;
8 else
9 num:=n*fact(n-1);
10 end if;
11 returnnum;
12 end;
13 /
Function created.
Sql> set serveroutput on;
PL/SQL CODE
SQL> declare
2 numb number;
3 i number;
4 begin
5 numb:=&number;
6 dbms_output.put_line(fact(numb));
7 end;
8 /
Execution of code:
SQL>z:\fact.sql
OUTPUT
Enter value for number: 5
old 5: numb:=&number;
new 5: numb:=5;
120
PL/SQL procedure successfully completed.
B.FIBONOCCI
FUNCTION
SQL> create or replace function fact(n in number)
2 return number is num number;
3 begin
4 if n=0 then
5 return 0;
6 elsif n=1 then
7 return 1;
8 else
9 num:=n*fact(n-1);
10 end if;
11 return num;
12 end;
13 /
Function created.
Sql> set serveroutput on;
PL/SQL CODE
SQL> declare
2 no number;
3 i number;
4 begin
5 no:=&number;
6 for i in 0..(no-1)
7 loop
8 dbms_output.put_line(fibo(i));
9 end loop;
10 end;
11 /
Execution of code:
SQL>z:\fibo.sql
OUTPUT
Enter value for number: 7
old 5: no:=&number;
new 5: no:=7;
0
1
1
2
3
5
8
PL/SQL procedure successfully completed.