Documente Academic
Documente Profesional
Documente Cultură
Page 1 of 121
Note:
This question-bank contains three sections.
Section-A contains 1 mark Multiple Choice Objective type questions.
Section-B contains 5 marks subjective questions.
Section-A contains 10 marks subjective questions.
Section A
[QUESTIONS 1 TO 152]
1 Marks Questions
[PAGE 1 TO 17]
(b) Instructions
(d) An object
Q8. In the IDE, which of following is used to design the layout of an application?
(a) Form Designer window
(b) Project Explorer window
(c) Context Menu
(d) Form Layout window
Q9. The location of the form on the desktop during execution is determined by the:
(a) Form Designer window
(b) Project Explorer window
(c) Context Menu
(d) Form Layout window
SUBJECT: VB
Page 2 of 121
SUBJECT: VB
Page 3 of 121
b. keyword
d.symbol
d.7
b.command
d.command1
c. list box
d. box
d.31
b. got focus
d. all of above
d.6
b.code window
d.text box
SUBJECT: VB
Page 4 of 121
b. ual basic
d. basic
c. llo
d. elo
SUBJECT: VB
Page 5 of 121
SUBJECT: VB
b.)
c.)
d.)
e.)
Page 6 of 121
SUBJECT: VB
b.)
c.)
d.)
e.)
Page 7 of 121
b.) Byte
d.) Integer
SUBJECT: VB
Page 8 of 121
e.) Long
Q66.Which is a numeric data type?
a.) Floating point
c.) Boolean
e.) All of the above.
b.) Integer
d.) Both a and b.
Q67.The Date data type does not hold which type of information.
a.) Seconds
b.) Hours
c.) Days
d.) Months
e.) Quarters
Q68.The Boolean data type:
a.) is unsigned.
b.) has two states.
c.) is displayed by the program as yes or no.
d.) Both a and b.
e.) All of the above.
Q69.Which is a valid statement for declaring a variable?
a.) Const Form As Integer
b.) Const myForm As Integer
c.) Private Dim Form As Integer
d.) Dim myForm As Integer
e.) All of the above.
Q70.VB.Net identifiers:
a.) are case sensitive.
c.) can begin with a number.
e.) All of the above.
SUBJECT: VB
Page 9 of 121
c.) .DOC
d.) .VBP
SUBJECT: VB
Page 10 of 121
SUBJECT: VB
b.)
c.)
d.)
e.)
Page 11 of 121
SUBJECT: VB
Page 12 of 121
SUBJECT: VB
c) Code window
Page 13 of 121
d) Title bar
b) Not updateable
d) Defined in the Intermediate window
Q110.Code is:
a) Updateable in the form editor
c) Seldom used
b) Instructions
d) An object
Q111.Controls are:
a) Code
c) Rules
Q112.In the IDE, which of following is used to design the layout of an application?
a) Form Designer window
b) Project Explorer window
c) Context Menu
d) Form Layout window
Q113.The location of the form on the desktop during execution is determined by the:
a) Form Designer window
b) Project Explorer window
c) Context Menu
d) Form Layout window
Q114.The Object Browser:
a) Displays the command buttons and textboxes, etc.
b) Shows frequently used shortcuts as objects
c) Is a Context Menu
d) Displays the object libraries and their combinations of data and code
Q115.The location of the form on the desktop during execution is determined by the:
a) Form Designer window
b) Project Explorer window
b) Context Menu
d) Form Layout window
Q116.The first procedure-oriented language was:
a) FORTRAN
b) BASIC
c) COBOL
d) ADA
Q117.RAD stands for
a. rapid application development
c. reused application development
Q118.dim is a _______
a. data type
c. operator
b. keyword
d.symbol
d.7
SUBJECT: VB
Page 14 of 121
b.command
d.command1
b. list
d. box
b. got focus
d. all of above
b. ual basic
d. basic
c. llo
d. elo
SUBJECT: VB
Page 15 of 121
b.) classes.
d.) events.
b.) classes.
d.) events.
SUBJECT: VB
Page 16 of 121
b.) Byte
d.) Integer
b.) Integer
d.) Both a and b.
d.) mni.
e.) mnu.
Q146. Which symbol creates an access key in the text of a menu item?
a.) @
b.) #
c.) $
d.) %
e.) &
Q147. Which is not a standard dialog box?
a.) ColorDialog
c.) OpenDialog
e.) ZoomDialog
b.) FontDialog
d.) PrintDialog
d.) dlg.
Q149. What is the method used to activate the color dialog box?
a.) ActivateDialog
b.) DisplayDialog
c.) ExhibitDialog
d.) ShowDialog
SUBJECT: VB
Page 17 of 121
Q150. The name of the class used to programmatically create a color dialog box is:
a.) Color
b.) ColorBox
c.) ColorDialog
d.) ColorDisplay
Q151. The name of the class used to programmatically create a font dialog box is:
a.) Font.
b.) FontBox.
c.) FontDialog.
d.) FontDisplay.
e.) FontDialogBox.
Q152. Which dialog control allows the user to zoom in on a document?
a.) PrintDialog
b.) PrintPreview
c.) PageSetupDialog
d.) Both a and b.
e.) All of the above.
Answers
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
D
D
D
D
A
B
D
A
D
D
D
A
A
D
C
D
A
A
A
A
A
A
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
A
B
A
A
A
C
D
C
A
A
D
A
B
D
E
A
E
C
A
A
E
E
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
A
C
D
E
D
C
E
d
A
C
D
B
E
E
B
E
A
E
A
D
A
D
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
E
D
D
B
D
B
D
A
A
D
C
B
B
B
E
E
D
A
D
E
C
A
89. E
90. A
91. A
92. C
93. B
94. C
95. B
96. B
97. B
98. A
99. B
100. E
101. B
102. B
103. A
104. A
105. D
106. D
107. D
108. D
109. A
110. B
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
D
A
D
D
D
A
D
B
B
C
A
D
A
D
A
A
A
D
E
A
C
A
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
C
D
B
E
B
A
D
A
D
A
D
D
E
E
E
D
D
C
C
b
SUBJECT: VB
Section B
[Questions 1 TO 174]
Page 18 of 121
5 Marks Questions
[PAGE 18 TO 100]
Q3. What is the difference between Event driven programming and procedural
Programming?
Ans. There different types of programming. And different languages at least support one of
them. We can categorize the programming into the following types.
1. Unstructured 2. Structured / Procedural 3. Object Oriented 4. Event driven.
1. Unstructured programming: - There is no specific flow of the program code, control can be
transferred from any where to any part of the program. More and more use of Go To statement in
the program helps to make the program unstructured.
2. Procedural programming: - In procedural programming, the program is divided in to the
small sub blocks. These blocks are called procedures and these procedures execute their source
code by calling. Procedural programming helps to make debugging easy.
3. Object Oriented programming: - This programming is based on the objects and classes.
4. Event driven programming: - Event or actions are performed on the specific component and
components respond according to these actions and execute the code written under the event
procedure.. Normally event procedures are local to the form in which they are declared and have
private access.
SUBJECT: VB
Page 19 of 121
Q4. Write down the names of different controls and their purpose.
(v.imp)
Ans. Toolbar: - It contains a set of controls that are used to place in a form at design time
thereby creating the user interface area. User can include additional controls in the toolbox by
using the Components menu item on the project menu. A Toolbox contains the following controls The pointer helps to move and resize the control and Forms.
Label displays a text that user cannot modify or interact with.
Frame control serves as a visual and functional container for controls.
Check Box displays a True/False or Yes/No option.
Textbox is a control used to display message and enter text.
The List Box displays a list of items from which a user can select one.
Combo Box contains a Textbox and a List Box. This allows the user to select an item from the
dropdown List Box or to type a selection in the Textbox.
HScroll Bar and VScrollbar controls allow the user to select a value within the specified
range of values.
Timer control executes timer events at specified intervals of time.
DirListBox allows the user to select directories and paths, which are displayed.
Shape control adds a shape (rectangle, square or circle) to a Form.
Image control is used to display icon, bitmaps, metafiles, etc.
OLE controls used to link or embed an object display and manipulate data from other
Windows based applications.
PictureBox displays icons/ bitmaps and metafiles. It displays text or acts as a visual container
for other control.
CommandButton carries out the specified action when the user chooses it.
The OptionButton control, which is a part of an option group, allows the user to select one
option even if it displays multiple choices.
The DriveListBox displays the valid disk drives and allows the user to select one of them.
The FileListBox displays a set of files from which a user can select the desired one.
Line control draws a straight line to the Form.
Data control enables the user to connect to an existing database and display information from
it.
Q5. Write down the properties of textbox and their purpose.
Ans. All the controls in the Toolbox except the Pointer are objects in Visual Basic. These
objects have associated properties. For example, a flower is loaded with certain colour, shape
and fragrance. Similarly, programming objects are loaded with properties.
A property is a named attribute of a programming object. Properties define the characteristic of an
object such as size, color, etc. or sometimes the way in which it behaves. For example, a Textbox
accepts properties such as Enabled, Font, Multi Line, Text, Visible, Width, etc. These are
discussed below:
SUBJECT: VB
Page 20 of 121
Enabled property allows the Textbox to be enabled or disabled at run time depending on the
condition set to True or False.
Font property sets a particular font allows the Textbox.
Multi Line property allows the Textbox to accept and display multiple lines at run time.
Text property of the Textbox control sets a particular text in the control.
Visible property is used to unhide the object at run time.
Width property sets the Textbox to the desired width at design time.
The properties that are discussed above are design time properties that can be set at the design
time by selection the Properties window. But certain properties cannot be set at design time.
A method is an action that can be performed on objects. For example, a cat is an object. Its
properties might include long white hair, blue eyes, three pounds weight, etc. A complete
definition of cat must not only encompass on its looks, but should also include a complete
itemization of its activities. Therefore, a cat's methods might be move, jump, play, breathe, etc.
Similarly, in object-oriented programming, a method is a connected or built-in procedure, a
block of code that can be invoked to impart some action on a particular object. A method requires
an object to provide them with a context. For example, the word Move has no meaning in Visual
Basic, but the following statement, performs a very precise action.
Text1. Move 700, 400
The textbox control has other associated methods such as Refresh, Set Focus, etc.
The Refresh method enforces a complete repaint of the control or a Form. For example,
Text1. Refresh refreshes the Text Box.
The Set Focus method moves the focus to the control .For example
Tex1. Set Focus sets the focus to Textbox control Text1.
Q6. Write a short note on option Explicit.
Ans. It may be convenient to declare variable implicitly, but it can lead to errors that may not
be recognized at run. Say e.g. a variable name intcount is used implicitly and is assigned a value.
In the next step, the field is incremented by 1 by the following statement.
Intcount =intcont+1
This calculation will result in intcount yielding a value of 1, as intcont would have been initialized
to zero. This because the intcount variable has been mistyped as intcont in the right hand side of
the second variable. But Visual Basic does not view this as a mistake and consider it to the new
variable and hence gives a wrong result.
To prevent errors of this nature, we can declare a variable by adding the following statement
to the general declaration section of the Form. Which is -Option Explicit
This forces the user to declare all the variable. The option explicit statement checks the
module for usage of any undeclared variable and reports an error to the user. The user can thus
rectify the error on seeing this error message.
SUBJECT: VB
Page 21 of 121
The Option Explicit statement can be explicitly placed in the general declaration section of
each module using the following steps.
Q7. Name and explain in brief various components of Visual Basic IDE.
Ans. IDE is Integrated Development Environment, which is commonly used in the
programming world to describe the interface and environment that we use to create our
applications. It is called integrated because we can access virtually all the development tools that
we need from one screen called an interface.
Main elements or components of IDE are:
a.Menu bar: - It contains different types of menus and a group of similar type instructions are
store in a single menu.
b.Toolbar: - It contains the shortcuts of the commands appearing in different menus. By using a
toolbar, user can use many items contained in different menus without opening a menu again &
again. User can directly select them from the toolbar.
c.Project Explorer :- it contains the list of forms, module and class modules used in the project
window
d.Properties:- It contains the list of properties for the selected control.
e.Toolbox: - It contains all the implicit controls used in VB.
f. Form Designer: - here we can design the form for vb project.
g. Object Browser: - It allow the user to browse through the various properties,
Q8. What is control? Can we create our own control in visual Basic?
Ans. A control is an object, which we place on the form to create a user interface. Examples of
controls are command button, textbox control, label, picture box etc. We can add more controls
by right clicking on the toolbox and then by selecting components from pop up menu. All the
controls can be accessed from the toolbox. Nearly every control has its own properties &
methods. We can set the properties of a control at design time and through coding. We can make
controls responding to the happening of events. For example: change method of textbox
responds to the code written in change method whenever the text in the textbox changes.
We can create our own controls in visual Basic & these are called ActiveX controls. User can
design their own controls or can extend the properties of existing controls. For example: you can
design a textbox control that accepts only numeric data.
Q9. Describe a forms life cycle.
Ans. A forms life cycle starts when it got loaded in the memory and ends when that form is
being unloaded. When a form is loaded the events fired are referred to as Birth Events such as
Initialize Event, Load event, Resize Event, Activate Event. To watch the interaction of the user with
the form various events are fired such as mouse move Event, click event, double click event etc.
When the form is unloaded its shutdown events are fired such as QueryUnload Event, unload
event, terminate event. All these events can be tracked through the immediate window. We can
display a message each time an event is fired.
Q10.What are classes and objects? Discuss how to add properties, events and methods to
a class module?
SUBJECT: VB
Page 22 of 121
Ans.A class is a self-sufficient piece of code, which means you can move the class from one
project to another and it should, work properly without any modification. A class contains
properties and methods that all work together to perform a set of related operations. Object is an
instance of a class, which is used to access the members of class.
Methods: - Adding method to a class is just like adding procedure to a class module. You can
prefix the method name with Private or Public, depending on the scope of method.
Properties: - are variables used to store and retrieve data from classes. Properties that are
declared as public are called exposed properties. This means the data within the class can be
accessed from another procedure outside the scope of the class. The exposed properties make
up a portion of the classs interface. Private properties can be used to keep data and procedures
hidden behind the interface. This prevents programs from directly or unintentionally modifying the
contents of data required for the class to function properly.
Events: - are most interesting portion of class module. They allow the class to communicate
information back to an application when sets of conditions are met. This makes the application an
event driven application means it relies on events to make program operate.
Q11. What is recursion? Explain with suitable example.
Ans. Recursion can be described as a procedure in which a function or procedure calls itself.
Code written in a function is extended sequentially but when a function calls itself then the same
code is executed by each call to the function. In recursion function, a function calls itself again &
again.
E.g. - If we want to calculate the factorial of a number with the help of a recursion function, then we
can write the following code for the function.
Private Function Rec (x as integer)
If x = 1 then
Rec= 1.
Else
f* rec (x 1)
Rec =f
End If
Q12.What do you understand by OLE?
Ans. OLE is object linking & embedding. With the help of OLE we can add other objects in our
visual basic application .OLE control is a part of visual basic toolbox. Through OLE control you
can insert an object from one application into another application. The inserted object is a copy of
the original object. For example, you can embed a range of cells from an excel worksheet in a word
document. OLE container control, allows you to insert objects from other applications into your
program. You can place only one object in the container control at a time, but there can be multiple
OLE container control on a single form. You can embed word documents, sounds, images and
SUBJECT: VB
Page 23 of 121
excel spreadsheets in your VB applications. OLE container control hides all the complications of
OLE from the user & you can build OLE-capable applications.
Q13.Discuss Timer control with suitable example.
Ans. Timer control is used to fire an event at specified intervals of time. The code you want to
execute is placed in the timer event of timer control. This control has no methods and only one
event called timer event. And has seven properties. This control is invisible at run time. When a
timer control is placed on form its Enabled property is by default true. Whenever this property is set
to true the timer controls timer event is fired at regular intervals as specified. The unit of
measurement is milliseconds. For example, following code will print how many times the timer has
been fired.
Private Sub Timer1_Timer()
Static counter as long
Counter = Counter +1
Label1. caption = The timer has been fired & str (counter)& times!
End Sub
Q14.Write a program in which When you click on add button the new option button is
added and when a delete button is clicked, the option button got deleted. And when you
click an option button the color of the picture changes.
Ans.
DIM MaxID as integer
Private Sub Add_Click ()
If MaxID =0 then MaxID =1
If MaxID >8 then Exit Sub
MaxID = MaxID +1
Load optbutton (MaxID)
Opt button (0). Set focus.
Opt button (MaxID). Top = Opt button (MaxID 1). Top + 400
Opt button (MaxID). Caption = Option&MaxID + 1.
End sub
Private Sub delete_Click ()
If MaxID< =1 then exit sub.
Unload opt button (MaxID)
MaxID = MaxID 1
Opt button (0). Set focus.
End Sub
Private Sub optbutton_Click (index as integer)
Picdisplay. Back color = QB color (Index +1)
End Sub
Q15.Explain Scrollbar & Slider controls.
SUBJECT: VB
Page 24 of 121
Ans. The scrollbar & slider controls allow the user to specify a magnitude by scrolling a
selector between its minimum and maximum values. Sometimes, the user doesnt know in
advance the exact value of the quantity to specify. The vertical scroll bar that lets the user move
up & down along a document. The scroll bars are the prime mechanism to view a large image or
text that doesnt fit entirely in a window. While scrolling a long document horizontally or vertically,
the user doesnt have to bother about line numbers or pixels.
The slider control is similar to the scrollbar control but it does not cover a continuous range of
values. The slider control has a fixed number of tick marks, which the developer can label. The
user can place the sliders indicator to the desired value. Scrollbar is used where continuous
value is important and slider control is used where discrete values are required, for example slow,
medium, fast etc. Scrollbar control is a long stripe with an indicator that lets the user select any
value between two ends of the control scrollbar can be of two types horizontal & vertical. The
basic properties of scrollbar control are Min, Max and value. Slider control is similar to the
scrollbar control but there is no continuity but there is some specific range e.g. slow, fast and very
fast. Slider control is not an intrinsic control of VB and we can add it from components dialog box
by selecting Microsoft common controls 6.0.
Q16.Write a program to make a text editor with cut and paste facilities.
Ans. Open a standard EXE project. Place a textbox and place four buttons on it. Name the
command button as cmdcut, cmdquit, cmdpaste and cmdreset. Name the text box as text editor
& add the following code.
DIM store as string
Private Sub cmdcut_click ()
Cuttext=Texteditor.Seltext.
store=Texteditor.Seltext.
Texteditor.Seltext=
Cmdpaste.Enabled=true
Texteditor.Set focus.
End Sub
Private Sub cmdQuit_Click ()
Unload me.
End Sub
Private Sub cmdreset_Click ()
Texteditor. Text=
Texteditor. Set focus
End Sub
Private Sub Text editor_Change()
Cmdcut.Enabled=True
Cmdpaste.Enabled=True
Cmdreset.Enabled=True
End Sub
Private sub cmdpaste_Click()
Texteditor.Seltext=store
Texteditor.Set focus
SUBJECT: VB
Page 25 of 121
End Sub
Q17.Write a program having one command button and on pressing the button it should
display labels & text boxes of Name, age, Roll No, and Address?
Ans.
Private Sub command1_Click()
Dim captions (10) as string
Dim sizes (10) as integer
Caption (1)=Name
Caption (2)=Age
Caption (3)=Roll No.
Caption (4)=Address
Size (1)=20
Size (2)=30
Size (3)=15
Size (4)=40
For I=1to 5
Load labels (I)
Load text boxes (I)
Labels (I).Top=labels (I-1). Top+400
Labels (I).Left=labels (0). Left
Text boxes (I).Top=Text boxes (I-1).Top+450
Text boxes (I).Left=Text boxes (0).Left.
Text boxes (I).Width=Sizes (I) * 60
Labels (I).Caption = Caption (I)
Labels (I).Visible = True
Textboxes (I).Visible = True
Next
End Sub
Q18.Classify the operators in VB.
Ans.Arithmetic operators:
+ Used to add two numbers if it is used with strings then it will concatenate the both strings.
-
less than
SUBJECT: VB
>
Page 26 of 121
greater than
String conciliation
String conciliation -------&
Faster compiler
New Activex data control object
Allows database integration with wide variety of applications
New data report designer.
New package & report designers
Additional Internet capabilities.
SUBJECT: VB
Page 27 of 121
Const pi=3.14
Value of pi is universal so value of pi is constant.
Symbolic or user-defined constants are declared using const keyword.
Q22.Write a program to authenticate user/password pair.
Add a form. Add two text boxes and two labels. Change caption of first label as username as
seconds as password. Name the first textbox as txtusr, and second as txtpass.
Add a command button and make its caption clickme.
Double click on button to write code for click event.
If txtusr = Munish and txtpass= VB6 then Msgbox Successful login
Else
Msgbox Login denied Reenter User name/Password
Txtusr =
Txtpass=
End If
Q23.What do you understand by scope of a variable? Differentiate between global variable and
local variable.
Ans. Scope of a variable depends upon the location where it is declared or which keyword is
used to declare the variable. Scope tells the lifetime of a variable. We can declare variables in
two ways.
1. Global variable: - When the variables are to be declared as global variables then they are
declared in the general section of the program. So that they are accessible within the whole form.
If they are declared with public keyword then they are accessible within the whole project with
form reference. If they are declared with in a module even then they could be called globally
within the project. If these variables are declare with private or dim keyword in the general section
then these variables are accessible with in the specified form only.
2. Local variable: - if the variables are declared with dim statement in any procedure of the form
then they are accessible with in that procedure only. We can declare local variable with public or
private keywords too.
Q24.Write a VB program to implement a calculator that coverts a number given a textbox to its
equivalent Binary Hexadecimal and octal number on the click of respective buttons and display
the result in another textbox.
Ans.
Private Sub Cmdbinary_Click()
Text2.text = ""
n = Text1.text
While n > 0
s = n Mod 2
SUBJECT: VB
Page 28 of 121
SUBJECT: VB
Page 29 of 121
Picture1.FillColor = vbYellow
Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2), 500
Picture1.FillColor = vbRed
Picture1.Circle (Picture1.ScaleHeight / 3 + 130, Picture1.ScaleWidth / 3 + 100), 100
Picture1.Circle (Picture1.ScaleHeight / 3 + 500, Picture1.ScaleWidth / 3 + 100), 100
Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2), 200, 2, 3
End Sub
SUBJECT: VB
Page 30 of 121
are attached with different controls of the form can only define in the run mode. We can define
different types of procedures those are called by the events of the control at runtime.
Q29.List out the mouse pointer properties with at least one pointer example.
Ans. Returns or sets a value indicating the type of mouse pointer displayed when the mouse is
over a particular part of an object at run time.
The settings for value are:
Constant
Value
Description
vbDefault
0
(Default) Shape determined by the object.
vbArrow
1
Arrow.
vbCrosshair
2
Cross (crosshair pointer).
vbIbeam
3
I beam.
vbIconPointer
4
Icon (small square within a square).
VbSizePointer
5
Size(four-pointed arrow pointing north,south,east, west).
vbSizeNESW
6
SizeNESW (double,arrow,pointing,northeast, southwest).
vbSizeNS
7
Size N S (double arrow pointing north and south).
vbSizeNWSE
8
SizeNWSE (double,arrow,pointing,northwest, southeast).
vbSizeWE
9
Size W E (double arrow pointing west and east).
vbUpArrow
10
Up Arrow.
vbHourglass
11
Hourglass (wait).
vbNoDrop
12
No Drop.
vbArrowHourglass
13
Arrow and hourglass.
vbArrowQuestion
14
Arrow and question mark.
vbSizeAll
15
Size all.
vbCustom
99
Custom icon specified by the MouseIcon property.
This example changes the mouse pointer to an hourglass while circles are drawn across the
screen and then changes the hourglass back to a pointer at the end of the procedure. To try this
example, paste the code into the Declarations section of a form. Press F5 to run the program,
and then click the form.
Private Sub Form_Click ()
Dim I .
Screen.MousePointer = vbHourglass
' Set random color and draw circles on form.
For I = 0 To ScaleWidth Step 50
ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255
Circle (I, ScaleHeight * Rnd), 400
Next
' Return mouse pointer to normal. Screen.MousePointer = vbDefault
End Sub
Q30.Explain the following
Image control
Command button control
Ans. 1. Image control: - An Image control can display a graphic from a bitmap, icon, or metafile,
as well as enhanced metafile, JPEG, or GIF files. The Image control uses fewer system
SUBJECT: VB
Page 31 of 121
resources and repaints faster than a PictureBox control, but it supports only a subset of the
PictureBox properties, events, and methods. Use the Stretch property to determine whether the
graphic is scaled to fit the control or vice versa. Although you can place an Image control within a
container, an Image control can't act as a container.
Properties: - there are two main properties of image control. These are
Picture: - In the picture property the image that we want to display on the image control is
specified.
Stretch: - Returns or sets whether the image/ graphics resizes to fit the size of an image control
or not.
2. Command Button: - The easiest way to allow the user to interact with an application is to
provide a button to click. You can use the command button control provided by Visual Basic. Most
Visual Basic applications have command buttons that allow the user to simply click them to
perform actions. When the user chooses the button, it not only carries out the appropriate action,
but it also looks as if it's being pushed in and released. Whenever the user clicks a button, the
Click event procedure is invoked Command button control has the default event click and its
default property is caption.
Q31.Write a short note on Rich Textbox control.
Ans. Rich textbox control is a full-fledged word processor; it provides all the functionality of a
textbox control and gives you capability to mix different fonts, sizes and attributes. You can place
images in your text, on a rich textbox control. Main property of rich textbox control is Text property
& it contains the Text, which is currently being displayed by the control. You can use Rich Textbox
control to specify the texts formatting including paragraph indentation, font, font size & style etc.
The control provides simple properties that turn the selected text to bold, italics, underline & so on.
The two important methods of Rich textbox control are save file that saves the contents of control
on the disk and can load file that loads the contents of file from the disk. Steps to add the Rich
Textbox control:1. Select the Project menu and choose component option.
2. Select the Control tab from the component box.
3. Select the Microsoft Rich Textbox Contol 6.0 item from the list of components.
4. Click on apply and Ok button to add the component.
Place the Rich Textbox Control on the form fromToolbox
Q32.What does docking a window mean? How is docking carried out?
Ans.You can dock controls to the edges of your form or have them fill the control's container
(either a form or a container control). For example, Windows Explorer docks its Tree View control
to the left side of the window and its List View control to the right side of the window. Use the
Dock property for all visible Windows Form controls to define the docking mode.
To dock a control
Select the control that you want to dock.
In the Properties window, click the arrow to the right of the Dock property.
An editor is displayed that shows a series of boxes representing the edges and the center of
the form.
SUBJECT: VB
Page 32 of 121
Click the button that represents the edge of the form where you want to dock the control. To fill
the contents of the control's form or container control, click the center box. Click (none) to disable
docking.
The control is automatically resized to fit the boundaries of the docked edge.
Q33.What are object Properties?
Ans.The Object properties provide general information about objects contained in the Database
window. Applies to Form object, Module object and Report object.
You can view the Object properties, and set the Description or Attributes properties, in the
following ways:
Click an object in the Database window, and then click the Properties button on the Database
toolbar.
Click an object in the Database window, and then click Properties on the View menu.
Right-click an object in the Database window, and then click Properties on the shortcut menu.
Graphical User Interface
Multiple UI
ActiveX Control Provision
Q34.What is Combo Box, Name and describe the three styles of Combo Boxes?
Ans. Combo Box control presents a set of choices that are displayed vertically in a single
column. If the number of items exceeds the value what can be displayed, scroll bars will
automatically appear on the control. A Combo Combine a feature of a Textbox and a List Box.
There are three types of Combo Box Styles.
Dropdown Combo: It appears as only an edit area with a down arrow button at right side. The
user can either select a value from the list or type a value in the edit area
Simple Combo: It displays an edit area with an attached list box always visible immediately
below the edit area. The user can select an item from the list or type an item in the edit box
portion for the combo box.
Dropdown List: It turns the combo box into a drop-down list box. The user could click the down
arrow to view the list. The user can select only one of the list items and cannot type an item in the
edit area.
Q35.What is the Purpose of Toolbar? How does a menu vary from a toolbar?
(v.imp)
Ans.Toolbars are used to provide quick access to the functions that are also available in menus.
Toolbars are even more helpful if they expose functions that are buried under a menu of options
or hidden deep in nested submenus. When you decide to create large applications, be sure to
use of toolbars and menus effectively.
Menus expose many of the underlying functions built into an application that are not
necessarily be observed at first glance. Menu options can be enabled, disabled, checked, and
even popped-up on an object. For example you can create a window list. Which is a menu, that
has an option for each MDI child form within the form.
Toolbar contains normally standard and frequently used options in an application like debug
and Form start options, Form editing options, IDE control option etc.
SUBJECT: VB
Page 33 of 121
SUBJECT: VB
Page 34 of 121
SUBJECT: VB
Page 35 of 121
Ans. Operators are symbols used in an expression to perform operations on the operands.
There are different types of operators in VB. Operators are symbols which effect upon the data.
Operator which work on operands.
Relational operators
< Less than
< = Less than or equal to
> Greater than
> = Greater than or equal to
= To compare equality
<>
Not equal to
SUBJECT: VB
Page 36 of 121
SUBJECT: VB
Page 37 of 121
SUBJECT: VB
Page 38 of 121
4. To place 2 top most items of the combo box in the list control, write the following code
Private Sub Command2_Click()
List1.AddItem (Combo1.List(0))
List1.AddItem (Combo1.List(1))
End Sub
Q46.How Scrollbars are added in the forms in VB?
Ans. Scrollbars are commonly used in windows programming. Using these, the user can select a
Value by postioning the thumb of the scrollbar to desired position.There are two types of
Scrollbar- Horizontal and Vertical Scrollbar.
Private sub form_laod()
Hscroll1.min=1
Hscroll1.max=255
End Sub
Private Sub hscroll1_Change()
Text1.Text=Hscroll1.Value
End Sub
Q47.Write a short note on Procedure and their types.
Ans. Procedure
Visual Basic program can be broke into smaller logical components called procedures.
Procedures are useful for condensing repeated operations such as the frequently used
calculations, text and control manipulation etc. Following are the benefits of using procedures in
programming.
It is easier to debug a program with procedures, which breaks a program into discrete logical
limits.
Procedures used in one program can act as building blocks for other programs with slight
modifications.
Procedures can be Sub, Function or Property Procedure.
Sub procedures
Sub procedures can be placed in standard, class and form modules. Sub procedure is a
procedure that performs a task but doesnt return any value. Each time the procedure is called,
the statements between Sub and End Sub are executed. The syntax for a sub procedure is a
follows.
[Private | Public] Sub procedurename (arglist)
[Statements]
End Sub
arglist is list of argument names separated by commas. Each argument acts like a variable in the
procedure. There are two types Sub Procedures general procedures and event procedures.
SUBJECT: VB
Page 39 of 121
Functions
A Function is a procedure that performs a task and returns a value. Each time the function is
called the statements between Function and End Function are executed. The syntax for a
function is as follows.
Function functionname (arglist)
[Statements]
End Function
Q48.Explain modules and its various types in detail.
Ans. Module is a block of code that performs a specific task and is complete in itself. Modules
can be defined as collection of code that performs a specific task. This code is hidden from rest of
the coding on the form. There are three types of modules in VB.
1. Form Module
2. Standard Module
3. Class Module
1. Form Module: The form that you see on the screen is a representation of the properties that
define its appearance. For each form in an application, there is a related form module that contains
its code and the form module is created in the file with extension .frm.
Each form module contains event procedures which is section of code to response to specific
code. Forms can contain controls & for each control on the form, there is corresponding set of
event procedures in the form module. Form module can contain sub procedure, event procedures
and function procedures. E.g. Form_load() is a event procedure written for each form on the project
if needed and responds when the form is loaded.
2. Code Module/Standard Module: When larger projects are built in VB, then developer wants to
reuse the code as much as possible. For this reason procedures and functions are stored in
separate modules rather than attaching them to forms.
A standard or code module is set of code that you want, to make accessible everywhere in the
project. Standard module has no visual components & is useful for reusing the code. So a module
or standard module has a global scope. Code modules are maintained in a separate folder in
project explorer window and these files are stored with .bas extension on hard disk.
3. Class Module: Class module is used to create objects that can be called from procedures within
your application classes. Standard module contains only code & a class module contains both
code & data. Standard module can never have more than one copy but class module data exists
separately for each instance of the class. Class module helps VB to be an object-oriented
language. For each class module you have to create an object of that class.
The data in a standard module has a program scope i.e. it exists for the life of your program while
class module data for each instance of a class exists only for the lifetime of an object.
Q49.Explain types of dialog boxes.
SUBJECT: VB
Ans.
Page 40 of 121
SUBJECT: VB
Page 41 of 121
SUBJECT: VB
Page 42 of 121
SUBJECT: VB
Page 43 of 121
For I = 0 to 2
Z (I) = Y (I) + Y (I)
Next I
Fun = Z
End function
Q57.What do you understand by file system controls?
Ans. File system controls in visual basic allow the users to select a new drive, to see the
hierarchical directory structure of disk or to see the names of the files in a given directory. For
using these controls you have to write code to take the full advantage of these controls.
There are three main controls named
1. DirList Box
2. DriveList Box
3. FileListBox.
Dirlistbox displays all the directories present in the selected drive of the computers and of any
other drive attached to the computer. File list box displays the files present in the current
directory .We can attach these controls with each other so that when a drive is selected then its
directories should be displayed in the DriveList box and when a directory is selected then all its
files should be displayed in the file list box. File system controls; let you to control the file system
of the computer.
Q58.Describe Menu Editor in VB.(v.imp)
Or
Write the steps to create Menus in VB application.
Ans.Menu editor is used to create new menus and members to add new commands to the
existing menus, to replace the existing menu commands with your own commands and to change
and delete existing menus and members
To display the Menu Editor
From the Tools menu, choose Menu editor
Or
SUBJECT: VB
Page 44 of 121
2.Random access: - Random access also works to retrieve data from ASCII files, but you have
greater flexibility when you use it instead of sequential mode. Random access allows you to
position yourself anywhere within the file at any time to get the data you need.
3.Binary Mode: - Binary mode allows you the greatest amount of flexibility when working with
files. When working with binary access mode, you retrieve data sequentially and in chunks; - the
binary mode. The number of bytes read form the file equals the size of the string, in bytes that
you want to read data into.
Q60.Explain the menu creation through menu editor in visual Basic.
Ans.1. To design menu, click on the tools menu and then select Menu editor. Menu editor dialog
box will appear.
2. Enter caption property and Name property in the first two boxes of menu editor.
3. You can also choose a short cut key for the current menu control.
4. The left and right arrow buttons are for indenting and out denting menu controls. A menu title
must be flush with the left margin of the menu list box at the bottom. A menu item is usually
indented once. You would indent a second time to create a submenu item (cascading menu) from
the previous menu item.
The up and down arrow buttons are for changing the order in which menu titles and menu items
appear.
5. You can type a number in the index field to make the menu control array. These are useful
when you want to list like ones you see at bottom of file menu in various applications.
The help control ID field is used to link the help menu to a help file through a unique identifies
called help context.
Finally the Negotiate Position field is used to determine where a top-level menu would be
positioned when an MDI child form is maximized and both forms must share the menu bar of MDI
parent form.
Q61.Explain the tasks involved in debugging the visual basic application.
Ans.Debugging is a process by which errors are identified and resolved in source code. Typically,
debugging is conducted at various levels. These levels are termed as-Level1 debugging, level2
debugging, and level3 debugging.
Level1 debugging: The first level of debugging is the implementation of a debugging procedure
and the necessary tuning to make it operate as expected.
Logical errors occur when the application does not perform as intended and produces incorrect
results. When a programmer sets to write a procedure, he/she would have in mind only the
expected output of that procedure. As the developer goes about writing the procedure, he/she
finds a better method that solves many more constraints, thereby working better in the worst of
circumstances also. This fine-tuning and developing of code functionality in such a way that the
program runs efficiently in called level1 debugging.
SUBJECT: VB
Page 45 of 121
Level2 debugging: Second level debugging is the activity required to make a functional unit of
code interact according to plan with other units of code, typically before shipping or deploying the
completed project. Generally this condition arises when the users procedure does not run
properly in a test case.
Level3. Debugging: Level3 debugging is primarily the diagnosis and repair of problems
occurring in applications that have already been deployed. These bugs are often the most difficult
to locate because they occur on a remote machine. They may be the result of unanticipated
circumstances. These may be one of the following:
User actions
Program configuration
System configuration
Q62.Explain the function and use of Err Object.
Ans. ErrObject is a class in VB to handle errors. It has number of properties and functions.
1. Clear: - This method is uesd to clear all the property settings of the error object.
2. Description: - Return or sets the string expression with a descriptive string associated with the
error objects.
3. HelpContext: - Return or sets a context ID for a topic in a help file.
4. Helpfile: - Return or sets the fully qualified path for help file.
5. Last DLL error: - Returns the system error code by call to DLL.
6. Number: - Returns or set a numeric value representing an error.
7. Raise: - This function will generate an error at runtime.
8. Source: - Returns or sets the name of the object that has originated the error
Q63.Write a VB program that takes a number from the user with an input box and which will
displays its multiplication table in the immediate window.
Ans.
Dim n As Integer
Dim I as integer
Dim c as integer
c=0
n = Input Box("enter number")
For i = 1 To 10
c=n*i
Debug. Print n, "*", i, "=", c
Next
Q64.What modality is and how does it affect the behavior of your dialog boxes?
Ans. Modality means whether the dialog box will give its control to the next dialog box or form
without being closed or unloaded. There are two types of dialog boxes.
1. Modal: - if the dialog box is of modal type then the control will not be transferred to their parent
form until the necessary information has been given to the dialog box or it has been closed. E.g.
of these dialog boxes are msgbox, inputbox in VB.
SUBJECT: VB
Page 46 of 121
2. Modeless: - if the dialog box are modeless type then the control can be transferred to the
parent form without closing the dialog box. E.g. of this type of dialog box is find & replace dialog
box.
Q65.What do you understand by bug (error)? What are the different types of bugs that you
may encounter while programming with visual basic?
OR
Q66.What are the common errors in the visual basic?
(v.imp)
Ans. Bugs are the errors. Bugs appear in the VB application at different situation and can
terminate the VB application abruptly. Some bugs will not terminate the application but will insist
the produce to produce the wrong result. All these bugs are divided to the following categories.
Syntax bugs(errors): These errors occur when we enter an incorrect line of code. Such as a
mistake in typing a keyword, a punctuation is missing or an incorrectly spelled variable.
Runtime bugs(errors): These occur when a command attempts to perform an action that is not
valid. For example, a runtime error occurs if we try to assign a string to a numeric variable. Error
handler executes only if a run-time errors encounters.
Logical bugs(errors): Occurs when an application executes without syntax error or run-time
errors, but the results are not what we intend or correct. For example, an application might
prompt the user for a password but then may not allow access to the application even if the
password is correct.
Q67.Write a program that verifies the order in which the events occur for the user control.
Use debug. print statement to display the name of each event as it occurs.
Ans. Using the following code we can find the order of the occurrence of events in the user
control and we can print the message on the debug window.
Private Sub UserControl_Initialize()
MsgBox "inalizining event"
Debug.Print "inalizining event"
End Sub
Private Sub UserControl_Paint()
MsgBox "painting event"
Debug.Print "painting event"
End Sub
Private Sub UserControl_Resize()
MsgBox "resize event"
Debug.Print "resize event"
End Sub
Private Sub UserControl_Terminate()
MsgBox "terminate event"
Debug.Print "terminate event"
End Sub
SUBJECT: VB
Page 47 of 121
Or
Ans. Visual Basic provides a great deal of flexibility, allowing you to configure the working
environment, which best suits, your individual style. You can choose between a single or multiple
document interface and you can adjust the size and positioning of the various Integrated
Development Environment (IDE) elements. Your layout will persist between sessions of Visual
Basic.
SDI or MDI Interface
Two different styles are available for the Visual Basic IDE:
Single document interface (SDI) or multiple document interface (MDI). With the SDI option,
all of the IDE windows are free to be moved anywhere on screen; as long as Visual Basic is the
current application, they will remain on top of any other applications. With the MDI option, all of
SUBJECT: VB
Page 48 of 121
the IDE windows are contained within a single resizable parent window. Any single document
interface can be converted into a multiple document interface by setting the value of the
MDICHILD property of a form as true.
e.g. in Vb project the following form is created to perform calculate the sum of two numbers. And
another form shows the welcome message. After inserting an MDI form in the project. We can
convert these SDI form into the MDI with the help of MDICHILD properties of these forms
Single Document Interface First Form
set firstform.mdichild=true
set secondform.mdichild=true
to change this interface to multiple document interface.
Q71.Explain in detail the On Error and the Resume Next statement.
Ans.Enables an error-handling routine and specifies the location of the routine within a
procedure; can also be used to disable an error-handling routine. Without an On Error statement,
any run-time error that occurs is fatal: an error message is displayed, and execution stops.
Syntax: On Error { GoTo [ line | 0 | -1 ] | Resume Next }
GoTo line : - Enables the error-handling routine that starts at the line specified in the required
line argument. The line argument is any line label or line number. If a run-time error occurs,
control branches to the specified line, making the error handler active. The specified line must be
in the same procedure as the On Error statement, or a compile-time error will occur.
SUBJECT: VB
Page 49 of 121
GoTo 0 : - Disables enabled error handler in the current procedure and resets it to nothing.
GoTo -1 : - Disables enabled exception in the current procedure and resets it to nothing.
Resume Next
Specifies that when a run-time error occurs, control goes to the statement immediately following
the statement where the error has occurred and the execution continues from that point. Use this
statement rather than On Error or Go To statements while accessing objects.
Q72.Explain break mode.
Or
Why we need to set break point in VB? Give code for the same.
Ans.It halts the operation of an application and gives a snapshot of its condition at any instant, as
the program is still active; only its execution is temporarily suspended. All variables retain their
values properties and statements. In this mode you can modify an applications code, or can
observe the applications interface condition or you can also determine the active procedures that
have been called or you can even change the program flow.
If visual Basic encounters any of the below mentioned statements, then it enters into the Break
Mode.
Breaks point
Stop statement
Break mode can be entered manually in several ways.
1. Press ctrl + Break
2. Select the Break button on the toolbar
3. Press F5 while your program is running.
Q73.Compare standard and MDI programs.
Ans. Standard and MDI form both are the part of vb application. Normally standard forms are
provided in simple applications and MDI form is used to manage all standard forms under a
single form. All the control commands like menu and toolbars are available on the MDI form.
A standard form can be distinguished from a MDI form on the basis of the following differences.
STANDARD FORM
MDI FORM
In a single project there are number of Only single MDI form is in the single project
standard forms
Standard form can become the child of MDI No MDI FORM could be the child of standard
FORM
form
We can place any type of control on the On MDI form only menus, toolbar and
standard form
runtime-hidden control are place able. Like
timer control, common dialog control etc.
To arrange the standard form there is no MDI form can arrange its child forms in
property and method
cascade and tiled style with arrange method.
Q74.What are three phases of component based system design?
Ans. In Component based system design component is created and coded to execute result
on the specific action on the component.
SUBJECT: VB
Page 50 of 121
Design Phase
Code Phase
Debugging
SUBJECT: VB
Page 51 of 121
Dim I As Integer
CM = 0
CL = 0
For I = 0 To 39
MARKS(I) = InputBox("ENTER MARKS OF " & I + 1 & "STUDENT")
Next
For I = 0 To 39
If MARKS(I) > 60 Then
CM = CM + 1
End If
If MARKS(I) < 33 Then
CL = CL + 1
End If
Next
MsgBox ("No of students having marks less than 33 :" & CL & vbCrLf & "number of students
having marks more than 60 : " & CM)
End Sub
Q77.What is a break expression? What is the difference between watch expression and break
expression?
Ans. Break Expression :- A break expression works as a marker in the code that tells visual
basic to suspend the program execution. By setting the breakpoints at a place make it easy to
investigate which line has suspended the program execution. Break expressions are temporary
and not preserved in the code.
Watch Expression : - Visual basic automatically monitor the watch expression that you define.
When the application enters break mode, these watch expressions appears in the watch window,
where you can observe their values. You can also direct watch expression to put application into
break mode whenever the expressions value changes or equal to specific value.
Difference between break expression and watch Expression
Break expression
Watch expression
It cab be added using toggle break point It can be added using add watch option of the
option of the debug menu
debug menu
It halts the execution of an application and It is monitored automatically by the visual basic
gives a snapshot to its condition at any
instant as the program is still active
In break expression we can check code Watch expression is added into the watch
using different debug tools
window and it force the form to enter in a break
mode where we can watch the current result of
the expression.
Q78.Use the common Dialog Control to create an application that asks user for a file to open and
then open that file in NOTEPAD.
Ans. Following steps are used to open a file in richtextbox.
1. Place an activex control richtextbox on the form.
2. Place a common dialog control on the form.
SUBJECT: VB
Page 52 of 121
3. Place a button on the form and do the following code on the button.
Private sub command1_click()
Commondialog1.filter=TextFiles |*.txt
Commondialog1.showopen
Richtextbox1.loadfile commondialog1.filename
End sub
To open the same file in notepad select run option from the start menu then write NOTEPAD in
the text box click on ok.. Now select open option from the file menu and open the same file.
Q79.What kinds of tools are available for aid in the debugging of vb application? Explain each in
brief.(v.imp)
Ans. There are different kinds of debugging tools provided by vb to the vb program error free.
These tools are.
The Immediate Window: Most programming languages have a way to test program statements
procedures and functions visual Basic users the immediate window for the testing purpose you
can use the immediate window to test statements or to perform quick calculations when you are
in break mode. If you type Print 2+2 in the immediate window and press enter, visual basic
quickly responds with a 4.
The Debug Object: You can also add lines of code to your program that will print values directly
to the immediate window. For this you can use a predefined visual basic object called debug.
E.g.Debug.Print variable
Debug.Print expression
Watch Window: In debugging terms, a watch is a variable or object that is specifically monitored
or watched in real-time as the program executes. You can view the properties of watches in the
watch window. The watch window can be called up by pressing the watch window button or by
adding a watch to the window.
Call Stack::- Call stack tool of vb provides the detail information of parent form , and about the
current position of the break control in forms debug process.
Step Into: Step into tool is used to find the logical errors and check the whole code by executing
statements line by line including all the functions and subroutine involved in the process.
Step out: Step out tool only provide the result of the subroutine or function in debug mode.
Step Over: Step over tool too execute the code line by line but excluding the procedures or
subroutines being called by the current event. It only shows the result of the called subroutines or
functions and then move to the next statement present in the current event or procedure.
Q80.Write a short note on dynamic array.
Ans.There will be a situation when the user may not know the exact size of the array at design
time. Under such circumstances, a dynamic array can be initially declared and later the user can
add elements when required instead of declaring the size of the array at design time.
Dim New Array ( )
The actual number of elements can be allocated using a ReDim statement. This example
allocates the number of elements in the array based on the value of the variable, Y.
SUBJECT: VB
Page 53 of 121
SUBJECT: VB
Page 54 of 121
2. Existing Visual Basic Control : - The simplest of custom ActiveX control is one that is based
on an existing control. The user can keep most or all of the original control's functionality and then
add custom members.
For example, when the style property of the Combo Box is set to 0 (Dropdown) or 1 (Simple
Combo), the user can enter a new field value in the edit box of the control, but the new entry is
not appended to the list of available choices. It can be enhanced by enrapturing the Enter key.
When the user presses Enter, add the entry in the Edit box to the list of options. This can result in
the development of a new control, say Enhanced Combo.
3. Constituent Control : - In cases where most of the functionality we want to include in our
custom control already exits, a new control can be designed that include existing control. The
control that form part of the newly developed custom control is called constituent control.
Q83.Differentiate between ActiveX EXE and Active X DLL.
Ans. Servers can be implemented as ActiveX DLL or Active X EXE components. The difference
lies in how the server is executed. An ActiveX DLL is an in-process server. The DLL is loaded in
the same address space as the client executable that calls the server and it runs on the same
thread as the client. At any given moment however, the client application or the DLL is running.
The merits of DLL are that they are faster, they become part of the application that uses them.
An ActiveX EXE otherwise called as an out-of-process server, as the name indicates runs as
a separate process. When a client application creates an object provided by an EXE server for
the first time, the server starts running as a separate process. If another client application creates
the same object, the running EXE server provides this object. In other words, a single EXE server
can service multiple clients. Out-of-process servers seem to be more efficient in terms of
resource allocation, but exchanging information between servers is a slow process.
Q84.Define the following.
Ans.Visual basic provides a variety of options to access remoter Client\Server database. They
are
Data Access Objects (DAO) It communicates with data sources through the JET database
engine.
Data Control : It binds data controls to Microsoft Access and other ODBC data sources.
ODBC Direct: It allows accessing of ODBC data sources through the RDO with DAO object,
bypassing the JET database engine.
Remote Data Object : (RDO): It provides a framework for using code to create and
manipulate components of a remote ODBC database system.
Remote Data Control (RDC) It binds the controls to an ODBC remote database.
Open Database Connectivity (ODBC) : This is an API call interface to the open Data
Connectivity libraries and drivers to provide data access to Oracle and other databases that
provide data access to Oracle and other databases that provide an ODBC driver.
Visual Basic Library for SQL Server (VBSQL) : It is an implementation of the DB library API
is specifically designed to provide access to an SQL server through a visual Basic Application.
SUBJECT: VB
Page 55 of 121
Active Data Object (ADO) : This is a programming model that eliminates the need to choose
from DAO (Data Access Object) and RDO (Remote Data Object) and all other data access
methods. It is designed to provide a common bridge between different database, file system and
e-mail servers.
Q85.Write a code in Visual Basic to Search a Record in Database.
Ans.
Object
Properties
Setting
Data
Name DatabaseName
c:\vb\student.mbd
Recordsource Student
Private Sub Command1_click ()
Data1.Record.FindFirst (Sname= &DBcontrol.text & )
Text1.Text=Data1.Recordset.fields(5)
Data1.Refresh
End Sub
Q86.Write a code in Visual Basic to update a record in Database.
Ans.
Object
Command button 1
Properties
Name
Caption
Command button 2
Name
Caption
Command button 3
Caption
Data
Name
DatabaseName
Record source
The following code entered in the Command button1 click
Private Sub Command1_click()
Msgbox You are now modify the Current Record
Data1.Recordset.Edit
Text1.Enable= False
Text2.Enable=False
End Sub
Enter the following code in the Command buton2 click
Private sub Command2_click()
Data1.Recordset (2) = Text3.Text
Data1.Recordset (3) = Val (Text4.Text)
Data1.Recordset.Update
Msgbox Record Update in file
Data1.refresh
End Sub
Setting
Command 1
Modify
Command 2
Update
Exit
Data1
c:\vb\Supplier.mbd
Supplier
SUBJECT: VB
Page 56 of 121
SUBJECT: VB
Page 57 of 121
Ans. Microsoft masked edit control is used for input validations in a text box. It looks like an
ordinary text box. You can restrict the characters entered without having to write code in the key
events. Most important property is mask property. This property controls what the user can enter.
The event dealing with input to Masked edit box is Validation Error event. This event is fired
whenever user tries to enter invalid character.
SUBJECT: VB
Page 58 of 121
approach is to create a recordset object, associate a command object with it and retrieve the
desired records.
3.Recordset: - This object stores the results produced on the execution of command object in a
database. Recordsets can be created without an explicit connection. To access the fields of a
recordset object, we can use fields collection.
Q92.Explain in process & out of process servers.
Ans. A class module is server, or an application that provides its services to client applications.
When we create an object variable to access the properties and methods of a class, we involve
an executable file, which runs in the background & waits to be contacted. Whenever we set or
read a property value or call a method, this executable file performs some actions and return
results to your application. Servers can be implemented as ActiveX EXE or ActiveX DLL
components. The difference is how they are executed.
An ActiveX DLL is called in process server. The DLL is loaded in the same address space as
the executable that calls the server. At any point either an application or a DLL is running. A DLL
is faster and becomes part of the application that uses it.
An ActiveX EXE is an out-of-process server and runs as separate process. When an
application creates an object provided by an EXE the server starts running as a separate
process. If another application creates a same object, the new object is provided by the already
running EXE. So a single EXE provides services to multiple applications. Example of out-ofprocess server is Excel. You can run two or more applications that requests services of excel and
it will be serviced by a single instance of excel.
Q93.Explain ADO data control.
Ans. Earlier there were DAO (Data Access Object) & RDO (Remote Data Object) controls which
were used to access the databases but these were not sufficient for more advanced databases like
Oracle, SQLServer etc. One of the new controls added to Visual Basic is Active Data Control or
ADO data Control. With ADO data control, We can connect to more databases of different types.
The simplest way to use ADO in your projects is to add ADO in the project & use it on the form just
like we use DAO. We can add ADO data control from the components. From the project menu,
select components & from the components check Microsoft ADO control 6.0 (`) option. ADO control
will be displayed in the toolbox of VB.
ADO data control has various properties. Place the control on the form & right click it to open
property pages of ADO control. We now have to specify the name of the data source i.e. name of
the database that ADO data control will connect.
There are three types of data sources:
1. File Data source: A database file that all user on the machine can access.
2. User Data source: A database file that a specified user can access.
3. System Data source: A database file that any user that can log on to the machine can access.
SUBJECT: VB
Page 59 of 121
When ADO data control is placed & data source is specified we can bind various other controls like
textboxes, list boxes, combo boxes etc. to ADO data control by specifying data source and data
member properties. This is why ADO data control is very effective tool for connecting to databases.
Q94.What are ActiveX Controls define it and explain any two applications of ActiveX
controls?
Ans. ActiveX is a set of reusable components that can be created and utilized by several
applications. ActiveX uses the internet technology to assist in creating compact and reusable
applications that can be deployed via internet or a corporate intranet.ActiveX provides a familiar
client server infrastructure to run your applications. Controls like coolbar, flatscrollbar, imageCombo
are ActiveX controls. ActiveX control can also be used in other ActiveX compliant programs. These
can be embedded and distributed through HTML web pages.
Image List Control: While working with toolbar & coolbar each button is assigned an image and
image list works behind the scene. It is not visible at run time and gives a way to store a group of
images in a single place. The key to work with an Image List control is ListImage object and
ListImages collection. The ListImages collection specifies the images stored. The main properties
of Image List control are its custom properties and are shown as dialog box. You can set pictures in
the ImageList control at design time and use their index to refer them. The Image tab on this dialog
box gives a convenient way to add images at design time.
To use image from imagelist control we can write
Set Picture1.picture=ImageList1.ListImage(1).Picture
Toolbar Control: It is one of the most important tools for providing an easy interface to the users.
The toolbar control provides easy access to options available in your application. To add design
time properties to the controls select its custom properties from the property windows.
A toolbar control contains a collection of Buttons objects used to create toolbar. A toolbar contains
buttons that correspond to items in an applications menu, providing a graphical interface for the
user to access an applications most frequently used functions and operations. You can even add
an Image in a button and Image list control is required on the same form, to add images in the
toolbar at design time. You can add buttons at design time in the toolbar using its property pages.
The custom property page has three tabs, General, Buttons and Picture. In the buttons tab you
can add more buttons to the toolbar.
Q95.Write a program in VB to find the student standing second in a class.
Ans.Public Type Student
Name As String
Marks As Double
End type
DIM S (10) as Student
SUBJECT: VB
Page 60 of 121
SUBJECT: VB
Page 61 of 121
SUBJECT: VB
Page 62 of 121
e.g
msgbox rs(0)
or
msgbox rs.fields(Name)
Q99.Explain in detail the difference between tables, dynasets and snapshots.
Ans. Table:- the table is only one of the potentially many components that will actually make up a
database. Tables are the starting point of any database, and they are where the data is stored.
Without a minimum of one table, a database would contain no data and be totally meaningless.
Dynaset :- Dynaset means dynamic set of records . the data in a dynaset does not actually existit is extracted from the underlying table or tables and only the criterias are saved. There are some
restrictions on editing in a dynaset.You may not be able to edit data if it threatens referential
integrity between more than one table or master and client table..
Snapshot :- The snapshot type recordset can refer to any table, attached table or query. A
snapshot cannot be update and does not reflect any change made by users.
Q100. What is the difference between List View and Tree View? Explain with example.
Ans. Tree View :- The Tree View control provides a hierarchical view of folders or other items
that can be neatly categorized in a tree- style layout. It is often used in conjunction with a List
View control, which is used to display the contents of the folder selected in the Tree View. This is
the ActiveX control, which is available in common window control.
Main properties of Tree View
Name, ImageList, Indentation OLEDragMode, OLEDropMode, LineStyle, Scroll etc
List View :- List View control provides a detailed view of the items appear in the specified folder
that we select in the tree view. Normally this is used in conjunction with a tree view. But we
can use it separately too. Any selected item can execute. This is also one of the ActiveX
control and is available in Common window controls.
Main Properties of List View
Arrange , SelectedItem ,Name, LabelEdit, LabelWrap, Listitems, view , GridLines etc.
Q101. Explain in detail steps needed to modify the data in a database record.
Or
How will you update Records sequentially through Visual Basic?
Ans. Suppose we have a table in Microsoft access called student.mdb and we want to modify
the record then we have to perform the following steps.
1.Include reference of ADODB library
2. initialize connection and recordset using following commands in general section
dim cn as new ADODB.connection
dim rs as new ADODB.recordset
3.open connection and recordset objects on the form activate them by using following command
cn.open provider=Microsoft.Jet.Oledb.4.0;Data source= &app.path &\student.mdb
rs.open select * from student,cn,adopendynamic, adopenlocopticmistic
4.create a find button to find the record to update and for this write following codeprivate sub cmdfind_click()
dim rno as integer
SUBJECT: VB
Page 63 of 121
SUBJECT: VB
Page 64 of 121
SUBJECT: VB
Page 65 of 121
rs.Close
End Sub
2. Performing a Parameter-Driven Stored Procedure:- it's possible to build your own ADODB
Parameters collection. In this case, youre performing a simple two-argument SP,
"AuthorByYearBorn", that returns a small resultset
Private Sub RunSPButton_Click()
Dim Qy As New ADODB.Command
Dim Parm As New ADODB.Parameter
Dim Parm2 As New ADODB.Parameter
Set Qy.ActiveConnection = cn
Qy(0)="1947"
Qy(1)="1948"
Qy.CommandType = adCmdStoredProc
Qy.CommandText = "AuthorByYearBorn"
Set rs = Qy.Execute(ShowRows)
ADOGrid1.ShowData rs
End Sub
Q106. Explain the following
(a)Opening a table for exclusive use
(b)DataGrid Controls
Ans. (a) The value of this property, along with the DatabaseName, ReadOnly, and Connect
properties, is used to open a database. In the Professional and Enterprise Editions, this property
corresponds to the exclusive argument in the OpenDatabase method.
The Exclusive property is used only while opening the Database. If you change the value of
this property at run time, you must use the Refresh method for the change to take effect. If
someone else already has the database open, you can't open it for exclusive use and a trappable
error results.
Database operations are faster if the database is opened for exclusive use.
After you open a database for exclusive use, your application can have as many instances
open as necessary. However, other applications running on your system are not permitted to
open the database.
(b) Data Grid Controls: - The data-aware DataGrid control appears similar to the Grid control;
however, you can set the DataGrid control's DataSource property to a Data control so that the
control is automatically filled and its column headers set automatically from a Data control's
Recordset object. The DataGrid control is really a fixed collection of columns, each with an
indeterminate number of rows.
Each cell of a DataGrid control can hold text values, but not linked or embedded objects. You
can specify the current cell in code, or the user can change it at run time using the mouse or the
arrow keys. Cells can be edited interactively, by typing into the cell, or programmatically. Cells
can be selected individually or by row.
If a cell's text is too long to be displayed in the cell, the text wraps to the next line within the
same cell. To display the wrapped text, you must increase the cell's Column object's Width
property and/or the DataGrid control's RowHeight property. At design time, you can change the
SUBJECT: VB
Page 66 of 121
column width interactively by resizing the column or by changing the column's width in the
Column object's property page.
Use the DataGrid control's Columns collection's Count property and the Recordset object's
RecordCount property to determine the number of columns and rows in the control. A DataGrid
control can have as many rows as the system resources can support and up to 32767 columns.
When you select a cell, the ColIndex property is set, thus selecting one of the Column objects
in the DataGrid object's Columns collection. The Text and Value properties of the Column object
reference the contents of the current cell. The data in the current row can be accessed using the
Bookmark property, which provides access to the underlying Recordset object's record. Each
column of the DataGrid control has its own font, border, word wrap, and other attributes that can
be set without regard to other columns. At design time, you can set the column width and row
height and establish columns that are not visible to the user. You can also prevent users from
changing the formatting at run time.
Q107. Explain the following
(a) Web Based deployment
(b) Packaging the Applications
Ans. (a):- These are the steps in deploying your web base application to the Internet:
1.Debug and compile your application.
2.Use the Package and Deployment Wizard to build a .cab file that contains the necessary files
for your application.
3.Digitally sign your .cab file and rebuild.
4.Use the Package and Deployment Wizard to deploy your application to the Web server you
want to use.
5.Manually copy any files associated with your applications HTML pages, such as images, to the
necessary location on your Web server.
6.Test the pages in your application to make sure that all the links to associated files still work. If
not, you may have to adjust the location of your files on the Web server to match the URLs in the
HTML pages.
(b) Packaging the Application
Using the Package and Deployment Wizard, you can easily create a professional setup program
for your application or deploy an Internet application to the Web. The wizard performs these steps
during the packaging process:
Automatic inclusion of your application's main setup program (setup1.exe). The wizard
adds the Setup Toolkit application, Setup1.exe, to the package. This file is the main installation
program for your application.
Automatic creation of your application's .cab files. The Package and Deployment Wizard
can create a single .cab file or multiple .cab files for your application.
Script-based sessions. You can select a script from another packaging session with the same
project if you want to use the same or very similar settings as you move through the wizard. This
can save you significant time.
Optional creation of dependency files. Dependency files identify the run-time files that must
be included with your application when it is distributed.
SUBJECT: VB
Page 67 of 121
Automatic support for data access, Remote Automation, and DCOM features. The wizard
automatically determines whether your project includes functionality that changes the setup
process. For example, if you include certain types of data access, Remote Automation, or DCOM
features, you may need to include drivers or other files in your package. The wizard checks your
projects and displays screens that allow you to specify the appropriate options in these cases.
Shared file capability. The wizard allows you to install some files as shared files. This means
that the files will not be removed from the system during an uninstall if other applications are
using them.
Alternate file locations for Internet packages. In Internet packages, the wizard allows you to
specify whether dependency files should be included in the setup program or downloaded from
an alternate Web site.
Safety settings for Internet packages. If you do not use the IObjectSafety interface in your
project, the Package and Deployment Wizard lets you mark components in your application as
safe.
Custom destination locations for each file in the project. Most files have a default location
to which they are installed, depending on whether they are project files or system files. You can
change these locations if you want to install the files to a different location.
Q108. How can you create your own object?
(b) What are the data bound Control.
Ans. (a) Class modules (.CLS file name extension) are the foundation of object-oriented
programming in Visual Basic. You can write code in class modules to create new objects. These
new objects can include your own customized properties and methods. Actually, forms are just
class modules that can have controls placed on them and can display form windows. Following
steps are applied to create new object.
Add class module from the project menu in your project
1. Define variable as private and procedure as public so that they are accessible out side
2. save the class module and refer in the form procedure by specifying the following statements.
Dim objectname as new classname
Or
Dim objectname as classname
Set objectname=classname
(b) Data bound Control:- Visual Basic allows you to mark properties of your control as bindable,
allowing you to create data-aware controls. A developer can associate bindable properties with
fields in any data source, making it easier to use your control in database applications.
The controls supplied with Visual Basic can be bound to data source fields using their
DataSource and DataField properties: - You can select one property of your control to be bound
to the DataField property. Typically, this will be the most important piece of data your control
holds.
Although you can mark only one field as bound to the field specified in the DataField property,
you can mark additional properties of your ActiveX control as bindable. Developers can use the
DataBindings collection to bind these additional bindable properties to data fields.
SUBJECT: VB
Page 68 of 121
SUBJECT: VB
Page 69 of 121
SUBJECT: VB
Page 70 of 121
Pass data field values to data-bound controls, where you can display or change the values.
Add new records or update a database based on any changes you make to data displayed in
the bound controls.
Q115.Write different VB procedures to navigate and update a database file.
Ans. There are different types of procedures provided by vb. These are as under
1.movefirst :- The procedure used to move the cursor in recordset at the beginning.
General syntax to use this method is
Recordset.movefirst
2.movelast :- use to shift the cursor at the last record in recordset.
General syntax to use this method is
Recordset.movelast
3.moveprevious :- shift the cursor to the previous record in the recordset.
General syntax to use this method is
Recordset.moveprevious
4.movenext: - shift the cursor to next record in the recordset.
General syntax to use this method is
Recordset.movenext
Q116.Write the DAO object hierarchy.
Ans. DAO stands for Data Access Object. DAO objects enable you to access and manipulate
data programmatically in local and remote databases. You use DAO to manage databases with
the help of their structures.
DAO objects hierarchy consist of the following structure.
1. Workspace object defines a session for the user. When your application starts, the Jet engine
creates a default workspace object. You can open additional workspaces if required and each
workspace has a userID and a password associated with it.
The set statement is used to assign a database to be open by a database object.
Eg.
Dim db as database
Set db=opendatabase(xyz.mdb)
2.Recodset :- A Recordset Object cotains a set of records from the database. You must create
the recordset by declaring a variable for the recordset object and then assigning it to the table as.
dim rs as recordset
set rs=db.openRecordset(employee,dbOpenTable)
The type of recordset can be either dbOpenTable or dbOpenDynaset or dbOpenSnapshot.
There are no bound controls for the DAO objects and so you have to copy data from a recordset
to a textbox one by one.
Q117.Write the steps to create an ActiveX Control for clock that exposes startclock() and
Stopclock() methods.
Ans. Following steps are used to create an ActiveX Control for clock
1. select ActiveX control project from the new project Dialogbox
SUBJECT: VB
Page 71 of 121
SUBJECT: VB
Page 72 of 121
in a programming to perform functions such as manipulating strings and numbers. These are
categorized into following categories:
Numeric Functions
String functions
Date and Time functions
Examples are:
Abs(argument):- returns absolute value of the argument
Sqr(argument):- Returns Square root of the argument.
Len(argument):- Returns the total number of characters that are required to store the argument.
UCase(argument):- Returns all characters of the argument in upper case.
Q120. What is With Block used for?.
Ans. You can assign properties to various components such as forms, control buttons and text
boxes, using two methods. These methods are using the properties window or by using VB
programming language. The With Block feature enables you to assign various properties to a
component without repeating the component name again and again
Example
Private sub command1_click()
with text1
.text=hello
.left=10
.top=100
.fontsize=16
end with
end sub
Q121. What do we call a Scroll Bar?
Ans. The scroll bars are used to view a large image or text that doesnt fit entirely in a window.
While scrolling a long document horizontally or vertically, the user doesnt have to bother about
line numbers or pixels. Visual Basic provides two types of Scrollbars, horizontal scrollbar and
vertical scrollbar. The horizontal scrollbar controls the position in horizontal direction and vertical
scrollbar control the position in vertical direction and you can move up and down using vertical
scrollbar.
Q122. Give any two examples of methods that can be added to a class module?
Ans. A class is a self-sufficient piece of code, which means you can move the class from one
project to another and it should, work properly without any modification. A class contains
properties and methods that all work together to perform a set of related operations. Object is an
instance of a class, which is used to access the members of class.
Methods: - Adding method to a class is just like adding procedure to a class module. You
can prefix the method name with Private or Public, depending on the scope of method.
Examples:
Enter the following code in the Code Window
SUBJECT: VB
Page 73 of 121
SUBJECT: VB
Page 74 of 121
Q129. Give an Example where searching and Sorting both are involved.
Ans. Sorting is a technique that is used to arrange data value in a specific order. Searching is a
technique that is used to find out a specific data value from the recordset entries.
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
rs.MoveFirst
rs.Find "empno=" & Text1.Text
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
End Sub
Private Sub Command2_Click()
rs.Sort = "ename ASC"
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
End Sub
Private Sub Form_Load()
rs.CursorLocation = adUseClient
cn.Open "provider=microsoft.jet.oledb.4.0; data source=f:\database.mdb"
rs.Open "emp", cn, adOpenDynamic, adLockOptimistic
End Sub
Q130. Give an Example where sorting is must?
Ans. Sorting is a technique that is used to arrange data value in a specific order. Sorting is
applicable, where we have large numbers of records and they must be processed fast in order to
get optimized Result. And we need to search information from these records frequently.
SUBJECT: VB
Page 75 of 121
SUBJECT: VB
Page 76 of 121
SUBJECT: VB
Page 77 of 121
SUBJECT: VB
Page 78 of 121
Select case testexprerssion [case expression list-n[statements-n]] End select : executes one of
the several groups of statements depending on the value of an expression.
Example:- IF then else Statement
Private Sub Form_Load()
Dim x, y As Integer
x = 10
y = 10
If x <> y Then
MsgBox " Both values are not equal"
Else
MsgBox " Both values are equal"
End If
End sub
Example:- Select case end Select statament
Private Sub Form_Load()
Dim sp As Integer
sp = 19
Select Case sp
Case Is <= 18
MsgBox "you are in juniors"
Case Is <= 50
MsgBox "you are in Seniors"
Case Else
MsgBox "you are in Olders"
End Select
End Sub
Q143. Write a Visual Basic code to accept a string only in lower case and display it by
changing its alternate characters to upper case?.
Ans. Open a new Project and Add a Label control with Caption as Enter your Name
Add a Text Control and a Command button
Then Write the coding as below in Code window
Private Sub Command1_Click()
MsgBox "You have entered String is" & UCase(Text1.Text)
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Form1.BackColor = vbGreen
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 65 And KeyAscii <= 91 Then
MsgBox "Only lowercase are allowed"
KeyAscii = 0
End If
End Sub
SUBJECT: VB
Page 79 of 121
Q144. What are the basic Object Oriented Principles and features ?.
Ans. The Object Oriented principles are the principles provided with the object-oriented
programming concept. The object-oriented programming concept or approach involves grouping
of data ad functions into modular entities known as a class. Classes are user-defined data types
that contain data and functions and to initiate a class, you need to create an object of the class.
You can access the data and methods of the classes by using this object only. You can create
any number of objects in a class. The various object-oriented principles such as encapsulation
and inheritance provide security to your data and allow the reuse of objects in a new application.
Various object oriented principles are:
Encapsulation: - Refers to the data hiding. Encapsulation wraps data and methods into a
single entity called class. This principle does not permit any outside programming to
directly access and manipulate the wrapped data and methods. To access data you need
to create an object of the class, which allows you to access the wrapped methods and
data. Therefore, this principle provides security to the data inside a program. Visual basic
use classes or class module to encapsulate the data and methods.
Inheritance: - Inheritance is the process by which objects can acquire the properties of objects of
other class. In OOP, inheritance provides reusability, like, adding additional features to an existing
class without modifying it. This is achieved by deriving a new class from the existing one. The
new class will have combined features of both the classes.
Polymorphism: - Polymorphism means the ability to take more than one form. An operation may
exhibit different behaviors in different instances. The behavior depends on the data types used in
the operation. Polymorphism is extensively used in implementing Inheritance.
Q145. What are the types of ActiveX Components available in visual Basic?.
Ans. You can create various types of ActiveX components in Visual Basic depending on the
requirements of the client application. Various types of ActiveX controls in Visual Basic are:
ActiveX Exe: These components are used to create applications that can be deployed on outprocess server architecture. The file extension for these files is .exe. The ActiveX Exe files run in
their own address space making communication between the separate processes but slow.
These files are more robust in terms of execution as bugs in the file do not lead to the crash of
the container.
ActiveX DLL:- These components are used to create applications that can be deployed on inprocess server architecture. The file extension for these files is .dll. These files cannot be
executed on their own. The ActiveX DLL files run in the same address space as the container
files leading to faster intercommunication between the processes.
ActiveX Control:- These components are used to create applications that can be deployed on
remote server architecture. The file extension for these files is .ocx. These files require
Cabinet(CAB) files for proper deployment of the control on the client machine.
ActiveX Document EXE:- These components are used to create controls for web-based
applications. These controls can be published to a web site. The client downloads the
corresponding control from the web site using the web browser.
SUBJECT: VB
Page 80 of 121
ActiveX Document DLL:- These Components are used to create component for Web-Based
applications like ActiveX Document EXE. In Contrast to the ActiveX Document EXE these files
require container files that can call the dll files to execute the required functionality.
Q146. How will you select a Record in a database through Visual Basic?.
Ans. Suppose we have a table in Microsoft access called database.mdb and we want to modify
the record then we have to perform the following steps.
1. Include reference of ADODB library(Microsoft AcvtiveX 2.0 Library)
2. Initialize connection and recordset using following commands in general section.
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
rs.MoveNext
If rs.EOF Then
MsgBox "You are at Last Record"
Exit Sub
End If
disp
End Sub
Private Sub Command2_Click()
rs.MovePrevious
If rs.BOF Then
MsgBox "You are at First Record"
Exit Sub
End If
disp1
End Sub
Private Sub Form_Load()
cn.Open "provider=microsoft.jet.oledb.4.0; data source=f:\database.mdb"
rs.Open select * from emp", cn, adOpenDynamic, adLockOptimistic
Text1.Text = rs(0)
Text2.Text = rs(1)
End Sub
Public Sub disp()
Text1.Text = rs(0)
Text2.Text = rs(1)
End Sub
Public Sub disp1()
Text1.Text = rs(0)
Text2.Text = rs(1)
End Sub
Q147. How will you play a Sound and a Movie File in visual Basic?.
SUBJECT: VB
Page 81 of 121
Ans. To Play a Sound or Movie File in Visual Basic You have to add an ActiveX control as
Window Media Player and an Commondialog control 6.0 in your Project file.
Now Add the following Coding in your Code Window:
Private Sub Command1_Click()
CommonDialog1.Filter = "Movie files|*.avi|Song files|*.mp3"
CommonDialog1.ShowOpen
MediaPlayer1.FileName = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
MediaPlayer1.Play
End Sub
Private Sub Command3_Click()
MediaPlayer1.Stop
End Sub
Private Sub Form_Load()
MediaPlayer1.ShowControls = False
MediaPlayer1.AutoStart = False
End Sub
Q148. What can be error handler used for?
(v.imp)
Ans. It is a routine that traps errors and directs a user or a program to perform a certain tasks to
overcome the error. Although Visual Basic handles the various errors that occur during runtime. It
is better for us to have control over the errors that are displayed.
The ErrObject when an error occur VBA activates the err object. The err object
is a class in VB to handle errors. It has number of properties and functions.
Clear: - This method is used to clear all the property settings of the error object.
Description: - Return or sets the string expression with a descriptive string associated with
the error objects.
HelpContext: - Return or sets a context ID for a topic in a help file.
Helpfile: - Return or sets the fully qualified path for help file.
Last DLL error: - Returns the system error code by call to DLL.
Number: - Returns or set a numeric value representing an error.
Raise: - This function will generate an error at runtime.
Source: - Returns or sets the name of the object that has originated the error
An error trapper should be introduced in the procedure where you anticipate the error. Once an
error occurs, the program flow must be directed to another part of the procedure where an error
will be resolved. In the error handler the error will be resolved b popping up a message box to a
user and initiating some action or the error will be ignored and execution of the procedure will
continue from the next statement.
SUBJECT: VB
Page 82 of 121
Ans. OLEDB is a set of Component Object Model(COM) interfaces that provide uniform access
to the data stored in diverse information sources, OLEDB is defined as a new low-level interface
that is a part of the universal Data Access platform. It is defined as a general purpose set of
interfaces designed to let developers build data access tools as a components using the
Component Object Model(COM). OLEDB enables applications to have uniform access to the
data stored in DBMS and non DBMS information containers while continuing to take advantage of
the benefits of the database technology without having transferred data from its place of origin to
a DBMS.
This means OLEDB is not restricted to ISAM, Jet or even relational data sources, but is
capable of dealing with any type of data, regardless of its format or storage method. OLEDB has
what is called providers which let you access the different data sources. For different data
sources you have different data providers. OLEDB provides four services that you will be using in
your application. These are:
A cursor service, which is defined as a temporary read-only table that saves the result of a
query with assigned name.
A service to perform batch updates.
A shape service to build that data in the form of hierarchy.
A Remote data service provider for managing data in multi-user environments over
connected or disconnected networks.
ADO: - ADO enables your client application to access and manipulate data in a database server
through any of the OLE DB providers. According to Microsoft ADOs primary
benefits are ease to use, high speed, low memory overheads and a small disk
footprint. ADO supports key features for building client/server and web based
applications.
The ADO features an object model like the DAO and the RDO but it is much flatter. In the case of
the DAO you had seventeen objects and in the case of ADO you have only seven object besides
you do not have to follow a strict hierarchy when working with these objects in ADO. Let us see
how ADO allows you to access data from a database.
Establishment of a connection to a data source
Extraction of the required data with a suitable command.
Having extracted the data and worked on it, we may have to up-to-date the data source.
Keep an eye on the errors that may occur and take suitable action.
Q150. What is data environment designer used for?.
Ans. A Data Environment Designer use an ActiveX designer tool provided by the VB. The Data
Environment designer provides an interactive design time environment to access data from a
database programmatically at run-time. A design time is defined as a time during which you
create an application in the VB environment and adding controls setting properties and writing
code to perform a specific task etc. The data Environment designer enables you to perform the
following tasks:
Adding Data environment Designer to a VB Project
Creating Connection Objects top create connections to the created database
SUBJECT: VB
Page 83 of 121
SUBJECT: VB
Page 84 of 121
Report designer. In that case, for each of the fields contained by the Command object, a text box
control will be created on the data report; the DataMember and DataField property for each text
box will be set to the appropriate values.
2.Toolbox ControlsThe Data Report designer features its own set of controls. When a Data
Report designer is added to a project, the controls are automatically created on a new Toolbox
tab named DataReport. Most of the controls are functionally identical to Visual Basic intrinsic
controls, and include a Label, Shape, Image, TextBox, and Line control. The Function Control
automatically generates one of four kinds of information: Sum, Average, Minimum, or Maximum.
3.Print PreviewPreview the report by using the Show method. The data report is then
generated and displayed in its own window.
4.Print ReportsPrint a report programmatically by calling the PrintReport method. When the
data report is in preview mode, users can also print by clicking the printer icon on the toolbar.
5.File ExportExport the data report information using the ExportReport method. Formats for
export include HTML and text.
6.Export TemplatesYou can create a collection of file templates to be used with the
ExportReport method. This is useful for exporting reports in a variety of formats, each tailored to
the report type.
7.Asynchonous OperationThe DataReport object's PrintReport and ExportReport methods
are asynchronous operations. Using the ProcessingTimeout event, you can monitor the state of
these operations and cancel any that are taking too long.
Q154. What are the Benefits of COM(Component Object Model).
Ans. COM is a technology to create binary executables that allows the programmers to reuse
the components defined for one application into another. The concept of producing binary
executables and to reuse the code offers multiple benefits to a user such as:
Programming Language: - The COM components can be built using various programming
languages such as C, C++. The use of various COM components arises from the fact that these
languages can support pointers to point to the functions defined in the source code. Moreover the
source code defined to create interfaces in these languages can be saved as binary executables.
The binary executables produced by these languages can be deployed and integrated with other
applications easily.
Reuseability Concept: - The COM allows programmers to create components and interfaces
based on built-in controls and operations that can be used in various applications. A programmer
can develop COM component to design the desired interface based on application requirement.
This developed COM component can be integrated with one or multiple applications to be
developed by the programmer. The concept of code reusability allows the programmer to create
the code and use it in various applications
Backward compatibility: - There is a constant need to upgrade the COM component and the
functionality provided by them. COM components allow the programmer to extend and
functionality of the existing components and interfaces using the request called QueryInterface.
All types of COM components support QueryInterface request. It allows the programmer to create
new interfaces with additional functionality. The new interface developed by queryInterface are
made backward compatible with the existing COM components.
SUBJECT: VB
Page 85 of 121
Maintaining Version Consistency: - With the growing need of an application to increase the
functionality and complexity of the COM component, the programmer either need to write the
code from the scratch or to revise the existing COM component for desired functionality.
Distributed Component Object Model: - The Distributed Component Object Model allows a
programmer to make an interface call for the Component Object Model that resides on remote
machine using remote procedure Call(RPC).Microsoft introduced the concept of DCOM to extend
the functionality of all existing components and attain distributed capabilities for a COM object.
Q155. Write a program to swap two values using call by reference parameter passing
mechanism.
Ans Function swap(ByRef a As Integer, ByRef b As Integer)
Dim c As Integer
c=a
a=b
b=c
Text3.Text = a
Text4.Text = b
End Function
Private Sub Command1_Click()
swap Text1.Text, Text2.Text
End Sub
Q156. Write a program that request a month of the year and then gives the number days in
the month?
Ans
SUBJECT: VB
Page 86 of 121
SUBJECT: VB
Page 87 of 121
The easiest way to expose COM objects is by using the COM class template. The COM class
template creates a new class, and then configures your project to generate the class and
interoperability layer as a COM object and register it with the operating system.
To set up your project to generate a COM object
1. Open a new Windows Application project from the File menu by clicking New Project.
2. In the New Project dialog box under the Project Types field, check that Windows is
selected. Select Class Library from the Templates list, and then click OK. The new project is
displayed.
3. In Solution Explorer, right-click your project, and then click Properties. The Project
Designer is displayed.
4. Click the Compile tab.
5. Select the Register for COM Interop check box.
Q158. Explain the process of adding controls to the form?
Ans we can add controls to the form in two ways first we can drag and drop the controls from
the the tool box and we also add control dynamically to the form at run time. We add control
mostly at design time.
To create a application which display hello world.
1. click file-- New project -- select the standard Exe form.
2. form layout window is displayed
3. resize the form by dragging the its borders.
4. double click the command button control in the toolbox to create a command button.
5. double click on the label control in the toolbox to create the label on the form.
6. now set the following properties of the form, command button and label like name and
caption.
7. now double click on the command button and open the code window and the write the code
for command button click. Click is the default event for command button control.
8. now save the project and run your project by pressing the F5 key from the key board.
Q159. How do you specify an access key for a menu item?
Ans menu command usually contain access key donated by underline letters in the menu text
users can quickly select menu commandby pressing the ALT key along with the access key .
Some commonly used access command may also have a shortcut key (usually a function key,or
a letter combined with CTRL,ALT or SHIFT key)Shortcut key activate the menu command without
having the select it.
To create a menu command
1. Enter the caption for the menu command in the caption field .( Includean ampersand(&)in the
caption to create an access key)
2. enter the name for the menu command in the name field.
Q160. How do you check whether a condition should be checked at the top of loop or at
the bottom ?
Ans we know that the condition checking in the for and while first or at the top if condition is true
then the loop is executed else not but the condition testing in the last in the do-while loop
SUBJECT: VB
Page 88 of 121
because the condition testing statement written in the last in this case statement executed first
and the checked according to the syntax of the do while loop.
for Loop
Syntax
Dim a as integer
For a=1 to 10 step 1
Statement1
Next a
In the above given program the condition testing in for loop in beginning of the loop and then
executing the statement if condition is not true then loop is not executed.
Q161. What is control array? How it is created ? discuss its uses.
Ans.
Control array is the array of controls. To create the array of control just place the control on form
at design time, then copy paste it again and again. By making the control array, similar type of
code can be used for multiple controls. These Controls have a common index property that is
used to identify a particular control in a control array.
How created control Array
First add two command
Buttons first to add labels and
Second to remove the labels
Add a label and make a control
Array for label.
Private Sub Command1_Click()
Dim a As Integer
For a = 0 To 3
Label1(a).Caption = "label" & a
Next
End Sub
Private Sub Command2_Click()
Dim a As Integer
For a = 3 To 0 Step -1
Label1(a).Caption = ""
Next
SUBJECT: VB
Page 89 of 121
End Sub
Control array is used to create a collection of controls. It is easy to maintain them and use
them. It is used to create more than one control of same type then we use control array.
Q162. What is collection? How do we add, delete elements from it?
Ans A collection is an object that contains a set of related objects. There is another type of
looping mechanism in visual basic that allow to you iterate ,or step ,through each control in a
collection.you can do this using for each next loops. This technique is extremely useful when
you dont know the exact number of items in the collection.
You can use for each loop through all items in the collection using code similar to the
following.
Dim cmd as command1
For each cmd in form1
With cmd
If .index<> index then
Msgbox button & trim$(str$(.index))&was not pressed.
End if
End with
Next
The first line dimension an object of the command button class. The next line tells visual basic to
iterate through every command button object for form1. the with cmd statement on the next line
tells the visual basic to use the current object in the collection set to cmd.
Looping through collection is useful for many tasks including iterating through items in treeview
and listview controls,childs formsin an MDI application and object in a dynamic HTML documents.
Q163. Discuss the string handling in-build function : instr, mid, left, right with suitable
example.
Ans Instr() function :- Instr function tells you whether the first string is a part of the another
string or not and also it will tell you the position from which the first string starts within the another
string. The syntax is
Instr [string1, string2, compare]
Example:
str=instr(1,Visual Basic,a)
mid() function :-It returns a substring containing a specified number of characters from a
string. The syntax is
mid(string,strat,length)
Example:
str=mid(Visual Basic,3,7)
left() function:- It returns a substring containing a specified number of characters from the
beginning of a string. The Syntax is
left(string ,length)
Example:
SUBJECT: VB
Page 90 of 121
str=left(Visual Basic,5)
right() function:- It returns a substring containing a specified number of characters from the
end of a string. The Syntax is
right(string ,length)
Example:
str=right(Visual Basic,4)
Q164. Suppose you have a database table EMP( ID,NAME,AGE,EMAIL) IN MS ACCESS .
Discuss the following using ADO.
(a) Connecting to the database
(b) Insert a record into the table
(c) Display records on a form.
Ans Two ways of establishing a connection to database with ADODB are:
1.By passing the connection string to open method of ADODB.
2.By creating a dsn that can be passed to open method of ADODB.
SUBJECT: VB
Page 91 of 121
Ans Create a DSN-less Database Connection: - The easiest way to connect to a database is to
use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access
database on your web site.
If you have a database called "northwind.mdb" located in a web directory like
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>
Note, from the example above, that you have to specify the Microsoft Access database driver
(Provider) and the physical path to the database on your computer
Q166. Give visual basic code for frames. And also explain what are the various properties
associated with it.
Ans frame is often used as a container for check box, option button too, each check box is
completely independent. Thus the setting for one check box has no effect on the setting for the
other in the same group.
CheckBoxes: - Option bars are used quite often in the windows environment as they can only
have two outputs 0 and 1 these get used to process the form. In this example it will be
used to change the some text from normal to bold or to italic.
SUBJECT: VB
Page 92 of 121
txtDisplay.FontItalic = True
Else ' If not checked.
txtDisplay.FontItalic = False
End If
End Sub
The checkboxes can be turned on at runtime by simply typing
name.value = 1 ' 1 On , 0 off
Q167. There is a label named lblResult that has a property named caption. There is a
variable named X.
(a) write a statement that display the value of x in the labels caption.
(b) Write a statement that display the variable X in the labels caption.
Ans
Private Sub Command1_Click()
Dim x As Integer
x = InputBox("enter the value of X")
lblResult.Caption = x
End Sub
Private Sub Command2_Click()
lblResult.Caption = "X"
End Sub
SUBJECT: VB
Page 93 of 121
SUBJECT: VB
Page 94 of 121
3333
3333
3333
Q171. what is progress bar how to use it.
Ans A ProgressBar control allows you to graphically represent the progress of a transaction. The
control consists of a frame that is filled as the transaction occurs. The Value property determines
how much of the control has been filled. The Min and Max properties set the limits of the control.
Use the ProgressBar whenever an operation will take more than a few seconds to complete. You
must also know how long the process will take by using a known end point and setting it as the
Max property of the control
SUBJECT: VB
Section C
[QUESTIONS 1 TO 23]
Page 95 of 121
10 Marks Questions
[PAGE 95 TO 120]
SUBJECT: VB
Page 96 of 121
program run. Each time an event occurs, it causes a message to be sent to the operating system.
The system processes the message and broadcasts it to the other windows. Each window can
take the appropriate action based on its own instructions for dealing with that particular message.
Event : - It is an action recognized by an object such as clicking of the mouse or pressing of a
key and you can write a code as a response to the occurrence of an event. Events can occur as a
result of a user action or program code or they can be triggered by the system. Some events are
like: Click
Dblclick
Keyup
Keydown
Load
Q3.
Difference between c and visual basic
ANS- There are many difference between c and visual basic
1. C language was developed by
Dennis Ritchie.
5. VB use Classes.
9. In VB we use forms.
Q4.
What is IDE and also explain its component?
Ans VB works in an Integrated Development Environment (IDE). IDE is a collection of menus,
toolbars and windows that make up your programming easy. Each part of IDE affects different
aspects of your programming activity. One of the most significant changes in Visual Basic 6.0 is
SUBJECT: VB
Page 97 of 121
the Integrated Development Environment (IDE). IDE is a term commonly used in the
programming world to describe the interface and environment that we use to create our
applications. It is called integrated because we can access virtually to all of the development tools
that we need from one screen called an interface. The IDE is also commonly referred to as the
design environment, or the program.
Components of IDE: Title bar
Menu Bar
Standard Bar
Toolbox
Project Explorer
Properties window
Form Layout Window
Form Designer window
Object Browser window
Code and text editor window
The Visual Basic startup dialog box
1) Title Bar : - Title bar is the top most bar on the IDE window that display the title of the project.
Title bar has three buttons minimize, maximize (restore down) and close.
2) Menu Bar : - This Menu Bar displays the commands that are required to build an application.
The main menu items have sub menu items that can be chosen when needed. The toolbars in
the menu bar provide quick access to the commonly used commands and a button in the toolbar
is clicked once to carry out the action represented by it.
3) Standard Toolbar : - It contains small icon buttons which are used to access most commonly
commands through shortcut small icon.
4) Toolbox : - The Toolbox contains a set of controls that are used to place on a Form at design
time thereby creating the user interface area. Additional controls can be included in the toolbox by
using the Components menu item on the Project menu. A Toolbox is represented in figure shown
below.
5) Project Explorer : - Docked on the right side of the screen, just under the toll bar. It is the
Project Explorer window. The Project Explorer as showed in figure services as a quick reference
to the various elements of a project namely form, classes and modules. The entire objects that
make up the application are packed in a project. A simple project will typically contain one form,
which is a window that is designed as part of a program's interface. It is possible to develop any
number of forms for use in a program, although a program may consist of a single form. In
addition to forms, the Project Explorer window also lists code modules and classes.
It also contains a hierarchical tree structure of the forms in the projects. A Project
Explorer consists of a number of forms, modules and controls that make up an application. It
helps to manage & navigate multiple projects. This window provides three buttons:
View Code.
View Object.
Toggle Folders.
SUBJECT: VB
Page 98 of 121
6) Properties Window : - The Properties Window is docked under the Project Explorer window.
The Properties Window exposes the various characteristics of selected objects. Each and every
form in an application is considered an object. Now each object in Visual Basic has
characteristics such as color and size. Other characteristics affect not just the appearance of the
object but the way it behaves too. All these characteristics of an object are called its properties.
Thus a form has properties and any controls placed on it will have properties too. All of these
properties are displayed in the Properties Window
The two tabs of property window are:
0.Alphabetic
1.Categorized
Sometimes it is convenient to display the properties sorted alphabetically. For this, alphabetic tab
can be used. But sometimes you can group the properties according to their categories. For this,
categorized tab can be used. e.g. categories can be appearance, behavior etc.
7) Form Layout Window : - Form Layout Window is used to set the position of the form on the
computer screen where it will be displayed when the project is run.
8) Forms designer window : - A form designer window contains the form. Form is the heart of
Visual Basic application. Form is a canvas or container window on which you will place the
various objects that make up application. We work in form designer window to add controls to the
form. It has a title bar in which it contains Project1- form1 (Form) name, minimum button,
maximum (restore down) button and close button.
9) Object Browser : - The Object Browser allows us to browse through the various properties,
events and methods that are made available to us. Selecting Object Browser from the View menu
or pressing the key F2 accesses it. The left column of the Object Browser lists the objects and
classes that are available in the projects that are opened and the controls that have been
referenced in them. It is possible for us to scroll through the list and select the object or class that
we wish to inspect. After an object is picked up from the Classes list, we can see its members
(properties, methods and events) in the right column.
A property is represented by small icon that has a hand holding piece of paper. Methods
are denoted by little green block while events are denoted by yellow lightning bolt icon.
10) Code and text editor window : - VB objects can recognize many different events. The
objects will not function unless you have written code to tell them what to do when the event
happens. This means that for any event, you must write an event procedure telling VB what to do,
so event procedures are lines of programming code that tell VB how to respond to a given event.
Double-clicking any, blank part of the form will open the code window. VB program code
is entered in this window. It contains two drop-down list boxes. If you pull down the left hand box
in the code window you will see a list of controls on your form. If you pull down the right hand box,
you will see the list of events supported by the selected controls.
Q5.
What is INTRINSIC CONTROLS
Ans- The controls are the building blocks (pre-define). Which are used to assemble (design) the
VB program. The toolbox is a foundation of controls from which we can select controls and place
them in the form. There are two types of controls in Visual basic.
SUBJECT: VB
Page 99 of 121
1) INTRINSIC CONTROLS: - These controls reside within VB itself. They cant be removed from
the toolbox. The Toolbox contains 21 intrinsic controls.
Icons
Control name
Pointer
Label
Deception
It is by default Selected control.
It is used to interact with controls on the form.
It is used to display graphics images, icons on a form and we can use
as a container object.
Displays static text.
TextBox
It is used to accept user input, which can display only editable text.
Frame
It's just like a container - It can hold other controls. There are two very
good reasons to use it. First is If you want multiple groups of option
buttons then place each group in a frame and each group will operate
independently. Second is If you want to manipulate controls as a
group then put them in a frame and you can handle them all at one
time.
This one works just like you expect. Press the button and it executes
a block of code.
Enables users to select or deselect an option. We can select multiple
check boxes depending upon the user.
PictureBox
Command
Button
CheckBox
Option
Button
ComboBox
FileListBox
It is used to contain list of items but user can select only one item
from a list of items or add and remove items in the combobox.
It is used to contain list of items but user can select multiple items
from a list of items using Multiple property or add and remove items in
the listbox.
Basically you use the slider value of a scroll bar as the input for other
code that you write. These are normally used in conjunction with other
controls.
Basically you use the slider value of a scroll bar as the input for other
codes that you write. These are normally used in conjunction with
other controls.
This is the most unusual of the intrinsic controls. It is Used to set a
timer on Form using its Interval property. At each interval, its Timer
event fires. Lets the program to perform actions in real time without
user interaction.
It is used to enable all the drives and we can select drive from the
drive listbox.
It is used to enable all the directories and we can select directory from
the directory listbox.
It is used to access the file in the directory.
Shape
Graphic control that can draw and fill a rectangle, circle, square, or
ListBox
HScrollBar
VScrollBar
Timer
DriveListBox
DirListBox
SUBJECT: VB
Line
Image
Data
OLE
Q6.
Explain explicit controls
Ans ) EXTRINSIC CONTROLS: - These are outside VB controls & reside in toolbox with .OCX
files. These can be added to & removed from the toolbox. If we want use it, firstly, insert the
extrinsic control.
Step to insert extrinsic control
1)Click on project menu and then select component option or right click on the Toolbox then
select Component option.
2)Then it displays Components dialog box, which contains Controls, Designers, and Insert able
Objects tab.
ACTIVEX CONTROLS.
3) Then select any one of then which component programmer requires.
4) Then click OK button.
5) Now the control that you selected from the components dialog box, is displayed in the toolbox.
Q7.
What is SDI and MDI form?
Ans. In a visual basic we used two type of form first is SDI and second is MDI form
1. SDI (Single Document Interface)
SUBJECT: VB
SUBJECT: VB
The local variables exist as long as the procedure in which they are declared. Once a
procedure is executed, the values of local variables are lost and the memory used by these
variables is free and can be reclaimed. Variables that are declared with Dim keyword exist only
the procedure is being executed.
For example : - In the following program "command1" and "command2" the variable X is
declared in each of the modules. Each variable X is independent of the other--the variable is only
recognized within its respective procedure.
Module Level Variables: - A module level variable is available to all the procedures in the
module. Using Public or Private keyword declares them. If you declare a variable using a
Private or Dim keyword in the declaration section of a standard BAS module, a form
module, a class module and so on then you are creating a private module-level variable.
Such variables are visible only from within the module and can't be accessed from the
outside. In general these variables are useful for sharing data among procedures in the
same module:
In the declarative section of any module
Private Login As Date
' Private module-level variable
Dim Password As String
' another private module-level variable
You can also use the Public keyword for module-level variables. All module types except
BAS modules. (Public variables in BAS modules are global variables.) In this case, you are
creating module-level variable that can be accessed by all procedures in the module to share
data and that also can be accessed from outside the module. In this case, however, it's more
appropriate to describe such a variable.
' In the declaration section of Form1 module
Public CustomerName As String
' A Public property
You can access a module property as a regular variable from inside the module and as a custom
property from the outside:
' From outside Form1 module...
Form1.CustomerName = "Dharam & Neshan"
Project level variables: - Project level variable is also called global or public scope. It means the
variable is accessible to all procedures in all modules of the project. The variables available to all
the modules and procedures in an application are said to have project level variable. Public
keyword is used to declare variable as project level scope. It is also known as global variable.
Basically project level variables are declared when we want use same variable in whole project. It
is declared in the general section but we cant declared in any private sub block.
Public vs private Variables : - The scope of the public variable is global, it means variable can
be accessible in all procedures and modules. The scope of the private variable is local, it
means variable can be accessible within procedure only where it is declared. A variable
can have the same name and different scope.
For example, we can have a public variable named R and within a procedure we can
declare a local variable R. References to the name R within the procedure would access the local
variable and references to R outside the procedure would access the public variable.
SUBJECT: VB
Static Variables : - Static variables are not reinitialized each time Visual Invokes a procedure
and, therefore, retain or preserve value even when a procedure ends. In case we need to
keep track of the number of times a command button in an application is clicked, a static
counter variable has to be declared. These static variables are also ideal for making
controls alternately visible or invisible. A static variable is declared as given below.
Static sta As Integer
Variables have a lifetime in addition to scope. The values in a module-level and public variables
are preserved for the lifetime of an application whereas local variables declared with Dim
keyword. It can exist only with the procedure in which they can declare is still being executed.
The value of a local variable can be preserved using the Static keyword. The following procedure
calculates the running total by adding new values to the previous values stored in the static
variable value.
The following is an example of an event procedure for a CommandButton that counts and
displays the number of clicks made.
Private Sub Command1_Click ( )
Static Counter As Integer
Counter = Counter + 1
Print Counter
End Sub
The first time we click the CommandButton, the Counter starts with its default value of zero.
Visual Basic then adds 1 to it and prints the result.
Q9.
What is data type explain with details?
Ans Data type means what type of data will be stored in the variable. This data can be an
alphabet, numerical having decimal point or without decimal point. Data type determines size
(range) of the data and how much storage space is allocated by variables. Visual Basic supports
many kind of data type. By default Visual Basic variables are of variant data types. The variant
data type can store numeric date/time or string data. When a variable is declared a data type is
supplied for it that determines the kind of data they can store. The fundamental data types in
Visual Basic including variant, integer, long, single, double, string, currency, byte and Boolean.
Each data type has limits to the kind of information and the minimum and maximum values it can
hold. In addition, some types can interchange with some other types. Lists of Visual Basic data
types are given below.
In Visual Basic 6.0, there are 11 different data types available in visual basic. Like
Type
Store
Memory
Identifier
1.Integer
Whole numbers
2 bytes
%
2.Long
Whole numbers
4 bytes
&
3.Single
Decimal numbers
4 bytes
!
4.Double
Decimal numbers
16 bytes
#
5.String
Text information
1 byte
$
6.Boolean
True/ False
2 bytes
-7.Byte
Whole number
1 byte
-8.Currency
@
9.Date
Date & Time
8 bytes
--
SUBJECT: VB
10. Object
11. Variant
None
Any of the data types
16 bytes
None
--
Integer : - The Integer data type occupies 2 bytes. The valid range of an Integer variable is 32768 to 32767. Integers should be used when you are working with values that cant contain
fractional numbers.
Long : - The Long data type occupies 4 bytes Memory. The valid range of a long variable is 2,147,483,648 to 2,147,483,647. Long variables can only contain non-fractional values. Long
data type is over Integers for increased performance. Most Win32 functions use this data type for
this reason.
Single : - The Single data type occupies 4 bytes memory space. The valid range of a long
variable is -3.402823e38 to -1.401298e - 45 for negative values and from 1.401298e -45 to
3.402823e38 for positive values. When you need fractional numbers within this range then we
can use single data type.
Double: - The Double data type occupies 16 bytes Floating-point memory used. These variables
range from -1.79769313486232e308 to -4.94065645841247e-324 for negative values and from
4.94065645841247e-324 to 1.79769313486232e308 for positive values. When high accuracy is
needed then we can use double data type.
String : - The String data type usually used as a variable-length and fixed-length type of
variables. A variable-length string can contain up to approximately 2 billion characters. If we use
fixed-length then it occupies fixed length the length that we define in the declaration time. Each
character has a value ranging from 0 to 255 based on the ASCII character set. Strings are used
when Text is involved.
Boolean : - The Boolean data type has only two states True and False. These types of variables
are stored 16-bit (2 Byte) memory. For example, lets suppose that you have a textbox (Text1) and
a command button (Command1). You want only Command1 to be enabled when there is text in
Text1. You would do something like this...
Whenever you Run the program then Command1 will only be enabled when there is text typed
into Text1, other wise command1 is disabled.
Byte : - The Byte data type is occupies 1-byte, which can store value from 0 to 255. This data
type is very useful for storing binary data.
Currency : - This data type is used for holding values related to item rates, payrolls details and
other financial functions. However this data type should not be used if you need extreme
accuracy beyond the fourth decimal point. For example, if you are working on foreign exchange
details or interest rates for very large values. So user used currency data type. Declaration for
currency is
Dim salary as currency
Date : - This variable holds date and time data. It can hold time from January 1 to December
31,9999 and time from 00.00.00(midnight) to 23.59.59. It occupies 8 bytes of memory. The date
is displayed as per the setting in your computer. You can store it in British format, American
format or any other format that is available in the regional setting on your control panel.
Dim tomorrow as date
SUBJECT: VB
Object : - In visual basic forms, controls, procedures and recordsets are all considered as
objects. All programming activity revolves around these objects. Visual basic is very much an
object-based programming language. It is natural to use Object data types.
Variant : - Variant is a special data type that can contain any kind of data except fixed-length
string data. Variant data can also be the special values Empty, Error, and NULL.
Dim a
It is a variant data type, because we can mention any data type. It will automatically pick any type
of data in the program.
Q10.Explain the difference between implicit and explicit declarations. Explain with
suitable example.
Ans There are many ways of declaring variables in Visual Basic, depending on where the
variables are declared and how they are declared. We can determine how they can be used by
our application. The different ways of declaring variables in Visual Basic are listed below: Implicit Declaration
Using Option Explicit statement
Implicit Declaration
Declaring a variable tells Visual Basic to reserve space in memory. There are two ways to declare
implicit variable.
1. Automatically variable declaration.
2. Using Dim keyword.
1. Automatically variable declaration: - It is not must that a variable should be declared before
using it. Visual basic language provides automatically variable declaration facility, it means we
can use variable without declaration. In this case Visual Basic compiler declares variable
automatically with variant data type and NULL value. This is called implicit declaration.
2. Using Dim keyword: - The variables are declared with Dim (Dimension) keyword and without
using Option Explicit are called implicit variables.
Syntax: Dim < variable name > as < date type >
1. Dim is a keyword that tells visual basic that you want to declare a variable.
2. Variable name is the name of the variable.
3. As is a keyword that tells visual basic that you are defining the data type for the variable.
4. Data type is the type of data.
For example
Dim strName As String
Dim intCounter As Integer
In the above example, we declared two variables strName as string type variable and intCounter
is an integer type variable.
Using Option Explicit statement : - It may be convenient to declare variables implicitly. But it
can lead to errors that may not be recognized at run time. For example a variable by name
intcount is used implicitly and is assigned to a value. In the next step this field is incremented by 1
by the following statement
Intcount = Intcunt + 1
SUBJECT: VB
This calculation will result in intcunt a value of 1 as intcount would have been initialized to zero.
This is because the intcount variable has been incunt in the right hand side of the second
variable. But Visual Basic does not see this as a mistake and considers it to be new variable and
therefore gives a wrong result.
In Visual Basic, to prevent errors of this nature we can declare a variable by adding the following
statement to the general declaration section of the Form.
Option Explicit : - This forces the user to declare all the variables. The Option Explicit
statement checks in the module for usage of any undeclared variables and generates error
reports to the user. The user can rectify the error on seeing this error message.
The Option Explicit statement can be explicitly placed in the general declaration section
of each module using the following steps.
Click Tools menu then select Options
Then it will display Options dialog box that contains many tabs.
SUBJECT: VB
Example
Result
Add
5+5
10
Subtract
10-5
Divide
25/5
Integer Division
20\3
Multiply
5*4
20
Mod
Example
Result
>
Greater than
10>8
True
<
Less than
10<8
False
>=
20>=10
True
<=
10<=20
True
<>
Not Equal to
5<>4
True
Equal to
5=7
False
Logical Operators : - These operators are used to combine two or more relational expressions.
They also return their result in a Boolean form.
Various types of logical operators used in visual basic but basically we use three operators in
visual basic. All LOGICAL operators have priorities lower than arithmetic and relational operators.
Therefore if an expression involving arithmetic relational and logical operators, the arithmetic
operators are evaluated first, followed by the relational operators, followed by the logical
operators.
Operators
Description
OR
AND
Operation will be true only if both the operands values are true
NOT
SUBJECT: VB
5.IIF ( ) statement
6.Select case statement
1. if...Then selection statement : - If...Then selection statement performs an indicated action,
only when the condition is true, otherwise the action skipped. It is the basic condition control
statement. When we have single condition then mostly used this statement. The if .Then
selection statement allows a programmer to test the value of a conditional expression and to
select or reject the execution of the statement or block of statements depending on this value. It
is also known as single block statement.
Syntax If...Then selection statement
2. If...Then...Else selection statements : - The If...Then...Else selection statement allows the
programmer to specify that a different action is to be performed, when the condition is True or
when the condition is False. If Expression is true then it executes first statement block, otherwise
it executes second statement block.
Syntax of the If...Then...Else selection statement
If <condition > Then
statements
First Statement Block
Else
statements
Second Statement Block
End If
3. If .ThenElseif selection statement : - If we have more than two conditions then we
uses if else if statement. In this we can create multiple blocks of statements and it will execute
according to the condition.
Syntax of the If...Then...Elseif Else selection statement
If <condition > Then
statements
First Statement Block
Elseif <condition > Then
statements
Second Statement Block
Else
Statements
Third Statement Block
End If
4. Nested If statement : - Nested If statement means, if statement within if statement. First if
statement is called outer if statement and second is inner if statement. If outer if statement is true
then check inner if statement, but If outer if statement is false then doesnt check inner if
statement.
Syntax of the Nested If statement
If < condition 1 > Then
If < condition 2 > Then
statements
Else
statements
End if
Else
If < condition 3 > Then
SUBJECT: VB
statements
Else
statements
End if
End If
5. IIF( ) statement : - IIF( ) statement means Immediate IF statement. Visual basic offers IIF( )
is a function that can be used as an alternative to simple IfThen.Else statement. Basically
this function is used to combines a single IfThen..Else statement in one line.
Syntax of the IIF ( ) statement
IIF (Condition, Expression1, Expression2)
6. Select...Case statement
Select case statement is used, when a single variable has multiple choices. In select case
statement we can gave multiple cases, if case will match then it will execute related block
otherwise default case will be executed. Select case statement is an alternative of the
If...Then...ElseIf statement. Select case statement is more convenient to use than the
If...Then...ElseIf statement. The variable used in select case statement is known as select case
variable. The variable in the select case statement can be integer or string type only.
In select case statement we use select, case and else keywords.
Syntax: Syntax of the Select...Case statement
Select
Case
<expression>
Case
value
Statements
Case
value
Statements
Case else
Statements
End Select
Q13. What is loop? Explain its types?
Ans There are many types of loops used in visual basic
1) For...Next Loop : - For..Next loop is used to repeat the set of statements till a particular
condition is true but if condition is false then loop will stop work. For.Next loop is a fix loop,
because we knows in advance how many times the loop will be repeat. For.Next loop is a
single line loop, because initialization, condition and updation written in a single line. Its also
known as entry control loop or top check loop. It means loop checks the condition first then it
executes the statement.
Syntax: For <counter_var>=<start_value> To <end value> step <increment /decrement value>
SUBJECT: VB
2. For Each..Next Loop Statement : - For Each Loop is used to repeats a group of
statements. It is collection of object or is an array instead of repeating the statements is a
specified number of items. This is especially helpful if you dont know how many elements are in
a collection or a dynamic array. For Each Loop used only variant variable.
Syntax: For Each element In group
[ statements ]
[ statements ]
Next [ element ]
3. Do While... Loop Statement : - Do While..Loop is used to repeat the set of statements till
particular condition is true but if condition false then loop stop its works. It is a true loop. In Do
While.Loop initialization, condition and updation statements gave separate(different )lines in
the loop. Its also known as entry control loop or top check loop. It means loop checks the
condition first then it execute the statements.
Syntax: Initialization
Do While condition
Statements
updation
Loop
4. Do Until...Loop Statement : - The Do Until.. Loop statement is used to repeat the set of
statements till a particular condition is false if given condition is true then the loop will terminate.
Its also known as false loop. Its also known as entry control loop or top check loop.
Syntax: Initialization
Do until condition
Statements
updation
Loop
5. While... Wend Statement : - While..Wend loop is used to repeat the set of statements till a
particular condition is true, if condition is false then loop will stop works. Same as Do
While.Loop. In WhileWend loop have three statements initialization, condition and
updation that written in separate (different) lines. Its also known as entry control loop and top
check loop. The While..Wend loop is an older statement pair from previous versions of BASIC
and was included in Visual Basic for compatibility. WhileWend loop cant terminate using Exit
keyword and another hand Do While..Loop can terminate using Exit keyword.
Syntax: Initialization
While condition
Statements
updation
Wend
SUBJECT: VB
Q14. What is menu how we can create menu and sub menu in visual basic?
Ans: menu is mostly used in all the application software. A list of commands or options from
which you can choose. Most applications now have a menu-driven component. You can choose
an item from the menu by highlighting it and then pressing the Enter or Return key, or by simply
pointing to the item with a mouse and clicking one of the mouse buttons.
The antithesis of a menu-driven program is a command-driven system, in which you must
explicitly enter the command you want rather than choose from a list of possible commands.
Menu-driven systems are simpler and easier to learn but are generally not as flexible as
command-driven systems, which lend themselves more naturally to interaction with programs.
Steps to Create a Menu Through Menu Editor
1.Invoke the menu editor.
2.In the caption text box type & color.
3.In the name text box type mnucol.
4.Press next button.
5.Now press right arrow button to give one level indent.
6.Now type &red in the caption text box and mnured in the name text box.
7.Similarly type other color entries.
8.Press OK to save.
9.Now switch to code window and type the following code in the mnured_click ( ).
10.
Private Sub mnuRed_click ( )
11.
Form1.BackColor = VbRed
12.
End Sub
Similarly type the code for mnugreen and mnublue click ( ) events. Now run the application.
Q15. What is error define its types in visual basic?
Ans So far, the errors you have encountered in your programs have probably been simple typing
mistakes or syntax errors. But what if you discover a nastier problem in your program one you
cant find and correct by a simple review of the objects, properties, and statements in your
application? The Visual Basic development environment contains several tools you can use to
track down and fix errors (bugs) in your programs. These tools wont stop you from making
mistakes, but they often can ease the pain when you encounter a mistake
Three Types of Errors : - As you develop Visual Basic programs, three types of errors can
produce unwanted results in your applications. These are described in the following topics:
1) Logic errors
2) Syntax errors
3) Run-time errors
Logic Errors : - A logic error is a human error a programming mistake that makes the
program code produce the wrong results. Most debugging efforts focus on tracking down
programmer logic errors.
Consider the following If...Then decision structure, which evaluates two conditional expressions
and then displays one of two messages based on the result:
If Age > 13 And Age < 20 Then
Text2.Text = "You're a teenager."
SUBJECT: VB
Else
Text2.Text = "You're not a teenager."
End If
Can you spot the problem with this decision structure? A teenager is a person who is between
13 and 19 years old, inclusive, yet the structure fails to identify the person who is exactly 13. (For
this age, the structure incorrectly displays the message, Youre not a teenager.)
This type of mistake is not a syntax error (the statements follow the rules of Visual Basic); it is a
mental mistake, or logic error. The correct decision structure contains a greater than or equal to
operator (>=) in the first comparison after the If...Then statement:
If Age >= 13 And Age < 20 Then
Believe it or not, this type of mistake is the most common problem in Visual Basic programs. It's
a matter of code that works most of the time but not all of the time and it's the hardest
problem to track down and fix.
Syntax Errors : - A syntax error (compiler error) is a programming mistake that violates the rules
of Visual Basic, such as a misspelled property or keyword. As you type program statements,
Visual Basic points out several types of syntax errors and you wont be able to run your
program until you fix each one.
Runtime Errors : - A run-time error is any error usually an outside event or an undiscovered
syntax error that forces a program to stop running. Two examples of conditions that can
produce run-time errors are a misspelled file name in a
LoadPicture function and an open floppy drive.
Q16. What is pop up menu
Ans A pop-up menu is a floating menu that is displayed over a form, independent of the menu
bar. The items displayed on the pop-up menu depend on where the pointer was located when the
right mouse button was pressed; therefore, pop-up menus are also called context menus. In
Windows 9x, you activate menus by clicking the right mouse button.
To create a pop-up menu, you first need to define a menu throught the menu editor. To ensure
that this menu will not be displayed on the menu bar, you make it invisible, i.e.make sure that the
visible check box in the menu editor is not checked for this very menu.
Any menu that has at least one menu item can be displayed at run-time as a pop-up menu. To
display a pop-up menu, use the PopupMenu method.
This method uses the following syntax:
PopupMenu <menuname>
For Example, the following code displays a menu name mnuFile when the user clicks a form with
the right mouse button.You can use the MouseUp or MouseDown events to detect when the user
clicks the right mouse button:
Private Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then Button=2 indicate the right mouse button is clicked.
PopupMenu mnuFile
End If
End Sub
This example shows you how to create a pop-up menu (sometimes called a context menu or a
right-click menu).
SUBJECT: VB
SUBJECT: VB
(Intrinsic)
(Intrinsic)
(Intrinsic)
(Extrinsic)
(Extrinsic)
(Extrinsic)
SUBJECT: VB
Table - A group of data records each containing same type of information. For e g.-Student.dbf.
Record- A physical line in a data table each consisting of a number of data fields.
Field - A column name each containing same type of data.
Query - A command designed to retrieve a certain group of records from a table or a group of
tables.
Recordset - A group of records created by a quarry.
To Link up front end application with database VB provide numbers of techniques.
These are categorized into the following category.
1.DAO
2. RDO
3. ADO
1.DAO stands for Data Access Object. This is the older technique to link front end application
with backend database in vb. The Default control for data connectivity is available with DAO. With
the help DAO we can connect access 97 , excel , dbase3 etc.
2.RDO stands for Remote Data object used to connect front end application that is available on
different computer can connect with server to access data remotedly.
RDO helps to make remote application can only connect client / server application.
3.ADO stands for ActiveX Data Object this is the newest technique to connect front end
application with back end database. ADO provide two method to connect database 1. Active Data
Control and ActiveX Data Object Library.
Q21. Explain string function
Ans STRING FUNCTIONS
Asc ( ) - It returns the character code corresponding to the first letter in the string.
For e.g
Text1.text=a
Text2.text=Asc(Text1.text)
The output will be - 97
Instr ( ) - It returns the position of first occurrence of a string within another.
For e.g. :
Text1.text=QuickBasic was Visual Basics ancestor
Text2.text=Instr(1,text1.text,Basic)
The output will be - 6
StrRevers ( ) - It returns the reverse of a string.
For e.g.
Text1. Text = hello
Text2.text = StrReverse (text1.text)
Output - olleh
SUBJECT: VB
SUBJECT: VB
4 Now select the project using browse button in project and deployment wizard
5 Now click on package option to create package
6 Select standard exe package
7 Click on next and choose the package folder where you want to assemble the package
8 click on Next
9 Choose Add button to add database or additional files for your project
10 Click on next and choose whether package in single cab or multiple cab file and click on next
11 Then specify the title to the project click on next
12 Specify the shared for the project
13 Now specify the setup script name
14 And click on finish button to finish the wizard now you setup is ready for deployed
When you click the Finish button, the package will be created and ready for distribution. Here
are the packaged files for the start program for download at Setup.exe
SETUP.LST You must download all files into a folder and then run the setup program.
Q23.What are various control structures in VB? Give their syntax.
Ans.Select Control structure
(v.imp)
Control structure is used to control the flow of program's execution. Visual Basic supports control
structure such as If. Then, If. Then Else , Select .. Case and loop structure such as
Do While .Loop, Do Loop while and For Next method.
If. Then Else Statement
The If.. Then block is used for conditional execution of one or more statements.
If condition then
Statements
End If
The statement is executed only if the condition is true. The condition is usually a comparison, but
it can be any expression that evaluates a numeric value. If then Else block is used to define
several blocks of statements, in order to execute to one block. The following block of statement
illustrates if. Else.. End if statement.
If A =1 Then
Statements
Else
Statements
End if
The following example illustrates the If .. Then.. Else statement.
E.g.- Illustrate an example to check for the number of digits in a number and display a message
indicating the number of digits in it within 1000.
SUBJECT: VB
A new Standard EXE project is opened and a TEXT Box and Command Button is added to the
Form. The following code is entered in the Command 1_Click () procedure.
Private Sub Command 1_Click ( )
If Val (Text1. Text)<10 then
MsgBox " It is a Single Digit Number"
Else if Val (Text1.Text)<100 then
MsgBox "It is a two Digit number"
Else if Val (Text1. Text )<1000 then
MsgBox " It is a Three Digit Number"
Else
MsgBox " The value is more than three digits
End if
End Sub
The program is executed by pressing F5. When a number is entered in the TextBox, it displays a
message accordingly.
Select Case statement
Select . Case structure is an alternative to If. Then . Elseif for selectively executing a single
block of statements from among multiple blocks of statements. Select..Case is more
convenient to use than the If Else . End if .The following program block illustrates the working
of Select. Case
Select case index
Case 0
Statements
Case 1
Statements
End select
Select Case structure evaluates an expression once at the top of the structure, where as
If.ThenElseif evaluates different expressions for each Else If statement.
Do while. Loop statement.
The Do while. Loop is used to execute statements until a certain conditions is met. The following
do loop counts from 1 to 100
counter =1
Do while counter <101
SUBJECT: VB
Counter =counter +1
Loop
The variable counter is initialized to 1 and then the Do While loop starts
Do.. Loop While Statement
The Do . Loop While statement first executes the statements and then tests the condition after
each execution. The following program block illustrates the structure.
Counter =200
Do
Text1. Text=Str (counter)
Counter =counter +1
Loop while counter <501
The program executes the statement between Do and Loop While structure in any case. Then it
determines whether the counter is less than 501. If so, the program again executes the
statements between Do and Loop While else exits the loop.
Do . Loop Until Statement
The Do.. Loop until structure executes the statements until the condition is satisfied. It is an
infinite loop if the test fails and to get released from this infinite loop we can use the
CTRL+BREAK combination or End from the Run menu. The following code entered in the
Form_Load () procedure illustrates the structure.
E.g. Private Sub Form _Load ( )
Do
X$ =Inputbox $ ("Password Please ?")
Loop Until X$ ="Vanilla Orange"
End Sub
The above example checks for the password set to open the Format runtime. At run time it asks
for the password and until it is entered as "Vanilla Orange" the loop remains infinite. Once the
correct password is typed in the input box and clicked OK, the Form is opened.
The For .Next Loop Statement
The For . Next Loop is another way to make loops in Visual Basic. The following loop counts
from 1 to 50.
for I =1 to 50 step 1
Text1. Text =Str (I)
SUBJECT: VB
Next
In order to count from 1 to 50 in steps of 2, the following loop can be used . :
For 1=1 to 50 step 2
Text1. Text =Str (I)
Next
The loop counts as 1,3,5, etc.
Exit For and Exit Do statement
A For .Next loop can be terminated
statement block.
For I= to 100
Text1.Text =Str (I)
If 1=50 Then
Exit for
End if
Next
The proceeding code increments the value of I by 1 until it reaches the condition
I =50. The
Exit for statement is executed and it terminates the For Next loop. The following statement
block containing Do While loop is terminated using Exit do statement.
I=1
Do while I<1001
Text1. Text <1001
I=I+2
If I>500 then
Exit Do
End if
Loop
With End With Statement
When properties are set for objects or methods are called, a lot of coding is included that acts on
the same object. It is easier to read the code by implementing the With-End with statement.
Multiple properties can be set and multiple methods can be called by using the With End With
Statement. The code is executed more quickly and efficiently as the object is evaluated only
once. This concept can be clearly understood with the following example.
With Textprice
SUBJECT: VB