Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Visual Basic VB Record

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 44

NEWS DEGREE COLLEGE

(Affiliated to Andhra University)


GAJUWAKA,VISAKHAPATNAM-26
****************************************************************

DEPARTMENT OF COMPUTER SCIENCE

Regd No: ______________________

CERTIFICATE

This is to certify that the bonafied record of Practical work


done in GUI Programming by Mr/Miss ________________________________
a student of III YEAR B.Sc., Computer Science of this college during the
year 2016– 2017.

Total No.of Programs: ___________

No.of Programs done : ___________

Lecturer in charge Head of the Department

Examiners:

1)

2)
INDEX

SL.NO DATE NAME OF THE EXPERIMENT PAGE


NO

1 CHECK PROFILE

2 BINARY SEARCH

3 STACK OPERATIONS

4 LIST OPERATIONS

5 SURVEY ON DIFFERENT AGE GROUPS

6 CALCULATOR

7 SORTING SYSTEM USING BUBBLE SORT

8 READ AND PRINT ADDRESS OF A PERSON

9 USER PROFILE CONNECTING WITH DATABASE

10 ELECTRICITY BILL

11 STUDENT MARK LIST

12 TRAFFIC SIGNALS

13 CREATING MENUS

14 DEMONSTRATING MDI FORMS

15 DATABASE OPERATIONS USING EMPLOYEE DB


1. VB application to display the profile of a valid user.
Conditions:
i. Cache the User with Password.
ii. Display his Profile.

1. Start VB and create a new StandardEXE project.


2. Add a loginform form addform option in project menu
project→Addform→loginform
3. Go to the code editor of the login and write the code as shown below
Option Explicit

Public LoginSucceeded As Boolean


Private Sub cmdCancel_Click()
LoginSucceeded = False
Me.Hide
End Sub

Private Sub cmdOK_Click()


If txtUserName = "admin" And txtPassword = "password" Then
LoginSucceeded = True
Me.Hide
Form1.Show
Else
MsgBox "Invalid Password, try again!", , "Login"
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
4. Now design the form as shown below and write the code in the code editor
as shown below

Private Subadd_Click()
If List1.ListCount <> 3 Then
List1.AddItem Combo3.Text
Else
MsgBox "maximum three skills to be choosed"

End If
End Sub
Private Subclear_Click()
Text1.Text = " "
Option1.Value = False
Option2.Value = False
Combo1.Text = " "
Combo2.Text = " "
Combo3.Text = " "
Combo4.Text = " "
Check1.Value = False
Check2.Value = False
Check3.Value = False
Check4.Value = False
List1.CLEAR
End Sub

Private Subclose_Click()
Unload Me
End Sub
Private Subsubmit_Click()
MsgBox (Text1.Text & " " & "your data has been submitted")
End Sub
5. Now the save the project and run the form by pressing F5 key
OUTPUT :
2. VB program to find an element in a list using binary search.
1.start VB and create anew standardEXE project.
2.place the required controls on the form and set the
properties as required.
3. Design the form as shown.
Option Explicit
Dim x(1 To 10) As Integer, n As Integer, I As Integer, j
As Integer, k As Integer, m As Integer, h As Integer, l As
Integer

Private Sub Cmdclear_Click()


List1.Clear
Text1.Text = " "
End Sub

Private Sub Cmdquit_Click( )


End
End Sub

Private Sub Cmdsearch_Click( )


n = Val(Text1.Text)
For i = 1 To n
x(i) = InputBox("enter the elements")
List1.AddItem (Str(x(i)))
Next i
List1.Visible = True
k = InputBox("enter the search element")
l=1
h=n
m = (l + h) / 2
While (l < h) And (x(m) <> k)
If k < x(m) Then
h=m-1
ElseIf k > x(m) Then
l=m+1
End If
m = (l + h) / 2
Wend
If k = x(m) Then
MsgBox "search succesfully"
Print "element found at", m
Else
MsgBox "search unsuccessfull"
End If
End Sub

Private Sub Form_Load()


List1.Visible = False
End Sub
4.Save the form and project
5.Run the form by pressing F5 key.
OUTPUT:
3. Visual Basic Application for stack operations.

1. Start VB and create a new standardEXE project.


2. Place the controls on the form and design the form as required.
3. Click on code view and write the following code.
Dim x(0 To 10) As Integer, n As Integer, i As Integer

Private Sub Cmdclear_Click()


Text1.Text = " "
List1.Clear
End Sub

Private Sub Cmddisplay_Click()


List1.Visible = True
End Sub

Private Sub cmdexit_Click()


End
End Sub

Private Sub cmdpop_Click()


If List1.ListCount = Empty Then
MsgBox "stack is underflow"
Else
List1.RemoveItem List1.ListCount - 1
End If
List1.Visible = False
End Sub
Private Sub Cmdpush_Click()
List1.Visible = False
n = Val(Text1.Text)
For i = 0 To n - 1
x(i) = InputBox("enter elements into stack")
List1.AddItem (Str(x(i)))
If i = n - 1 Then
MsgBox "stack is over flow"
End If
Next i
End Sub

Private Sub Form_Load()


Me.WindowState = 2
End Sub
4. Save the project and rin the form by pressing F5 key.

OUTPUT:
4. VB application for coping the elements from one list to other list
and vice-versa.
1. start VB and create a new standardEXE project.
2. create the command buttons and set the properties as required.
3. click on codeview and write the following code.
Private Sub Command1_Click()
List2.AddItem List1.Text
List1.RemoveItem List1.ListIndex
List1.Text = Clear
End Sub

Private Sub Command2_Click()


List1.AddItem List2.Text
List2.RemoveItem List2.ListIndex
List2.Text = Clear
End Sub

Private Sub Command3_Click()


End
End Sub

Private Sub Form_Load()


List2.Clear
List1.AddItem "java"
List1.AddItem "c"
List1.AddItem "oracle"
List1.AddItem "c++"
List1.AddItem "VB"
End Sub
4. save the form and run the form by pressing F5 key.
OUTPUT:
5. VB programe to make a survey on different agegroups for
example age groups may be 25 -34 or 35-44 or 45-54 and
greater than or equal 55.Display the number of people on a
particular age group.
1.start VB and create a new standardEXE project.
2.Design the form as shown below.

3.Add a module to the project by


Projectmenuadd module
4.write the following code in the module.

Public n As Integer
Public age As Integer
Public a As Integer, b As Integer, c As Integer, m As Integer
Public Sub calculate(age As Integer)
If age >= 25 And age <= 34 Then
a=a+1
ElseIf age >= 35 And age <= 44 Then
b=b+1
ElseIf age >= 45 And age <= 54 Then
c=c+1
ElseIf age >= 55 Then
m=m+1
End If
End Sub
5.Click on code view of the form and then write the following code.

Private Sub Compute_Click()


Label4.Caption = "number of persons whose age is between 25-
34:" & a & vbCrLf & "number of persons whose age is between 35-44:" &
b & vbCrLf & "number of persons whose age is between 45-54:" & c &
vbCrLf & " number of persons whose age is above 55:" & m
End Sub

Private Sub submit_Click()


n = Text2.Text
calculate (n)
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text1.SetFocus
End Sub
6.save the form and project.
7.run the form by pressing F5 key.

OUTPUT:
6 . VB application to illustrate the working of a calculator by
using a control array of command buttons.

1. start VB and create a new standardEXE project.


2. design the form as shown.
3. create a control array(11 controls) called command 1 by placing command
button and then copying and pasting it on the form.
4. create a control array(4 controls) called command 2 by placing command
button on the form and then copying it and pasting it on the form.
5. set the properties as required.
6. Go to code view and write the following code.
Dim v1 As Double, v2 As Double, opcode As String

Private Sub Command1_Click(Index As Integer)


Text1.Text = Text1.Text + Command1(Index).Caption
End Sub

Private Sub Command2_Click(Index As Integer)


v1 = Val(Text1.Text)
opcode = Command2(Index).Caption
Text1.Text = " "
End Sub

Private Sub Command3_Click()


v2 = Val(Text1.Text)
Select Case opcode
Case "+"
Text1.Text = v1 + v2
Case "-"
Text1.Text = v1 - v2
Case "*"
Text1.Text = v1 * v2
Case "/"
Text1.Text = v1 / v2

End Select
opcode = " "
End Sub

Private Sub Command4_Click()


Text1.Text = " "
End Sub

Private Sub Form_Load()


Me.WindowState = 2
End Sub
7. save the form and project.
8. run the project by pressing F5 key.

OUTPUT:
7. VB application to sort the elements in the given list using Bubble sort.

1.Start VB and create a new standardEXE project.


2.Place the required controls on the form and set the properties as
Required.
3.Design the form as shown
4.Open code view and write the following code.

Option Explicit
Dim x(10) As Integer, n As Integer, i As Integer, j As
Integer, t As Integer

Private Sub Cmdclear_Click()


List1.Clear
list2.Clear
Text1.Text = " "
End Sub

Private Sub Cmdgo_Click()


n = Val(Text1.Text)
For i = 1 To n
x(i) = InputBox("enter elements into array")
List1.AddItem (Str(x(i)))
Next i
Call sort(x(), n)
For i = 1 To n
list2.AddItem (Str(x(i)))
Next i
List1.Visible = True
list2.Visible = True
original.Visible = True
sorted.Visible = True
End Sub

Private Sub Cmdquit_Click()


End
End Sub
Private Sub Form_Load()
List1.Visible = False
list2.Visible = False
original.Visible = False
sorted.Visible = False
End Sub

Private Sub sort(x() As Integer, n As Integer)


For i = 1 To n
For j = 1 To n - i
If x(j) > x(j + 1) Then
t = x(j)
x(j) = x(j + 1)
x(j + 1) = t
End If
Next j
Next i
End Sub
5.Save the form and project.
6.Run the form by pressing F5 key.
OUTPUT:
8. VB application to read the address and print the address of a person.

1. start VB and create a new standardEXE project.


2. design the form as shown below.

3. click on code view and write the code.


Dim x, y, z, w As String

Private Sub Command1_Click()


x = InputBox("enter name of person")
y = InputBox("enter addressline1 ")
z = InputBox("enter addressline2 ")
w = InputBox("enter addressline3 ")
End Sub

Private Sub Command2_Click()


Label2.Caption = x & vbCrLf & y & vbCrLf & z & vbCrLf & w
End Sub
4. save the form and project.
5. run the form by pressing F5 key.
OUTPUT:
9. Procedure to Develop an application form which abstracts the user profile
consisting of skills regarding OS, databases, web technologies,
programming languages and experience details.

1. Start VB and create a new standardEXE project.


2. Place the controls on the form and design the form as required.
3. Click on code view and write the following code.
Private Sub add_Click()
If List1.ListCount <> 3 Then
List1.AddItem Combo3.Text
Else
MsgBox "maximum three skills to be choosed"
End If
End Sub

Private Sub CLEAR_Click()


Text1.Text = " "
Option1.Value = False
Option2.Value = False
Combo1.Text = " "
Combo2.Text = " "
Combo3.Text = " "
Combo4.Text = " "
Check1.Value = False
Check2.Value = False
Check3.Value = False
Check4.Value = False
List1.CLEAR
End Sub
Private Sub CLOSE_Click()
Unload Me
End Sub
Private Sub SUBMIT_Click()
MsgBox (Text1.Text & " " & "your data has been submitted")
End Sub
4.Save the form and run the form by pressing F5 key

OUTPUT:
10. Visual Basic Application to generate Electricity Bill.

1.Start VB and create a new standardEXE project.


2. Place the controls as required.
3.Click on code view and write the following code.
Dim prev As Double, curr As Double
Dim netamt, units As Double
Dim price_unit As Double, servicetax As Integer
Private Sub CMDCAL_Click()
mno = Val(Text1.Text)
cname = Val(Text2.Text)
curr = Val(Text3.Text)
prev = Val(Text4.Text)
units = curr - prev
If units > 0 And units < 50 Then
price_unit = 1.45
servicetax = 15
netamt = units * price_unit + servicetax
ElseIf units > 51 And units < 100 Then
price_unit = 2.8
servicetax = 20
netamt = units * price_unit + servicetax
ElseIf units > 101 And units < 200 Then
price_unit = 3.05
servicetax = 20
netamt = units * price_unit + servicetax
ElseIf units > 201 And units < 300 Then
price_unit = 4.75
servicetax = 20
netamt = units * price_unit + servicetax
ElseIf units > 300 Then
price_unit = 5.5
servicetax = 20
netamt = units * price_unit + servicetax
End If
Label6.Visible = True
Label6.Caption = "no.of units is:" & units & vbCrLf & " price per unit
is:" & price_unit & vbCrLf & "servicetax is : " & servicetax & vbCrLf
& "total charge is:" & netamt
End Sub

Private Sub CMDEXIT_Click()


End
End Sub

Private Sub Form_Load()


Label6.Visible = False
End Sub
4.save the form and run the form by pressing F5 key.

OUTPUT:
11. Visual Basic application, which develops a student mark list.
Conditions:
i.read any 5 subject marks.
ii.for qualifying minimum marks are 40%.
iii .for pass average is 50%
iv .for first class percentage is>=60
v .for second class percentage is between 40 and 59.
Vi .for third class percentage is 40
Vii .minimum percentage is<50 then result is fail.
1. Start VB and create a new standardEXE project.
2. Place the controls as shown below.
3. Click on codeeditor of the form and write the code.
Dim total As Integer, avg As Double
Dim s1, s2, s3, s4, s5 As Integer
Private Sub Command1_Click()
s1 = Val(Text1.Text)
s2 = Val(Text2.Text)
s3 = Val(Text3.Text)
s4 = Val(Text4.Text)
s5 = Val(Text5.Text)
If s1 >= 40 And s2 >= 40 And s3 >= 40 And s4 >= 40 And s5 >= 40
Then
total = s1 + s2 + s3 + s4 + s5
avg = total / 5
If avg = 50 Then
Text6.Text = "pass"
ElseIf avg >= 60 Then
Text6.Text = "first class"
ElseIf avg > 40 And avg < 50 Then
Text6.Text = "second class AND FAIL"
ElseIf avg >= 50 And avg <= 59 Then
Text6.Text = "secondclass and pass"
ElseIf avg = 40 Then
Text6.Text = " qualified ,third class AND FAIL"
End If

Else
Text6.Text = "fail"
End If
End Sub

Private Sub Command2_Click()


Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub

Private Sub Command3_Click()


End
End Sub
4. Save the project and run the form by pressing F5 key.

OUTPUT:
12. VB program to generate the traffic signal.

1.start VB and create a new standardEXE project.


2.Change the caption of the form as traffic lines.
3. now, create the required controls and place them on the
form as shown below.
4. now set the properties as required.
5. design the form as shown.
6. click on codeview and write the following code.
Option Explicit
Dim s As Integer
Private Sub Cmdchange_Click()
s=1
Shpred.BackColor = vbRed
Shpyellow.BackColor = vbWhite
Shpgreen.BackColor = vbWhite
Lblmessage.Caption = "stop"
End Sub

Private Sub Cmdstop_Click()


End
End Sub

Private Sub Tmrlights_Timer()


If s = 3 Then
s=1
Else
s=s+1
End If
Select Case s
Case 1

Shpred.BackColor = vbRed
Shpyellow.BackColor = vbWhite
Shpgreen.BackColor = vbWhite
Lblmessage.Caption = "stop"
Tmrlights.Interval = 18000
Case 2
Shpred.BackColor = vbWhite
Shpyellow.BackColor = vbWhite
Shpgreen.BackColor = vbGreen
Lblmessage.Caption = "go"
Tmrlights.Interval = 12000
Case 3
Shpred.BackColor = vbWhite
Shpyellow.BackColor = vbYellow
Shpgreen.BackColor = vbWhite
Lblmessage.Caption = "wait"
Tmrlights.Interval = 6000
End Select
End Sub
7. Save the form and project.
8. run the form by pressing F5 key.

OUTPUT:
13. VB program to create menus.

1. Start VB and create a new standard EXE project.


2. Add a textbox to the form and set the height and width of the textbox
Similar to the scale height and scale width of the form.
3. Click on tools menu and then on menu editor option.
4. Add two menus file and edit.
5. Add menu items new and open to file menu and add
Copy and paste menu items to edit menu.
6. Add common dialog control to the toolbox by
Project menu → components → Microsoft common dialog
control6.0
7. Add the control to the form.
8. Click on code view and write the following code

Private sub mnunew_click ( )


Dim newform as new form1
form = form+1
newform.caption=”form”+str (form)
newform.show
end sub

private sub mnuopen_click( )


dim s as string
on error go to errortrap
commondialog1.showopen
msgbox ” selected file is “ +commondialog1.filename
exit sub
errortrap:
msgbox”dialog box is cancelled”
exit sub
end sub

private sub mnucopy_click( )


clipboard.clear
clipboard . settext text1.seltext
end sub
private sub mnupaste_click( )
text1.seltext = clipboard.Gettext( )
end sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As


Single, Y As Single)
If Button = 2 Then
popup mnufile
End If
End Sub

Private Sub Form_Resize()


Me.Text1.Height = Me.ScaleHeight
Me.Text1.Width = Me.ScaleWidth
End Sub

9.Now save the form and project.


10. Run the application by pressing F5 key.
OUTPUT:
14. VB program to demonstrate MDI forms.

1. start VB and create a new standardEXE project.


2. add a textbox to the form.
3. add an MDI form to the project by
projectmenuadd MDI form
4. specify the MDI child property of standard form (form 1) to true.
5. add a menu bar to the MDI form by clicking on
toolsmenueditor
6. add two menus file and window. add two menu items new and
exit to file menu and add two menu items tile and cascade to window
menu.

Adding a toolbar to the MDI form


1. Add a toolbar to the MDI form.
Projectmenu componentsMicrosoft windows common control
5.0(Sp2)
2 .Add the toolbar from the toolbox to on the form
3.Right click on the tool bar and select the properties
propertiespropertypages buttons tabinsert button
and specify the caption of the buttons
4. Add an image list to the MDI form. Now right click on imagelist
and select properties.
Propertiesimagesinsert picturebrowse
Select an icon and place it into the imagelist and click on OK.
5. right click on the tool bar and select
propertiesgeneraltabimagelistimagelist1
and specify the number in image property.

Adding a statusbar to the MDI form


1,.add a status bar to the MDI form from the toolbox
2.right click on the
statusbarpropertiespropertypagespanelinsertpanel
3.click twice on the insert panel.

4.In the general tab specify the text and tooltip text for date and time
5.place the timer on the MDI form and set interval property of timer
to 100
6.click on codeview of the MDI form and write the following code.
Private Sub mnunew_Click()
Dim newform As New Form1
Form = Form + 1
newform.Caption = "childform" + Str(Forms)
newform.Show
End Sub

Private Sub mnuexit_Click()


End
End Sub

Private Sub mnutile_Click()


MDIForm1.Arrange vbTileHorizontal
End Sub

Private Sub mnucascade_Click()


MDIForm1.Arrange vbCascade
End Sub

Private Sub Timer1_Timer()


StatusBar1.Panels(1) = Format(Date, "dd:mm:yyyy")
StatusBar1.Panels(2) = Format(Time, "hh:mm:SS")
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As


ComctlLib.Button)
MsgBox "you have clicked on" & Button.Caption
End Sub
7.Save the MDI form and project
8.Run the MDI form by pressing F5 key.
OUTPUT:
15. VB Application to make following Database operations by using
Employee Database
i. Inserting the Employee Details
ii. Deleting the Employee Details
iii.Modifying the Employee Details
iv. Finding an Employee

1.Start VB and create a new StandardEXE project.


2.Place the controls as shown below
3.open oracle and create a table named as emp10 with fields
empno,ename,job,sal
4.now open code editor of the form and write the following code
Dim env As rdoEnvironment
Dim con As rdoConnection
Dim rs As rdoResultset
Private Sub cmdadd_Click()
Call clearrec
rs.AddNew
End Sub
Private Sub cmddelete_Click()
rs.Delete
rs.MoveNext
If rs.EOF Then
rs.MoveLast
End If
Call disp
MsgBox "record deleted successfully"
End Sub
Private Sub clearrec()
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
End Sub
Private Sub cmdlast_Click()
rs.MoveLast
Call disp
End Sub
Private Sub cmdmodify_Click()
rs.Edit
rs("empno") = Text1.Text
rs("ename") = Text2.Text
rs("job") = Text3.Text
rs("sal") = Text4.Text
rs.Update
Call disp
MsgBox "record updated successfully"
End Sub
Private Sub cmdprev_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
End If
Call disp
End Sub
Private Sub cmdnext_Click()
rs.MoveNext
If rs.EOF Then
rs.MoveLast
End If
Call disp
End Sub
Private Sub cmdsave_Click()
If rs.EditMode = dbEditAdd Then
rs("empno") = Text1.Text
rs("ename") = Text2.Text
rs("job") = Text3.Text
rs("sal") = Text4.Text
End If
rs.Update
Call disp
MsgBox "record updated successfully"
End Sub
Private Sub findfirst_Click()
Dim a As String
a = Text5.Text
rs.find "(empno)=" & CInt(Text5.Text)
If rs.NoMatch Then
MsgBox "record not found"
Else
rs.Edit
Text1.Text = rs(0)
Text2.Text = rs(1)
Text3.Text = rs(2)
Text4.Text = rs(3)
End If
End Sub

Private Sub find_Click()


filfile.Pattern = Text5.Text
End Sub

Private Sub Form_Load()


Set env = rdoEnvironments(0)
env.CursorDriver = rdUseOdbc
Set con = env.OpenConnection(dsname:=" ", Prompt:=rdDriverPrompt,
ReadOnly:=False, Connect:=" ")
Call loademp10
End Sub
Public Sub loademp10()
Dim s As String
s = "select * from emp10"
Set rs = con.OpenResultset(Name:=s, Type:=rdOpenDynamic,
LockType:=rdConcurRowVer)
If rs.EOF Then
MsgBox "no records found"
Else
Call disp
End If
End Sub
Public Sub disp()
Text1.Text = rs("empno")
Text2.Text = rs("ename")
Text3.Text = rs("job")
Text4.Text = rs("sal")
End Sub
Private Sub cmdfirst_click()
rs.MoveFirst
Call disp
End Sub

5.Now goto control panel and open administrative tools


In that select DataSources(ODBC)
6.now the following dialog box will be displayed

7.In that select ADD button then Create New DataSource dialog box
Appears
8.Now select Microsoft ODBC for Oracle and then select finish
9. Now Microsoft ODBC for Oracle Setup dialog box appears in that
select datasurce name as emp10,Description as project and
Username as scott and press ok

10.Now goto vb project and add a control called Microsoft


Remote Data
Control2.0
Project→References→ Microsoft Remote Data control2.0

11.Now save the project and run the form by pressing F5 key

12.select username as “scott” and password as “tiger” and select OK


OUTPUT:

You might also like