Visual Basic Lab Manual PDF
Visual Basic Lab Manual PDF
End Semester
EXPERIMENT NO:- 1
1.OBJECTIVE :- Design a form for arithmetic operations using textbox, label, command button.
2.HARDWARE & SYSTEM SOFTWARE REQUIRED :-P2,P4 System or windows
xp,vista.
5.THEORY :TextBox:This control displays text that the user can edit.
Label:This control displays text on a Form that the user cant edit.
Command Button:This is the most common element of the Windows interface.A Command
button represents an action that is carried out when the user clicks the button.
Properties Window :
Form1 :
Caption
: Math Calculator
Command :
Style
: Graphical
Text1 :
Alignment : Right Justify
Locked
: True
Source Code :
Option Explicit
Dim operand1 As Double, operand2 As Double
Dim operator As String
Dim cleardisplay As Boolean
Private Sub Command1_Click()
Text1.Text = Text1.Text + Command1.Caption
End Sub
Private Sub Command10_Click()
Text1.Text = ""
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text + Command1.Caption
End Sub
Private Sub Command12_Click()
If InStr(Text1.Text, ".") Then
Exit Sub
Else
Text1.Text = Text1.Text + Command12.Caption
End If
End Sub
Private Sub Command13_Click()
operand1 = Val(Text1.Text)
operator = "+"
Text1.Text = ""
End Sub
Private Sub Command14_Click()
operand1 = Val(Text1.Text)
operator = "-"
Text1.Text = ""
End Sub
Private Sub Command15_Click()
operand1 = Val(Text1.Text)
operator = "*"
Text1.Text = ""
End Sub
Private Sub Command16_Click()
operand1 = Val(Text1.Text)
operator = "/"
Text1.Text = ""
End Sub
Private Sub Command17_Click()
Dim result As Double
operand2 = Val(Text1.Text)
If operator = "+" Then result = operand1 + operand2
If operator = "-" Then result = operand1 - operand2
If operator = "*" Then result = operand1 * operand2
If operator = "/" And operand2 <> "0" Then result = operand1 / operand2
Text1.Text = result
End Sub
Private Sub Command18_Click()
End
End Sub
Private Sub Command2_Click()
Text1.Text = Text1.Text + Command2.Caption
End Sub
Private Sub Command3_Click()
Text1.Text = Text1.Text + Command3.Caption
End Sub
Private Sub Command4_Click()
Text1.Text = Text1.Text + Command4.Caption
End Sub
Private Sub Command5_Click()
Text1.Text = Text1.Text + Command5.Caption
End Sub
Private Sub Command6_Click()
Text1.Text = Text1.Text + Command6.Caption
End Sub
Private Sub Command7_Click()
Text1.Text = Text1.Text + Command7.Caption
End Sub
Private Sub Command8_Click()
Text1.Text = Text1.Text + Command8.Caption
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text + Command9.Caption
End Sub
6.OBSERVATIONS :-Task is Performed
EXPERIMENT NO:- 2
1.OBJECTIVE :- Design a form for speed control program using scroll bars.
2.HARDWARE & SYSTEM SOFTWARE REQUIRED :-P2,P4 System or windows
xp,vista.
5.THEORY :ScrollBars-This property controls the attachment of scroll bars to the TextBox control if the text
exceeds the controls dimensions.
Properties Window :
Form1 :
Caption
: Shape
Source Code :
Private Sub Command1_Click()
End
End Sub
Private Sub HScroll1_Change()
Shape1.Width = HScroll1.Value
End Sub
Private Sub VScroll1_Change()
Shape1.Height = VScroll1.Value
End Sub
6.OBSERVATIONS :-Task is Performed.
EXPERIMENT NO:- 3
1.OBJECTIVE :- Design a form to display a picture using image box/picture box selected from a
file in file list box directory list box, drive list box.
2.HARDWARE & SYSTEM SOFTWARE REQUIRED :-P2,P4 System or windows xp,vista.
3.SOFTWARE REQUIRED :- Visual Basic6
4.PROGRAM INPUTS & OUTPUT :-
5.THEORY :PictureBox:This control is used to display images , and the images are set with the Picture
property.
Image:This control is similar to the PictureBox control in that it can display images,but it
supports only a few features of the PictureBox control(You cant draw on an Image control as
you can on the PictureBox control) and requires fewer resources.
File ListBox:This control displays a list of all files in the current folder.
Directory ListBox:This control displays a list of folders in the current drive and lets the user
move up or down in the hierarchy of the folders.
Drive ListBox:The control displays the drives on the system in a drop-down list from which
the user can select.
Properties Window :
Form1 :
Caption
: Image Viewer
Image1 :
Stretch
: True
Source Code :
Private Sub Command1_Click()
Image1.Picture = LoadPicture(Dir1.Path + "\" + File1.FileName)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
6.OBSERVATIONS :-Task is Performed.
EXPERIMENT NO:- 4
1.OBJECTIVE :- Design a form using shape control to display signal and change it timely using
timer control.
5.THEORY :-
Timer1.Interval = 10000
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Timer1_Timer()
Select Case myposition
Case "stop"
Shape1.FillColor = vbWhite
Shape2.FillColor = vbYellow
Shape3.FillColor = vbWhite
myposition = "wait"
Case "wait"
Shape1.FillColor = vbWhite
Shape2.FillColor = vbWhite
Shape3.FillColor = vbGreen
myposition = "go"
Case "go"
Shape1.FillColor = vbRed
Shape2.FillColor = vbWhite
Shape3.FillColor = vbWhite
myposition = "stop"
End Select
End Sub
6.OBSERVATIONS :-Task is Performed.
EXPERIMENT NO:- 5
1.OBJECTIVE :- Design form to create a font dialog box using combo/ list, text, option buttons,
and check box control.
5.THEORY :TextBox:This control displays text that the user can edit.
Option Button:Option buttons,or radio buttons,appear in groups,and the user can select choose
only one of them.
CheckBox:The CheckBox control presents one or more choice that the user can select.
Properties Window :
Form1 :
Caption
: Font Dialog Box
Source Code :
Private Sub Check1_Click()
If Check1.Value Then
Text1.FontSize = 24
Else
10
Text1.FontSize = 12
End If
End Sub
Private Sub Combo1_LostFocus()
Text1.Font = Combo1.Text
Text1.Refresh
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 60
Combo1.AddItem (Screen.Fonts(i))
Next
End Sub
Private Sub Option1_Click()
Text1.FontBold = True
End Sub
Private Sub Option2_Click()
Text1.FontBold = False
End Sub
6.OBSERVATIONS :-Task is Performed.
11
EXPERIMENT NO:- 6
1.OBJECTIVE :- Design a simple application using OLE control.
2.HARDWARE & SYSTEM SOFTWARE REQUIRED :-P2,P4 System or windows xp,vista.
3.SOFTWARE REQUIRED :- Visual Basic6
4.PROGRAM INPUTS & OUTPUT :-
5.THEORY :OLE:This control is a window you can place on your Form to host documents from other
applications,such as Microsoft Word or Excel.Through this control,you can access The
functionality of other applications,if they support OLE.
Properties Window :
Form1:
Caption
: OLE Drag
Source Code :
Private Sub Command1_Click()
End
End Sub
12
13
EXPERIMENT NO:- 7
1.OBJECTIVE :- Design a form using Tab control, image list, status bar, tool bar which
facilitates different arithmetic operations.
5.THEORY :Tab control- A Tab control Presents the user with a row (or rows ) or tabs that acts like the
dividers
in a notebook or the labels on a group of files folders.
Image list control- Image list control are invisible controls that serve one purpose: to hold
images that are
used by other controls.
Properties Window :
Form1 :
Caption
: Using Tab Control
ImageList1 :
Toolbar1:
14
Source Code :
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim msgpress As Integer
Select Case Button.Key
Case Is = "ADD"
Text3.Text = CInt(Text1.Text) + CInt(Text2.Text)
Case Is = "SUB"
Text3.Text = CInt(Text1.Text) - CInt(Text2.Text)
Case Is = "MUL"
Text3.Text = CInt(Text1.Text) * CInt(Text2.Text)
Case Is = "DIV"
Text3.Text = CInt(Text1.Text) / CInt(Text2.Text)
Case Is = "EXIT"
Unload Me
End
End Select
StatusBar1.Panels(1).Text = " Result :: " + Text3.Text & Format$(Index)
End Sub
6.OBSERVATIONS :-Task is Performed.
15
EXPERIMENT NO:- 8
1.OBJECTIVE :- Design a form using menu editor, MDI, common dialog box which has
standard format like Notepad. (eg. File , Edit , format) open copy, font, save and cut.
5.THEORY :MDI-The Multiple Document Interface(MDI) was designed to simplify the exchange of
information among documents , all under the same roof.
Properties Window :
frmMain :
Caption
: Notepad
Source Code :
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As
Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Const EM_UNDO = &HC7
Private Declare Function OSWinHelp% Lib "user32" Alias "WinHelpA" (ByVal hwnd&, ByVal
HelpFile$, ByVal wCommand%, dwData As Any)
16
17
ActiveForm.rtfText.SelAlignment = rtfCenter
Case "Align Right"
ActiveForm.rtfText.SelAlignment = rtfRight
End Select
End Sub
Private Sub mnuHelpAbout_Click()
MsgBox "Version " & App.Major & "." & App.Minor & "." & App.Revision
End Sub
Private Sub mnuHelpSearchForHelpOn_Click()
Dim nRet As Integer
'if there is no helpfile for this project display a message to the user
'you can set the HelpFile for your application in the
'Project Properties dialog
If Len(App.HelpFile) = 0 Then
MsgBox "Unable to display Help Contents. There is no Help associated with this project.",
vbInformation, Me.Caption
Else
On Error Resume Next
nRet = OSWinHelp(Me.hwnd, App.HelpFile, 261, 0)
If Err Then
MsgBox Err.Description
End If
End If
End Sub
Private Sub mnuHelpContents_Click()
Dim nRet As Integer
'if there is no helpfile for this project display a message to the user
'you can set the HelpFile for your application in the
'Project Properties dialog
If Len(App.HelpFile) = 0 Then
MsgBox "Unable to display Help Contents. There is no Help associated with this project.",
vbInformation, Me.Caption
Else
On Error Resume Next
nRet = OSWinHelp(Me.hwnd, App.HelpFile, 3, 0)
If Err Then
MsgBox Err.Description
End If
End If
End Sub
Private Sub mnuWindowArrangeIcons_Click()
Me.Arrange vbArrangeIcons
End Sub
Private Sub mnuWindowTileVertical_Click()
Me.Arrange vbTileVertical
End Sub
Private Sub mnuWindowTileHorizontal_Click()
Me.Arrange vbTileHorizontal
End Sub
18
19
20
End Sub
Private Sub mnuFileSaveAs_Click()
Dim sFile As String
If ActiveForm Is Nothing Then
Exit Sub
With dlgCommonDialog
.DialogTitle = "Save As"
.CancelError = False
'ToDo: set the flags and attributes of the common dialog control
.Filter = "All Files (*.*)|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
ActiveForm.Caption = sFile
ActiveForm.rtfText.SaveFile sFile
End Sub
Private Sub mnuFileSave_Click()
Dim sFile As String
If Left$(ActiveForm.Caption, 8) = "Document" Then
With dlgCommonDialog
.DialogTitle = "Save"
.CancelError = False
'ToDo: set the flags and attributes of the common dialog control
.Filter = "All Files (*.*)|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
ActiveForm.rtfText.SaveFile sFile
Else
sFile = ActiveForm.Caption
ActiveForm.rtfText.SaveFile sFile
End If
End Sub
Private Sub mnuFileClose_Click()
'ToDo: Add 'mnuFileClose_Click' code.
MsgBox "Add 'mnuFileClose_Click' code."
End Sub
Private Sub mnuFileOpen_Click()
Dim sFile As String
If ActiveForm Is Nothing Then LoadNewDoc
With dlgCommonDialog
.DialogTitle = "Open"
.CancelError = False
'ToDo: set the flags and attributes of the common dialog control
.Filter = "All Files (*.*)|*.*"
.ShowOpen
21
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
ActiveForm.rtfText.LoadFile sFile
ActiveForm.Caption = sFile
End Sub
Private Sub mnuFileNew_Click()
LoadNewDoc
End Sub
6.OBSERVATIONS :-Task is Performed.
22
EXPERIMENT NO:- 9
1.OBJECTIVE :- Design a simple database application which covers all database
concepts.(Data control,DAO,RDO,ADO, DB-list , DB combo), Create property pages without
using the property page wizard.
2.HARDWARE & SYSTEM SOFTWARE REQUIRED :-P2,P4 System or windows xp,vista.
3.SOFTWARE REQUIRED :- Visual Basic6
5.THEORY :DAO-Visual Basic only supported DAO, which connected to the Microsoft Jet database engine
(the Database engine in Microsoft Access).
ADO- ADO is also called OLE DB, and in fact, its based on COM programming techniques.
DB List-The data-bound List control can be bound to a specific column of the RecordSet and is
commonly used as a lookup table.
DB combo- The list of the data-bound ComboBox control , you must set its RowSource property
to a Data control , connected to the database and table from which the data will come.
Properties Window :
Form1:
Caption
: ADO
Source Code :
Option Explicit
Dim Cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSql As String
23
24
25