SEMESTER – VI
PROGRAMMING IN VB
1. CONSTRUCTION OF AN ARITHMETIC CALCULATOR (SIMPLE)
AIM:
To construct a simple arithmetic calculator using visual basic
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
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text + Command1(Index).Caption
End Sub
Private Sub CLEAR_Click()
Text1.Text = ""
End Sub
Private Sub ADD_Click()
1|P ag e
value = Text1.Text
Text1.Text = ""
ch = "+"
End Sub
Private Sub SUB_Click()
value = Text1.Text
Text1.Text = ""
ch = "-"
End Sub
Private Sub MUL_Click()
value = Text1.Text
Text1.Text = ""
ch = "*"
End Sub
Private Sub DIV_Click()
value = Text1.Text
Text1.Text = ""
ch = "/"
End Sub
Private Sub EQL_Click()
Select Case (ch)
Case "+"
Text1.Text = Val(value) + Val(Text1.Text)
2|P ag e
Case "-"
Text1.Text = Val(value) - Val(Text1.Text)
Case "*"
Text1.Text = Val(value) * Val(Text1.Text)
Case "/"
Text1.Text = Val(value) / Val(Text1.Text)
End Select
End Sub
INPUT DESIGN
3|P ag e
OUTPUT DESIGN
RESULT:
Thus the above program has been executed successfully.
4|P ag e
2(A) FIBONACCI SERIES
AIM:
To Generate Fibonacci series using for loop.
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:
Private Sub Command1_Click ( )
Dim x, g, n, i, sum As Integer
n = Val(Text1.Text)
x=0
y=1
Print x
Print y
For i = 3 To n
sum = x + y
Print sum
x=y
y = sum
y = sum
Next i
End Sub
5|P ag e
OUT PUT DESIGN
RESULT:
Thus the above program has been executed successfully
2(B) SUM OF N NUMBERS
AIM:
To find the sum of N numbers Using loop.
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:
Private Sub Command1_Click()
Dim n, i, s As Integer
Cls
n = Val(Text1.Text)
For i = 1 To n
s=s+i
Next i
Print "Sum of N Number = "; s
End Sub
OUT PUT DESIGN
RESULT:
Thus the above program has been executed successfully
7|P ag e
2 (C) TRIANGLE FORMAT
AIM:
To display the numbers/symbols in triangle format
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:
Private Sub Command1_Click()
Dim i, n As Integer
n = Val(InputBox("Enter Number of rows"))
For i = 1 To n
Print Space(n - i) + String(i, ("*"))
Next i
End Sub
8|P ag e
OUTPUT DESIGN
RESULT:
Thus the above program has been executed successfully
9|P ag e
3 Write a program to create a menu and MDI Forms
AIM:
To create a menu and MDI Forms.
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
MDI FORM CODING
Private Sub EXIT_Click()
End
End Sub
Private Sub OPEN_Click()
10 | P a g e
Form1.Show
End Sub
FORM CODING
Private Sub C_Click()
MDIForm1.Show
End Sub
OUTPUT DESIGN
RESULT
Thus the above program has been executed successfully
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.
2. Create Option boxes to display the gender
3. Create command button display the gender in textbox
4. Double click on the buttons and write code to print the display the gender
5. Display the output in the form.
6. Save and Press F5 to execute the application
CODING:
Private Sub DISPLAY_Click()
If Option1.Value = True Then
MsgBox"MR."& Text1.Text
Else
MsgBox"MRS."& Text1.Text
End If
12 | P a g e
OUTPUT
RESULT
Thus the above program has been executed succesfully
13 | P a g e
5. Write a program to display files in a directory using DriveListBox,
DirListBox and FileListBox control
AIM:
To display files in a directory using DriveListBox, DirListBox and FileListBox
control
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:
DirListBox, DriveListBox, FileListBox, RichtextBOx
Private Sub Command1_Click()
RichTextBox1.LoadFile (File1.Path + File1.FileName)
End Sub
Private Sub Command2_Click()
RichTextBox1.SaveFile File1.Path + File1.FileName, rtfRTF
MsgBox ("File Saved !!!")
RichTextBox1.Text = ""
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
14 | P a g e
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
OUTPUT
RESULT
Thus the above program executed success fully
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.
2. Create and TEXT box
3. Create command button to save, open,edit 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
Private Sub Command1_Click()
nf = FreeFile
cd1.ShowSave
Open cd1.FileName For Output As #nf
Write #nf, Text1.Text
MsgBox"EDIT"
End Sub
Private Sub open_Click()
Dim contentfile As String
On Error GoTo A
Form1.cd1.ShowOpen
Open Form1.cd1.FileName For Input As #1
Do Until EOF(1)
16 | P a g e
Input #1, contentfile
Form1.Text1 = Form1.Text1 + contentfile + vbCrLf
Loop
Close #1
A:
End Sub
Private Sub save_Click()
nf = FreeFile
cd1.ShowSave
Open cd1.FileName For Output As #nf
Write #nf, Text1.Text
MsgBox"saved"
Close
End Sub
OUTPUT:
RESULT:
Thus the above program has been executed successfully
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
Private Sub LOGIN_Click()
Dim username As String
Dim password As String
username = "admin"
password = "admin"
If (username = Text1.Text And password = Text2.Text) Then
MsgBox"login successfull.."
Form2.Show
Else
MsgBox"sorry login failed try again...."
18 | P a g e
End If
End Sub
Private Sub reset_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
REGISTRATION FORM
private Sub register_Click()
Data1.Recordset.Update
MsgBox"register"
End Sub
Private Sub addnew_Click()
Data1.Recordset.ADDNEW
End Sub
Private Sub reset_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
OUTPUT
19 | P a g e
RESULT
Thus the above program has been executed successfully
20 | P a g e
8. Develop a program to Insert, update, delete a Record in database using
ADO
AIM
To develop a program to insert, update, delete a Record in database using ADO
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
Private Sub SAVE_Click()
Adodc1.Recordset.Fields("NAME") = Text1.Text
Adodc1.Recordset.Fields("REGNO") = Text2.Text
Adodc1.Recordset.Fields("DEPT") = Text3.Text
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
Private Sub TOTAL_GotFocus()
TOTAL = Val(Text6) + Val(Text7) + Val(Text8) + Val(Text9) + Val(Text10) +
Val(Text11)
End Sub
OUTPUT:-
RESULT
Thus the above program has been executed successfully
23 | P a g e
9. Write a program to implement Personal Information System using MDI
and Standard ADODC controls and reports.
AIM
To develop write a program to implement Personal Information System using
MDI and Standard ADODC controls and reports.
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.
6.Click Add button in wizard, Select Microsoft Ms Access driver, Click
finish.
7. Give Data Source Name and select the database which is already saved
and click ok.
8. Double click on the buttons and write the cod change data properties on
property form.
9.. Display the output in the form.
10. Save and Press F5 to execute the application.
24 | P a g e
CODING:
Private Sub PIS_Click()
Form1.Show
Me. Hide
End Sub
25 | P a g e
RESULT
Thus the above program has been executed successfully.
26 | P a g e
10 . Write a program to implement animation using timers
AIM
To implement animation using timers
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:
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
27 | P a g e
Private Sub Timer1_Timer()
Image1.Left = Image1.Left + 10
If Image1.Left >= 2600 Then
Image1.Top = Image1.Top - 10
Image1.Left = Image1.Left + 10
End If
End Sub
OUTPUT
RESULT
Thus the above program has been executed successfully.
28 | P a g e