VB Programs
Content
1.Arithmetic calculation
2.Control structure
3.Colour palatee
4.Mouse down Event
5.Serial ball moving
6.Image Resize
7.Picture Animation with timer
control
8.clock animation using timer
9.Simple and compound interest
calculation
10.Fibonacii serial
11.Timer
12.Picture animation
13.DAO Control
14.ADO Control
15.Sub procedure
16. Number puzzle
17.Font Dialog box
18.Monthly sales details flex
grid control
19.MS FlexGrid control
20.Picture box and image box
21.Matrix
Addition
22.String function
23.EYE Animation
First Value |
Second Value |
Text 1 |
Text2 |
Text 3 |
Text4 |
Text5 |
Text6 |
Command 1 |
Command 2 |
Command 3 |
Command 4 |
Private sub command 1_click()
Text3.text=val(text1.text)+val(text2.text)
End sub
Private sub command 2_click()
Text4.text=val(text1.text)-val(text2.text)
End sub
Private sub command 3_click()
Text5.text=val(text1.text)*val(text2.text)
End sub
Private sub command 4_click()
Text6.text=val(text1.text)/val(text2.text)
End sub
2. Control
structure
1.If
–then statement
2.If-then-else
statement
3.IF-Then
else if statement
4.Select
case statement
1.IF
Private sub form_click()
Dim n as integer
N=inputbox(“Enter any value”)
If(n>10)then
Msgbox”The ans is =”&n
Endif
Endsub
2.If-else
Private sub form_click()
Dim a,b as integer
A=inputbox(“Enter A value”)
B=inputbox(“Enter b value”)
If (a>b) then
Msgbox”A is big”&a
Else
Msgbox”B is big”&b
Endif
End sub
3.if else if
Private sub form1_click()
Dim a,b,c as integer
A=inputbox(“Enter a value”)
B=inputbox(“Enter b value”)
C=inputbox(“Enter c value”)
If (a>b) and(a>c) then
Msgbox “A is big”&a
ElseIf(b>c) then
Msgbox”B is big”&b
Else
Msgbox”c is big”&c
Endif
End sub
4.Select Case
Private sub form1_click()
dim n as integer
n=inputbox(“enter the value”)
select case(n)
case 1
msgbox”ONE”
case 2
msgbox”TWO”
case 3
msgbox”THREE”
case else
msgbox”give 1 to 3”
End select
End sub
5. Multiplication table
Private sub form_click()
dim a,i,s,b as integer
s=1
a=inputbox(“enter the table number”)
b=inputbox(“enter the table limited”)
for s=1 to b
i=s*a
print s;”*”;a;”=”;i
next s
End sub
End
End sub
Private sub form_load()
Hscroll1.max=255
Hscroll1.min=0
Hscroll2.min=0
Hscroll2.max=255
Hscroll3.min=0
Hscroll3.max=255
End sub
Private sub HSCROLL1_Change()
Text1.backcolor=RGB(Hscroll1.value,Hscroll2.value,Hscroll3.value)
End sub
Private sub HSCROLL2_Change()
Text1.backcolor=RGB(Hscroll1.value,Hscroll2.value,Hscroll3.value)
End sub
Private sub HSCROLL3_Change()
Text1.backcolor=RGB(Hscroll1.value,Hscroll2.value,Hscroll3.value)
End sub
4.Mouse down Event
Private sub form_mousedown(Button as integer,shift as
integer,x as single, y as single)
Circle
(x,y),500,RGB(Rnd*255,Rnd*255,Rnd*255)
End sub
5.Serial ball moving
Private sub command1_click()
End
End sub
Private sub form_load()
Me.windowstate=2
Shape2. visible=false
Shape4.visible=false
Shape6.visible=false
End sub
Private sub Timer1_timer()
If shape1.visible=true then
Shape3.visible=true
Shape5.visible=true
Shape1.visible=false
Shape3.visible=false
Shape5.visible=false
Shape2.visible=true
Shape4.visible=true
Shape6.visible=true
Elseif shape2.visible=true then
Shape4.visible=true
Shape6.visible=true
Shape2.visible=false
Shape4.visible=false
Shape6.visible=false
Shape1.visible=true
Shape3.visible=true
Shape5.visible=true
End if
End sub
6.Image Resize
Private sub command1_click()
Me.backcolor=RGB(Hscroll1.value,Rnd*255,Rnd*255)
End sub
Private sub command2_click()
Unload me
End sub
Private sub form_load()
Me.windowstate=2
Image1.stretch=true
End sub
Private sub hscroll1_change()
Image1.width=hscroll1.value
Hscroll1.largechange=300
Hscroll1.smallchange=50
Hscroll1.max=2300
Hscroll1.min=100
End sub
Private sub vscroll1_change()
Vscroll1.largechange=300
Vscroll1.smallchange=50
Vscroll1.max=2500
Vscroll1.min=300
Image1.height=vscroll1.value
End sub
7.Picture Animation with timer control
Timer
Private sub form_load()
Timer1.interval=1000
End sub
Private sub
timer1_timer()
Set p=picture1.picture
Picture1.picture=picture2.picture
Picture2.picture=picture3.picture
Picture3.picture=picture4.picture
Picture4.picture=p
End sub
8.clock animation using timer
Private sub form_load()
Me.windowstate=2
Line2.visible=false
Line3.visible=false
Line4.visible=false
Line5.visible=false
Line6.visible=false
Line7.visible=false
Line8.visible=false
Line9.visible=false
Line10.visible=false
Line11.visible=false
Line12.visible=false
End sub
Private Sub Timer1_timer()
If line1.visible=true then
Line1.visible=false
Line2.visible=true
Elseif line2.visible=true then
Line2.visible=false
Line3.visible=true
Elseif line3.visible=true then
Line3.visible=false
Line4.visible=true
Elseif line4.visible=true then
Line4.visible=false
Line5.visible=true
Elseif line5.visible=true then
Line5.visible=false
Line6.visible=true
Elseif line6.visible=true then
Line6.visible=false
Line7.visible=true
Elseif line7.visible=true then
Line7.visible=false
Line8.visible=true
Elseif line8.visible=true then
Line8.visible=false
Line9.visible=true
Elseif line9.visible=true then
Line9.visible=false
Line10.visible=true
Elseif line10.visible=true then
Line10.visible=false
Line11.visible=true
Elseif line11.visible=true then
Line11.visible=false
Line12.visible=true
Elseif line12.visible=true then
Line12.visible=false
Line1.visible=true
End if
End sub
9.Simple and compound interest calculation
Dim p as integer
Dim n as
double
Dim r as
variant
Dim si,ci
As variant
Private sub command1_click()
P=val(text1.text)
N=val(text2.text)
R=val(text3.text)
Si=(p*n*r)/100
Msgbox “The
simple interest=”&si
End sub
Private sub command2_click()
P=val(text1.text)
N=val(text2.text)
R=val(text3.text)
Ci=((p*1+r/100)^n-p)
Msgbox”The compound interest=”&ci
End sub
10.Fibonacii serial
Private sub form_click()
A=-1
B=1
V=val(text1+text2)
For i=0 to 10
C=a+b
Print c
A=b
B=c
Next i
End sub
11.Timer
Private sub form_load()
Me.windowstate=2
Shape2.visible=false
Shape4.visible=false
End sub
Private sub timer1()
If shape1.visible=true then
Shape3.visible=true
Shape1.visible=false
Shape3.visible=false
Shape2.visible=true
Shape4.visible=true
Elseif shape2.visible=true then
Shape4.visible=true
Shape2.visible=false
Shape4.visible=false
Shape1.visible=true
Shape3.visible=true
End if
End sub
12.Picture animation
Private sub command1_click()
Picture1.width=picture1.width+100
Picture1.height=picture1.height+100
End sub
Private sub command2_click()
Picture1.width=picture1.width-100
Picture1.height=picture1.height-100
End sub
Private sub command3_click()
Picture1.top=picture1.top-100
End sub
Private sub command4_click()
Picture1.top=picture1.top+100
End sub
Private sub command5_click()
Picture1.left=picture1.left+100
End sub
Private sub command6_click()
Picture1.left=picture1.left-100
End sub
13.DAO Control
ODBC-Open
database connectivity
DAO-Data
Access objects
C1-MOVEFIRST
C2-MOVEPREVIOUS
C3-MOVE
END NEXT
C4-MOVE
LAST
C5-ADD
C6-DELETE
C7-UPDATE
Database
connectivity
Step
1
Menubar
Add
ins
Click-Visual
data manager
New
–microsoft Access->Version 7.0 MDB
File
name CSCDB->Save
Properties
->Right click-> New table
Table
name:CSCTABLE->ADD FIELD
Name : student name type: text
Place : splace type:text
Close
Click->
Build the Table
Table
name->CSCTABLE->Right click->Open
Add->Student
name :XXXX
Splace :YYYY
Update->Add->close
Step-II
Data
contral->Right click->Properties
Database
Name :CSCDB->Record source : CSCTABLE
Step-III
Text1->Data
source : data1->data field : Student name
Text2->Data source : data1->data
field :splace
Coadings
Private sub command5_click()
Data1.Recordset.Addnew
End sub
Private sub command6_click()
Data1.Recordset.delete
Msgbox”Record delete”
Data1.Recordset.movenext
If data1.Recordset.EOF=true then
Data1.Recordset.moveprevious
End If
End sub
Private sub command3_click()
Data1.recordset.movefirst
Msgbox(“This is the first Record”)
End sub
Private sub command4_click()
Data1.Recordset.movelast
Msgbox(“This is the last Record”)
End sub
Private sub command2_click()
On Error Resume next
If(Data1.Recordset.EOF) then
Msgbox(“No more Records”)
Else
Data1.Recordset.movenext
End if
End sub
Private sub command1_click()
On Error Resume next
If(data1.Recordset.BOF) then
Msgbox(“No previous Record”)
Else
Data1.Recordset.moveprevious
End if
End sub
Private sub command7_click()
Data1.UpdateRecord
Msgbox(“Record updated”)
End sub
14.ADO Control
Project->
components->microsoft ADO Data
control 6.0 (OLEDB)
Connectivity
steps
Step
1
Menubar
Add
ins
Click-Visual
data manager
New
–microsoft Access->Version 7.0 MDB
File
name CSCDB->Save
Properties
->Right click-> New table
Table
name:CSCTABLE->ADD FIELD
Name : student name type: text
Place : splace type:text
Close
Click->
Build the Table
Table
name->CSCTABLE->Right click->Open
Add->Student
name :XXXX
Splace :YYYY
Update->Add->close
Step
2
Adodc1->Right
click->ADODC properties
Property
pages->Use connecting string->Build
Data
link properties-> Microsoft jet 4.0 OLEDB provider->next
Test
connection->ok->ok
Proper
pages->Record source->command type : 2-adcmdtable
Table or
stored produre Name:CSCTABLE
Step-III
text 1->Datasource:Adodc1->Data
Filed : name
text2->Datasource:Adodc1->Data
Field:place
Program coadings:-
Private sub command5_click()
Adodc1.Recordset.Addnew
End sub
Private sub command6_click()
Adodc1.Recordset.delete
Msgbox”Record deleted”
Adodc1.Recordset.movenext
If Adodc1.Recordset.EOF= true then
Adodc1.Recordset.moveprevious
End if
End Sub
Private sub command3_click()
Adodc1.Recordset.movefirst
Msgbox”This is the first record”
End sub
Private sub command4_click()
Adodc1.Recordset.movelast
Msgbox”This is last Record”
End sub
Private sub command2_click()
On Error Resume next
If (Adodc1.Recordset.EOF) then
Msgbox(“No more Records”)
Else
Adodc1.Recordset.movenext
End if
End sub
Private sub command1_click()
On error resume next
If(Adodc1.Recordset.BOF) then
Msgbox(“No previous record”)
Else
Adodc1.Recordset.moveprevious
End if
End sub
Private sub command7_click()
Adodc1.recordset.update
Msgbox(“Record updated”)
End sub
15.Sub procedure
Codings
Option
Explicit
Private sub command1_click()
Timer1.Enabled=true
End sub
Private sub
Timer1_timer()
Color
End sub
Private sub color()
If
form1.backcolor=vbred then
Form1.backcolor=vbgreen
Elseif
form1.backcolor=vbgreen then
Form1.backcolor=vbyellow
Elseif
form1.backcolor=vbyellow then
Form1.backcolor=vbred
End if
End sub
16. Number puzzle
Private sub command1_click()
If
command2.caption=” “ then
T=command1.caption
Command1.caption=command2.caption
Command2.caption=t
Elseif
command4.caption=” “ then
T=command1.caption
Command1.caption=command4.caption
Command4.caption=t
End
if
End sub
Private sub command2.click()
If
command1.caption=” “ then
T=command2.caption
Command2.caption=command1.caption
Command1.caption=t
Elseif
command5.caption=” “ then
T=command2.caption
Command2.caption=command5.caption
Command5.caption=t+
Elseif
command3.caption=” “ then
T=command2.caption
Command2.caption=command3.caption
Command3.caption=t
End
if
End sub
Private sub command3_click()
If
command2.caption=” “ then
T=command3.caption
Command3.caption=command2.caption
Command2.caption=t
Elseif
command6.caption=” “ then
T=command3.caption=command6.caption
Command6.caption=t
Elseif
command4.caption=” “ then
T=command3.caption
Command3.caption=command4.caption
Command4.caption=t
End
if
End sub
Private sub command4_click()
If
command1.caption=” “ then
T=command4.caption
Command4.caption=command1.caption
Command1.caption=t
Elseif
command5.caption=” “ then
T=command4.caption
Command4.caption=command5.caption
Command5.caption=t
Elseif
command7.caption= “ “ then
T=command4.caption
Command4.caption=command7.caption
Command7.caption=t
Elseif
command3.caption=”” then
T=command4.caption
Command4.caption=command3.caption
Command3.caption=t
End
if
End sub
Private sub command5_click()
If
command2.caption=” “ then
T=command5.caption
Command5.caption=command2.caption
Command2.caption=t
Elseif
command4.caption=” “ then
T=command5.caption
Command5.caption=command4.caption
Command4.caption=t
Elseif
command6.caption=” “ then
T=command5.caption
Command5.caption=command6.caption
Command6.caption=t
Elseif
command8.caption=” “ then
T=command5.caption
Command5.caption=command8.caption
Command8.caption=t
End
if
End sub
Private sub command6_click()
If
command3.caption=” “ then
T=command6.caption
Command6.caption=command3.caption
Command3.caption=t
Elseif
command5.caption=” “ then
T=command6.caption
Command6.caption=command5.caption
Command5.caption=t
Elseif
command9.caption=” “ then
T=command6.caption
Command6.caption=command9.caption
Command9.caption=t
End
if
End sub
Private sub command7_click()
If
command4.caption=” “ then
T=command7.caption
Command7.caption=command4.caption
Command4.caption=t
Elseif
command8.caption=” “ then
T=command7.caption
Command7.caption=command8.caption
Command8.caption=t
End
if
End sub
Private sub command8_click()
If
command7.caption=” “ then
T=command8.caption
Command8.caption=command7.caption
Command7.caption=t
Elseif
command5.caption=” “ then
T=command8.caption
Command8.caption=command5.caption
Command5.caption=t
Elseif
command9.caption=” “ then
T=command8.caption
Command8.caption=command9.caption
Command9.caption=t
End
if
End sub
Private sub command9_click()
If
command8.caption=” “ then
T=command9.caption
Command9.caption=command8.caption
Command8.caption=t
Elseif
command6.caption=” “ then
T=command9.caption
Command9.caption=command6.caption
Command6.caption=t
End
if
End sub
Private sub command10_click()
T=command4.caption
Command4.caption=command6.caption
Command6.caption=command8.caption
Command8.caption=command3.caption
Command3.caption=command5.caption
Command5.caption=command2.caption
Command2.caption=command1.caption
Command1.caption=command7.caption
Command7.caption=command9.caption
Command9.caption=t
End sub
Private sub form_load()
Me.windowstate=2
End sub
Private sub command11_click()
If
Command1.Caption=”1” And Command2.Caption=”2”
And
Command3.Caption=”3” And
Command4.Caption=”4”
And
Command5.Caption=”5”
And
Command6.Caption=”6”
And
Command7.Caption=”7”
And
Command8.Caption=”8”
And
Command9.Caption=”9
"then
Msgbox”winner”
Else
Msgbox”looser”
End
if
End sub
0 comments:
Post a Comment