VB Lab Programs
VB Lab Programs
PROGRAMMING IN VB
1. CONSTRUCTION OF AN ARITHMETIC CALCULATOR (SIMPLE)
AIM:
PROCEDURE
1.Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2.Create textbox to get integer number in VB form.
3.Create command button, copy the button and paste the button for input (0
to 9).
4.Create command buttons for arithmetic operations.
5.Double click on each button and write code for arithmetic operation.
6.Display the output in the text box.
7.Save and Press F5 to execute the application.
CODING
Option Explicit
Dim ch
Dim value
End Sub
Text1.Text = ""
End Sub
1|P ag e
value = Text1.Text
Text1.Text = ""
ch = "+"
End Sub
value = Text1.Text
Text1.Text = ""
ch = "-"
End Sub
value = Text1.Text
Text1.Text = ""
ch = "*"
End Sub
value = Text1.Text
Text1.Text = ""
ch = "/"
End Sub
Case "+"
2|P ag e
Case "-"
Case "*"
Case "/"
End Select
End Sub
INPUT DESIGN
3|P ag e
OUTPUT DESIGN
RESULT:
4|P ag e
2(A) FIBONACCI SERIES
AIM:
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Create textboxes to get the Fibonacci series.
3. Create command button Fibonacci series.
4. Double click on the buttons and write code to print the Fibonacci series
5. Display the output in the form.
6. Save and Press F5 to execute the application.
CODING:
5|P ag e
OUT PUT DESIGN
RESULT:
AIM:
PROCEDURE:
1.Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Create textboxes to get the sum of N numbers
3. Create command button sum of N numbers
4. Double click on the buttons and write code to print the sum of N numbers
5. Display the output in the form.
6. Save and Press F5 to execute the application.
6|P ag e
CODING:
Dim n, i, s As Integer
Cls
n = Val(Text1.Text)
For i = 1 To n
s=s+i
Next i
End Sub
RESULT:
7|P ag e
2 (C) TRIANGLE FORMAT
AIM:
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Create display the numbers/symbols in triangle format
3. Create command button display the numbers/symbols in triangle format
4. Double click on the buttons and write code to print the display the
numbers/symbols in triangle format
5. Display the output in the form.
6. Save and Press F5 to execute the application
CODING:
Dim i, n As Integer
For i = 1 To n
Next i
End Sub
8|P ag e
OUTPUT DESIGN
RESULT:
9|P ag e
3 Write a program to create a menu and MDI Forms
AIM:
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Right click the project explorer click add and choose MDI form
3. Right click form and click menu editor
4. Give the names for menus and write the code
5. Display the output in the form.
6. Save and Press F5 to execute the application
End
End Sub
End Sub
FORM CODING
MDIForm1.Show
End Sub
OUTPUT DESIGN
RESULT
11 | P a g e
4. Write a program to create a simple input screen with four basic controls
to read input and write it to a file.
AIM:
To create a simple input screen with four basic controls to read input and
write it to a file.
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
CODING:
MsgBox"MR."& Text1.Text
Else
MsgBox"MRS."& Text1.Text
End If
12 | P a g e
OUTPUT
RESULT
13 | P a g e
5. Write a program to display files in a directory using DriveListBox,
DirListBox and FileListBox control
AIM:
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project Dialog
Box and click open.
2. Create and write code to Dir, drive,file list boxes to display the file and
rich text box
3. Create command button to save the file
4. Double click on the buttons and write code to print the saved file
5. Display the output in the form.
6. Save and Press F5 to execute the application
CODING:
End Sub
RichTextBox1.Text = ""
End Sub
File1.Path = Dir1.Path
14 | P a g e
End Sub
Dir1.Path = Drive1.Drive
End Sub
OUTPUT
RESULT
15 | P a g e
6. Write a program to illustrate Common Dialog Control and to open, edit
and save text file
AIM:
To illustrate Common Dialog Control and to open, edit and save text file
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
nf = FreeFile
cd1.ShowSave
MsgBox"EDIT"
End Sub
On Error GoTo A
Form1.cd1.ShowOpen
Do Until EOF(1)
16 | P a g e
Input #1, contentfile
Loop
Close #1
A:
End Sub
nf = FreeFile
cd1.ShowSave
MsgBox"saved"
Close
End Sub
OUTPUT:
RESULT:
17 | P a g e
7. Write a program to develop windows based installation file with Student
Registration form and Login form using database access.
AIM:
To develop windows based installation file with Student Registration form and
Login form using database access.
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Open 2 forms and create form design for login and registration
3. Create command buttons for both forms and place the data control
4. Create the database for registration form
4. Double click on the buttons and write code to print the saved file and
change data properties on property form
5. Display the output in the form.
6. Save and Press F5 to execute the application
LOGIN FORM
username = "admin"
password = "admin"
MsgBox"login successfull.."
Form2.Show
Else
End Sub
Text1.Text = ""
Text2.Text = ""
End Sub
REGISTRATION FORM
Data1.Recordset.Update
MsgBox"register"
End Sub
Data1.Recordset.ADDNEW
End Sub
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
OUTPUT
19 | P a g e
RESULT
20 | P a g e
8. Develop a program to Insert, update, delete a Record in database using
ADO
AIM
PROCEDURE
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Open forms and create form design for Student details
3. Create command buttons for forms and place the ADO data control
4. Create the database for registration form
4. Double click on the buttons and write code to Insert, Update, Delete file
and change data properties on property form
5. Display the output in the form.
6. Save and Press F5 to execute the application
CODINGS:-
Private Sub ADDNEW_Click()
Text1.SetFocus
Adodc1.Recordset.ADDNEW
MsgBox"RECORD HAS BEEN ADDED"
End Sub
Private Sub AVG_GotFocus()
AVG = Val(TOTAL) / 6
End Sub
Private Sub DELETE_Click()
Confirm = MsgBox("Are you sure you want to delete this record?", vbYesNo,
"Deletion Confirmation")
If Confirm = vbYes Then
Adodc1.Recordset.DELETE
MsgBox"Record Deleted!", ,"Message"
Else
MsgBox"Record Not Deleted!", ,"Message"
End If
21 | P a g e
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub GRADE_GotFocus()
If AVG > 90 And RESULT.Text = "pass" Then
GRADE.Text = "o grade'"
Else
If AVG > 75 And RESULT.Text = "pass" Then
GRADE.Text = "a grade'"
Else
If AVG > 60 And RESULT.Text = "pass" Then
GRADE.Text = "b grade'"
Else
If AVG > 40 And RESULT.Text = "pass" Then
GRADE.Text = "c grade'"
Else
GRADE.Text = "d grade'"
End If
End If
End If
End If
End Sub
Private Sub RESULT_GotFocus()
If Val(Text6.Text) >= 40 And Val(Text7.Text) >= 40 And Val(Text8.Text) >=
40 And Val(Text9.Text) >= 40 And Val(Text10.Text) >= 40 And
Val(Text11.Text) >= 40 Then
RESULT = "pass"
Else
RESULT = "fail"
End If
End Sub
22 | P a g e
Adodc1.Recordset.Fields("BATCH") = Text5.Text
Adodc1.Recordset.Fields("DOB") = Text4.Text
Adodc1.Recordset.Fields("VB") = Text6Text
Adodc1.Recordset.Fields("OS") = Text7.Text
Adodc1.Recordset.Fields("SE") = Text8.Text
Adodc1.Recordset.Fields("CN") = Text9.Text
Adodc1.Recordset.Fields("MSA") = Text10.Text
Adodc1.Recordset.Fields("SS") = Text11.Text
Adodc1.Recordset.Update
MsgBox"RECORD IS UPDTAED SUCCESSFULLY"
End Sub
OUTPUT:-
RESULT
23 | P a g e
9. Write a program to implement Personal Information System using MDI
and Standard ADODC controls and reports.
AIM
PROCEDURE
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Open form and create form design for Personal Information Systems
details.
3. Create command buttons for forms and place the ADODC data control
and MDI form.
4. Create the database for Personal Information System.
5. Create a new MS access database.
24 | P a g e
CODING:
Form1.Show
Me. Hide
End Sub
25 | P a g e
RESULT
26 | P a g e
10 . Write a program to implement animation using timers
AIM
PROCEDURE:
1. Open Visual Basic 6.0 IDE, Select Standard Exe from the New Project
Dialog Box and click open.
2. Place the timer and give the intrevel 1
3. Create command button to move the image and stop the image
4. Double click on the buttons and write code to print the saved file
5. Display the output in the form.
6. Save and Press F5 to execute the application
CODING:
Timer1.Enabled = True
End Sub
Timer1.Enabled = False
End Sub
Timer1.Enabled = False
End Sub
27 | P a g e
Private Sub Timer1_Timer()
Image1.Left = Image1.Left + 10
Image1.Top = Image1.Top - 10
Image1.Left = Image1.Left + 10
End If
End Sub
OUTPUT
RESULT
28 | P a g e