0% found this document useful (0 votes)
469 views35 pages

Visual Basic Programming Lab Exercises

The document contains a list of 10 programs to be written in Visual Basic to demonstrate various concepts. The programs include: 1. Designing a calculator application using Visual Basic. 2. Using checkboxes and option buttons in a program. 3. Performing drag and drop operations. 4. Demonstrating the use of a rich text box. 5. Using common dialog boxes. 6. Creating a program based on timers. 7. Demonstrating menu design. 8. Using multiple document interface forms. 9. Accessing child forms in an MDI form. 10. Accessing data through data controls.

Uploaded by

ashu nain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
469 views35 pages

Visual Basic Programming Lab Exercises

The document contains a list of 10 programs to be written in Visual Basic to demonstrate various concepts. The programs include: 1. Designing a calculator application using Visual Basic. 2. Using checkboxes and option buttons in a program. 3. Performing drag and drop operations. 4. Demonstrating the use of a rich text box. 5. Using common dialog boxes. 6. Creating a program based on timers. 7. Demonstrating menu design. 8. Using multiple document interface forms. 9. Accessing child forms in an MDI form. 10. Accessing data through data controls.

Uploaded by

ashu nain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PRACTICAL FILE

VISUAL BASIC PROGRAMMING


SOFTWARE LAB – II (CS DE37)

SUBMITTED TO : Directorate of Distance Education


Kurukshetra University , Kurukshetra

SUBMITTED BY : Ashu Nain, MCA II


Roll No. – 2291413101
Regn No. – 20-DE-8878
LIST OF PROGRAMS

1. Write a program to design a calculator using VB.


2. Write a program to use check box and option button.
3. Write a program to perform the Drag & Drop operation.

4. Write a program to show the use of rich text box.

5. Write a program to show the use of common dialog box.

6. Write a program based on timer.


7. Write a program to show the use of menu design.
8. Write a program to show the use of MDI (Multiple document interface)
form.

9. Write a program to access the child form in MDI form.

10. Write a program to access data through data control form design.
1. Write a program to design a calculator using VB.
Design window

Dim val1 As Double


Dim val2 As Double
Dim opt As String
Dim cleardisp As Boolean
Private Sub cmdAdd_Click()
val1 = Val([Link])
opt = "+"
[Link] = ""
End Sub
Private Sub cmdDiv_Click()
val1 = Val([Link])
opt = "/"
[Link] = ""
End Sub
Private Sub cmdDot_Click()
If InStr([Link], ".") Then
MsgBox "Don't Press Point Again", vbInformation, "!!Error"
Else
[Link] = [Link] + "."
End If
End Sub
Private Sub cmdEqual_Click()
Dim result As Double
val2 = Val([Link])
If opt = "+" Then result = val1 + val2
If opt = "-" Then result = val1 - val2
If opt = "X" Then result = val1 * val2
If opt = "/" And val2 <> 0 Then result = val1 / val2
If opt = "sqr" Then result = val1 * val1
If opt = "sqrt" Then result = Sqr(val1)
[Link] = result
End Sub
Private Sub cmdMul_Click()
val1 = Val([Link])
opt = "X"
[Link] = ""
End Sub
Private Sub cmdPercent_Click()
val1 = Val([Link])
opt = "1/X"
[Link] = ""
End Sub
Private Sub cmdSqrt_Click()
val1 = Val([Link])
opt = "sqr"
[Link] = ""
End Sub
Private Sub cmdsqr_Click(Index As Integer)
val1 = Val([Link])
opt = "sqr"
[Link] = ""
End Sub
Private Sub cmdSqroot_Click(Index As Integer)
val1 = Val([Link])
opt = "sqrt"
[Link] = ""
End Sub
Private Sub cmdSub_Click()
val1 = Val([Link])
opt = "-"
[Link] = ""
End Sub
Private Sub CommandClear_Click()
[Link] = ""
End Sub
Private Sub digit_Click(Index As Integer)
If cleardisp Then
[Link] = ""
cleardisp = False
End If
[Link] = [Link] + digit(Index).Caption
End Sub
Private Sub Form_Load()
End Sub

OUTPUT :

:
2. Write a program to use check box and option button.
Design Window

Private Sub Check1_Click()


If ([Link] = 1) Then
[Link] = True
Else
[Link] = False
End If
End Sub
Private Sub Check2_Click()
If ([Link] = 1) Then
[Link] = True
Else
[Link] = False
End If
End Sub
Private Sub Check3_Click()
If ([Link] = 1) Then
[Link] = True
Else
[Link] = False
End If
End Sub
Private Sub Form_Load()
End Sub
Private Sub Option1_Click()
[Link] = 10
End Sub
Private Sub Option2_Click()
[Link] = 12
End Sub
Private Sub Option3_Click()
[Link] = 14
End Sub
Private Sub Option4_Click()
[Link] = vbBlue
End Sub
Private Sub Option5_Click()
[Link] = vbGreen
End Sub
Private Sub Option6_Click()
[Link] = vbRed
End Sub

Output
3. Write a program to perform the Drag & Drop operation.
Design Window

Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)


[Link] = vbBlue
End Sub
Private Sub picture1_dragover(Source As Control, X As Single, Y As Single, state As
Integer)
If state = 0 Then
[Link] = vbRed
If state = 2 Then
[Link] = "source control moves over the picture box"
If state = 1 Then
[Link] = vbGreen
[Link] = "drag & drop demo"
End If
End Sub
4. Write a program to show the use of rich text box.
Design Window

Dim a As Variant
Private Sub Command1_Click()
[Link] = True
End Sub
Private Sub Command10_Click()
MsgBox ([Link])
End Sub
Private Sub Command11_Click()
[Link] = Len([Link])
MsgBox ([Link])
End Sub
Private Sub Command2_Click()
[Link] = True
End Sub
Private Sub Command3_Click()
[Link] = False
[Link] = False
End Sub
Private Sub Command4_Click()
[Link] = " "
End Sub
Private Sub Command5_Click()
[Link] = "C:\Documents and Settings\[Link]-01\My
Documents\[Link]"
End Sub
Private Sub Command6_Click()
a = [Link]
[Link] = a
End Sub
Private Sub Command7_Click()
a = [Link]
Print a
End Sub
Private Sub Command8_Click()
[Link] = UCase([Link])
Print a
End Sub
Private Sub Command9_Click()
[Link] = "revised string"
End Sub
Output:
5. Write a program to show the use of common dialog box.
Design Window

Public newform As frmmain


Private Sub MDIForm_Initialize()
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link]("cut").Enabled = False
[Link]("copy").Enabled = False
[Link]("paste").Enabled = False
[Link]("save").Enabled = False
End Sub
Private Sub MDIForm_Load()
[Link]
End Sub
Private Sub mnubold_Click()
If [Link] = True Then
[Link] = False
Else
[Link] = True
End If
End Sub
Private Sub mnubolditalic_Click()
[Link] = True
[Link] = True
End Sub
Private Sub mnucolor_Click()
[Link]
[Link] = [Link]
End Sub
Private Sub mnueditcopy_Click()
[Link] [Link]
[Link] = True
[Link]("paste").Enabled = True
End Sub
Private Sub mnueditcut_Click()
[Link] [Link]
[Link] = ""
[Link] = True
[Link]("paste").Enabled = True
End Sub
Private Sub mnueditpaste_Click()
[Link] = [Link]
End Sub
Private Sub mnueditselall_Click()
[Link] = 0
[Link] = Len([Link])
[Link]
End Sub
Private Sub mnufileexit_Click()
End
End Sub
Private Sub mnufilenew_Click()
Set newform = New frmmain
[Link] = ""
[Link] = "untitled" & Str([Link] - 2)
[Link] = True
[Link] = True
[Link] = True
[Link] = True
[Link]("cut").Enabled = True
[Link]("copy").Enabled = True
[Link]("save").Enabled = True
[Link]("file").Text = [Link]
[Link]
End Sub
Private Sub mnufileopen_Click()
[Link]
End Sub
Private Sub mnufilesaveas_Click()
[Link]
End Sub
Private Sub mnuitalic_Click()
If [Link] = True Then
[Link] = False
Else
[Link] = True
End If
End Sub
Private Sub mnuregular_Click()
[Link] = False
[Link] = False
End Sub
Private Sub mnuunderline_Click()
If [Link] = True Then
[Link] = False
Else
[Link] = True
End If
End Sub
Private Sub mnuwincas_Click()
[Link] vbCascade
End Sub
Private Sub mnuwinth_Click()
[Link] vbTileHorizontal
End Sub
Private Sub standard_ButtonClick(ByVal Button As [Link])
Select Case [Link]
Case "new"
mnufilenew_Click
Case "open"
mnufileopen_Click
Case "save"
mnufilesaveas_Click
Case "cut"
mnueditcut_Click
Case "copy"
mnueditcopy_Click
Case "paste"
mnueditpaste_Click
End Select
End Sub
Private Sub Timer1_Timer()
Dim num As Integer
num = [Link] - 2
If num > 0 Then
[Link]("file").Text = [Link]
Else
[Link]("file").Text = "enjoy mdi notepad"
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link] = False
[Link]("cut").Enabled = False
[Link]("copy").Enabled = False
[Link]("paste").Enabled = False
[Link]("save").Enabled = False
End If
End Sub
output:
6. Write a program based on timer.
Design Window
Option Explicit
Dim a, b, l, t, c, col As Integer
Private Sub exit_Click()
End
End Sub
Private Sub Form_Load()
l=0b=0t=0
[Link] = False
[Link] = " VISUAL BASIC"
[Link] = True
[Link] = vbRed
[Link] = vbYellow
[Link] = "20"
[Link] = "timer"
[Link] = 2
End Sub
Private Sub start_Click()
[Link] = True
End Sub
Private Sub stop_Click()
[Link] = False
End Sub
Private Sub Timer1_Timer()
[Link] = Time
[Link] = "no. of records" & c
If (col < 15) Then
[Link] = QBColor(col)
col = col + 1 Else
col = 1 End If
If ([Link] < 12000 And t = 0) Then
[Link] = 100
[Link] = [Link] + 100
ElseIf ([Link] > 9700 And t = 0 And [Link] < 9500) Then
[Link] = [Link] + 100
l=1b=0
ElseIf ([Link] >= 1000 And b = 0) Then
[Link] = 9400
[Link] = [Link] - 100
t=1
ElseIf ([Link] > 500 And b = 0 And t = 1) Then
[Link] = 50
[Link] = [Link] - 100
Else
c=c+1
t=0b=0l=0
End If End Sub
Output:
7. Write a program to show the use of menu design.
Design Window

Private Sub abcolorblue_Click()


[Link] = True
[Link] = False
[Link] = False
[Link] = False
If [Link] = 0 Then
[Link] = vbBlue
ElseIf [Link] = 0 Then
[Link] = vbBlue
ElseIf [Link] = 0 Then
[Link] = vbBlue
End If
End Sub
Private Sub abcolorgreen_Click()
[Link] = False
[Link] = True
[Link] = False
[Link] = False
If [Link] = 0 Then
[Link] = vbGreen
ElseIf [Link] = 0 Then
[Link] = vbGreen
ElseIf [Link] = 0 Then
[Link] = vbGreen
End If
End Sub
Private Sub abcolorred_Click()
[Link] = False
[Link] = False
[Link] = True
[Link] = False
If [Link] = 0 Then
[Link] = vbRed
ElseIf [Link] = 0 Then
[Link] = vbRed
ElseIf [Link] = 0 Then
[Link] = vbRed
End If
End Sub
Private Sub abcoloryellow_Click()
[Link] = False
[Link] = False
[Link] = False
[Link] = True
If [Link] = 0 Then
[Link] = vbYellow
ElseIf [Link] = 0 Then
[Link] = vbYellow
ElseIf [Link] = 0 Then
[Link] = vbYellow
End If
End Sub
Private Sub abfileexit_Click()
End
End Sub
Private Sub abshapecircle_Click()
[Link] = True
[Link] = False
[Link] = False
[Link] = 0
[Link] = 1
[Link] = 1
[Link] = &H0&
[Link] = &H0&
End Sub
Private Sub abshaperectangle_Click()
[Link] = False
[Link] = False
[Link] = True
[Link] = 1
[Link] = 0
[Link] = 1
[Link] = &H0&
[Link] = &H0&
End Sub
Private Sub abshapesquare_Click()
[Link] = False
[Link] = True
[Link] = False
[Link] = 1
[Link] = 1
[Link] = 0
[Link] = &H0&
[Link] = &H0&
End Sub
Output:
8. Write a program to show the use of MDI (Multiple document interface) form.
Design Window

Private Sub mcascade_Click()


[Link] vbCascade
End Sub
Private Sub MDIForm_Load()
[Link] [Link]
[Link]
[Link] = 2
End Sub
Private Sub mhorizontal_Click()
[Link] vbHorizontal
End Sub
Private Sub mvertical_Click()
[Link] vbVertical
End Sub

Output:
9. Write a program to access the child form in MDI form.
Design Window

Option Explicit
Dim documentforms(10) As New Form1
Private Sub arrange_Click()
arrange 2
End Sub
Private Sub cascade_Click()
arrange 0
End Sub
Private Sub FormOpen_Click()
Dim i As Integer
For i = 0 To 9
documentforms(i).Show
documentforms(i).Caption = "document" & Format(i)
documentforms(i).BackColor = QBColor(Rnd * 14 + 1)
Next i
End Sub
Private Sub FormsClose_Click()
Dim i As Integer
For i = 0 To 9
Unload documentforms(i)
End Sub
Private Sub horizontal_Click()
arrange 1
End Sub
OUTPUT:

WHEN WE CLICK ON CHILD FORMS AND THEN OPEN FORMS


10. Write a program to access data through data control form design.
Design Window

Option Explicit
Dim responce As Integer
Private Sub Command1_Click()
[Link]
[Link]
End Sub
Private Sub Command2_Click()
responce = MsgBox("do you want to delete the record", vbYesNo)
If responce = vbYes Then
[Link]
[Link]
End If
End Sub
Private Sub Command3_Click()
[Link]
[Link]
End Sub

Private Sub Command4_Click()


If [Link] = True And [Link] = True Then
MsgBox "the file is empty"
Else
[Link]
End If
End Sub
Private Sub Command5_Click()
If [Link] = True And [Link] = True Then
MsgBox "the file is empty"
Else
[Link]
If [Link] = True Then
[Link]
MsgBox "you are at 1st record"
End If
End If
End Sub
Private Sub Command6_Click()
If [Link] = True And [Link] = True Then
MsgBox "the file is empty"
Else
[Link]
If [Link] = True Then
[Link]
MsgBox " you are at last record"
End If
End If
End Sub
Private Sub Command7_Click()
If [Link] = True And [Link] = True Then
MsgBox "the file is empty"
Else
[Link]
End If
End Sub
Private Sub Command8_Click()
End
End Sub
Output:

You might also like