Sunteți pe pagina 1din 38

SUBJECT: VISUAL BASIC

Page:
Page:1

Q1. What is an event driven programming?


Ans.
In event driven programming the flow of program execution is controlled
by the events that occurs as the 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 then take the
appropriate action based on its own instructions for dealing with that particular
message.
Events can be triggered by users actions, by messages from the system or other
application, or even from the application itself. The sequence of these events
determines the sequence in which the code executes. Thus the path through
applications code differs each time the program runs.
Q2. Differentiate between a variable and a constant.
Ans.
Constant is a meaningful name that takes the place of a number or a
string that does not change. Variable is a placeholder in memory. Value of the
variable can be modified.
Q3. Give the syntax of for loop in VB.
Ans.
For variable = start to end step value
Statements
Statements
Next
For example
For I = 1 To 10 Step 1
Print I
Next
Q4. What is a form in VB?
Ans.
A form is a window that contains an application code and has other
objects placed on it to create the user interface. A form may fill the entire screen
or have other forms contained within it or it may be a custom dialog box.
Q5. What is the difference between label and caption?
Ans.
Label is a control, which is used to display the text on the form.
Caption is the property of an object. It will also show the text, which is assigned to
caption property.
Q6. When will you use combo Box?
Ans.
Combo box is required when we want to show a list of items on form. It
will show a list from which we can select one item.
Q7. Give any two advantages of VB?
Ans.
We can develop graphical user applications.
It can be attached with any database.
Q8. Why should you change the control name from its default value?
Ans.
Default names assigned by the program to the controls have a number
following the name of the control. It is original practice to change the name of
control according to its respective usage in the application. It will also help in
proper documentation.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:2

Q9. What is the difference between a decision statement and a looping


statement?
Ans.
Decision-statement is used to check the condition and then to execute
a group of statements if condition is true. The decision statement executes a
group of statements once whereas looping statement is used to execute a group
of statements more than once till the condition is true.
Q10.
Differentiate between a check box and an option button.
Ans.
More than one check box can be checked in an application, whereas in
case of option buttons only one from a group can be selected.
Q11.
What is difference between Now and Time function?
Ans.
Now function retrieves date and time whereas Time function retrieves
time only.
Q12.
Explain the visual basic program development process.
Ans.
First step in creation of a VB program is to add project. From New tab
choose the project template.
After choosing the project type, add forms in your project. Set the properties of the
form. Third Add controls on the form and set their properties. If it is simple forms
then use the menu editor to define the menu bar.
Define the code of controls for the action events. Add module if necessary.
Save forms and project. Set the default form to run.
Q13.
What is the purpose of Visual Basic file types?
Ans.
Different file types are used for different purposes in VB. Programmers
can know from the extension of the file that which file meant for what purpose.
.VBP: It is the extension of Visual Basic Project File. It is a collection of Forms,
MDI Forms, Class and Modules etc.
.FRM: It is the extension of Form where we can place controls
.BAS: It is the extension of Class file.
.OCX: It is the extension of ActiveX Control File, used to make user controls.
Q14.
What is a Combo Box? Name 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 box
combines the features of a Text box and a List Box. The three styles of combo
box are
Dropdown Combo

Simple Combo

Dropdown List
Q15.
What is difference between linking and embedding?
Ans.
Data associated with a linked object is stored by the application that
supplies the object. This application stores only a link reference that displays a
snapshot of the source data.
When an embedded object is created all the data associated with that object
is contained in the object.
Q16.
What is the purpose of a toolbar in an application?

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:3

Ans.
It contains several controls that are used to place on a form at design
time there by creating the user interface area.
Q17.
Which control is used to draw circles on the form?
Ans.
Shape control is used to draw circles.
Q18.
Write down the various kind of Data type in Visual Basic and how
much memory it will occupy in the main memory.
Ans.
Integer 2 bytes
Long 4 bytes
Single 4 bytes
String
1 byte
Byte 1 byte
Date 8 bytes
Variant 16 bytes
Double 16 bytes
Q19.
Write down various inbuilt functions with example.
Ans.
These functions are procedures that return a value. Three categories of
these types of functions are: Date and Time function
Format function and
String function
Date and Time functions: Date and time are internally stored in visual basic. The
systems current date and time can be retrieved using now, date and time
functions in VB i.e
Year (NOW), Month (Now), Day (Now),Datediff function returns the interval
between two dates in terms of years , month or days.
Format functions
The format function accepts numeric values and converts it to string, in the format
specified by the format argument.
Format (expression [, format [, firstdaydayof week]])
String Function
VB string functions can manipulate strings in application.
Strcmp()- Compare two strings
Len () -find the length of string
Lset(),Rset() - justify the string
Q20.
Write down various list controls.
Ans.
List box and Combo box:
List and Combo box controls are used to present a set of choices that we want to
display vertically in a single column. If the number of items exceeds the value that
can be displayed, scroll bars will automatically appear on the control.
Q21.
What are exit for and exit do statements?
Ans.
Exit for and Exit do statements are used to terminate the loop before
normal termination of loop.
Q22.
What do you mean by focus or control focus?
Ans.
The focus or control focus is the currently selected control. Visual
Basic indicates the control with the focus by highlighting the control.
Q23.
Explain the checkbox control?
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:4

Ans.
A check box control is used to offer an option to the user. It is an option
on the form that is checked when selected and unchecked when not selected.
Use a checkbox control when you want to offer the user two or more choices.
Q24.
Write a note on input box function.
Ans.
The input box () function displays a modal dialog box that asks the user
to enter some data. The dialog box contains a message, an OK button and a
Cancel button. The first parameter of the input box () function is the message of
the dialog box and the second parameter is the title of the message box.
e.g.
n = input (Enter your name,name please)
Q25.
Write the syntax of if then else statement in VB.
Ans.
The ifthen block is used for conditional execution of one or more
statements.
If (condition) then
Statement1
Statement2
End if
Q26.
Write syntax of select case in VB.,
Ans.
Select. Case structure is an alternative to ifthen..else structure. It is
used for selectively executing a single block of statements from multiple blocks of
statements. Select. Case is more convenient in use than if else end if,
because it reduces the program complexity. It makes the program easy to read
and follow.
Select case index
Case 0
Statements1
Statements2
Case 1
Statements1
Statements2
End case
Q27.
Describe the various mouse events.
Ans.
The main mouse events are mouse down, mouse up and mouse move.
The mouse down event occurs when the user presses any mouse button and the
mouse up event occurs when the user releases any button. The mouse move
event occurs whenever the mouse pointer is moved to the new point on the
screen.

Q28.
Write a short note on Combo box control and its different types.
Ans.
A combo box combines the features of a text box and a list box. This
control enables the user to select an item either by typing the text in the combo
box or by selecting an item from the list.
Different types of combo box are1.
Dropdown combo (style 0)
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:5

2.
Simple combo (style 1)
3.
Dropdown list (style2)
Private sub form _load ()
Combo1. Add Item "MCA"
Combo1. Additem "PGDCA"
The add item method is used to add values to the combo and list box controls.
Q29.
Write a note on IDE.
Ans.
IDE is integrated development environment, which is commonly used in
the programming 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.
Q30.
Write down the various elements or components of IDE.
Ans.
Main elements or components of IDE are:

Menu bar

Tool bar

Project explorer

Properties window

Toolbox

Form Designer

Object Browser
Q31.
Discuss briefly about the show method.
Ans.
The show method is used to display the form object.
e.g, form1.show
Q32.
Discuss briefly about the unload statement.
Ans.
The unload statement removes the form from the display and releases
its memory. The following code should be enteredUnload form 1
Q33.
Write an applicable program by using text box and command
button.
Ans.
Private sub command 1_click ()
Text1. Text="This text box is locked"
End sub
The following code is entered in the command 2 buttons.
Private sub command2_click ()
End
End sub
Q34.
Write an application by using Hscroll bar.
Ans.
Private sub cmdexit_Click ()
End
End Sub
The following code is entered in Hscrolls Change event
Private sub HScroll_Change()
Text1.Text=Str(HScroll1.Value)+"mph"
End sub
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:6

The following code is entered in Hscrolls Scroll Event


Private sub HScroll_Scroll ()
Text1_Change
End sub
Q35.
Write a code in Visual Basic to draw a box using graphic method.
Ans.
Line (600,600) Step (1000,0)
Line walk (0,10000)
Line Step (-1000,0)
Line Step (0, -1000)
Q36.
Differentiate between procedural programming and event driven
programming.
Ans.
Events are the various things that
can happen in a program. In a procedural language, a written application is
executed by checking the statements logically one after the other. But in event
driven application the program statements are executed only when a particular
event calls a specific part of the code, which is assigned to that event. e.g. Text
box events are change, click, mouse move etc.
Q37.
What are the various startup positions of the form in the VB?
Ans.
Startup position property is used to set the position of the form when it
gets displaced on the screen. Various options are:
0.
Manual
1.
Center owner
2.
Center Screen
3.
Windows default
Q38.
Explain the two tabs of the property window?
Ans.
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.
Q39.
What are various types of list box controls used in visual basic?
Ans.
List box control is used to display a list of the items. The items can be
added to the list box control both, at design as well as at run time. Following types
of list box controls are provided in visual basic, which can be used or set through
its style property.
0Standard.
1 - Checkbox
Q40.
What is the one major difference between a list box control & a
combo box control?
Ans.
One major difference between a list box & a combo box control is that in combo box the user can enter its own items whereas in list box control a user
has to select the item only from the list provided & the user can not enter its own
items in the list.
Q41.
Write three important properties of command button.
Ans.
Three important properties of command button are Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:7

1.
Name: The name property of the command button will be used in the
code window while programming any event on the command button.
2.
Caption: Caption property sets the caption of the command button which will be
displayed on the button e.g. O.K.,Cancel,Yes,No etc.
3.
Enabled: This property is either true or false. If it is true then the user can click
the button other wise if it is false then the user is unable to click the button.
Q42.
Explain the difference between implicit & explicit declarations.
Ans.
In visual basic, there are two types of declarations implicit & explicit. In
visual basic, you cannot to declare a variable and if Visual Basic comes across an
undeclared variable, then it declares that variable automatically of type variant.
Such declaration of variable is called implicit declaration.
Another type of declaration is explicit declaration where declaration of variables is
must. Here variable is declared by Dim statement followed by variable's name and
type e.g.
Dim meters as integer
For explicit declarations, statement option explicit should be written on top of the
form.
Q43.
Explain the difference between Access keys & Shortcut keys.
Ans.
Access Keys
Shortcut Keys
1. Access keys start with the alt 1. Shortcut keys start with
key
the ctrl key
2. Access keys are designated
2. Shortcut keys are to be
by putting '&' sign before the selected from the Menu
letter.
editor.
3. If designer doesn't designate 3. There is no such rule for
any access key then VB uses shortcut keys
the first character as Access
key.
4. Access keys can be defined Shortcut keys are only
for command buttons, menus defined for menus.
etc.
Q44.
Write four important properties of listbox control.
Ans.
Four important properties of listbox control are:
1.
List (): This property contains all the elements in the list
2.
List count: This counts the number of items in the list.
3.
Sorted: By setting this property to true, items in the list are always
sorted.
4.
Style: This property determines the appearance of the control
Q45.
List three file controls used in visual basic?
Ans.
Three file controls used in Visual Basic are
1)
DriveList box: Displays the name of the drives within & connected to PC
2)
DirList box: Displays the folders of the current drive.
3)
FileList Box: Displays the files of current folder.
Q46.
Why Dim statement is used in visual basic?
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Ans.

Page:
Page:8

Dim statement is used in visual basic to declare a variable.


e.g. Dim a as Integer
Above statement declares a variable 'a' of the type integer.
Write a note on variable naming conventions used in visual basic.
Following are the few naming conventions used while declaring

Q47.
Ans.
variables.
1.
It must begin with a letter.
2.
Can't contain an embedded period or any of the keywords.
3.
Must not exceed 255 characters.
Must be unique within its scope.
Q48.
Define Event.
Ans.
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.
Q49.
How is secondary form added to an active object? How is it
removed?
Ans.
To add secondary form- select project menu -> select add form option.
To remove the secondary form from the project, right click on the form icon in the
project explorer window and select remove form the popup menu.
Q50.
How secondary form is made visible when it has been loaded?
How is it made hidden?
Ans.
We can make the form visible at load time by specifying the visible
property of the form as true.
To make the form hidden at runtime we have to use the method formname.hide.
Q51.
How the values to the properties of the controls are assigned in
VB?
Ans.
To set the properties at design time select the control and set properties
using the property window.
Q52.
How a control is removed from the form design window?
Ans.
To remove a control from the form design window select the control and
then press the delete key from the keyboard.
Q53.
What is the purpose of the list index property? Which control
supports this property?
Ans.
List index property is used to find the index of the selected item in the
list. This property is used with the list box control.
Q54.
For what type of applications the timer control is intended?
Ans.
Timer control is used to call the subroutine or function again and again
after a specific period of time. We can also call a specific code again and again
after a specific interval.
Q55.
Suggest three different uses of a scrollbar.
Ans.
Scrollbar are used for the following purposes.
1.
These are used to navigate the document.
2.
By making changes in the value property of the scrollbar control we can
modify the value of the scroll bar.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:9

3.
Scrollbars are also useful for changing the border size and shape of the
shapes.
Q56.
Briefly describe the difference between the Design and RUN mode.
Ans.
Design mode-In this mode the controls are added to a project, their
properties set & the relevant code is written.
Run mode-In this mode we examine our program in action just as the user
will see it. Here property settings can be changed by a programs code. This is
accomplished by writing a special kind of assignment statement that gives a new
value to a specific property of a selected object.
Q57.
How can you declare a variable in VB? Explain with example.
Ans.
In vb the variables can be declared as1. Implicit
2. Explicit
1.
Implicit: - In implicit declaration, variables are automatically declared as
type variant whenever they are used in the application.
e.g a=10
2.
Explicit: - In explicit declaration, variables must be declare before the their
use otherwise vb interpreter will generate an error.
e.g dim a as integer
a=10
Q58.
What is the role of a LABEL control and a TEXTBOX control in VB?
Ans.
Label is a static text control in vb. Text of the label cannot be modified
at runtime.
TextBox control is an editable text control. We can set or edit the values of this
control at runtime
Q59.
What are the various properties that any control can have?
Ans.
Various controls can have the following properties1. Name 2. Height 3. Width 4. Top 5. Left 6. Enabled 7. Visible
Q60.
What is the purpose of a toolbar in an application?
Ans.
Toolbars are used in an application to make the life of an user easy
because then there is no need to open the instruction from the menu. User can
directly execute the instruction by selecting the tool from the toolbar.
Q61.
Name the component of visual basic IDE.
Ans.
Components of visual basic IDE are.
1. TITLE BAR 2. MENU BAR 3. TOOLBAR 4. TOOLBOX. 5. PROPERTY
WINDOW 6. CODE WINDOW. 7. PROJECT EXPLORER WINDOW.
Q62.
What are the two major components within the visual
programming development system?
Ans.
The components of visual basic IDE are very helpful to develop a good
application.
The two major components of VB IDE are the form and the code window. Without
form user cannot use any control in vb. To make any control interactive, code
window is needed. In code window we can code the event for any controls.
Q63.
What is an event? What is an event procedure?
Ans.
Event is an action performed on the component. An event procedure
can contain the code that will be executed when a specific action is performed on
a specific component.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:10

Q64.
What is a form in visual basic?
Ans.
Form is an interface between the user and the application. A user can
interact with an application with the help of a form. A form contains a number of
sub objects that helps in interacting with the user.
Q65.
Name some of the controls which feature OLE drag and drop.
Ans.
Most of the control in VB provide the OLE drag and drop feature. Some
of these controls are1.
List 2. Combo 3. Textbox 4. Image 5. Picture etc.
Q66.
Explain in brief the difference between Image Control and Picture
Control.
Ans.
Image Control: Displays Bitmaps, Icons, JPEG or Gif files and act like
a command button when clicked.
Properties:

Name: Sets the name of the control.

Picture: You can add the graphic by setting the picture property.

Stretch: This is a Boolean property means it can take only two values
either true or false. By setting this property to true the inserted pictures size could
be controlled.
Picture Box: This control is also used to Display Bitmaps, Icons, JPEG or Gif
files. This control does not have a stretch property like Image Box. It requires less
memory than image box.

Q1.
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.
The Option Explicit statement can be explicitly placed in the general declaration
section of each module using the following steps.
Q2 Write down the names of different controls and their purpose.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:11

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.

CommanButton 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.
Q3. Differentiate between Properties, Methods and events.
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:

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.


Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:12

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 hide 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,
ect.

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.
Q4. 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:

Menu bar: - It contains different types of menus and a group of similar


type instructions are store in a single menu.

Tool bar :- 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.

Project explorer :- it contains the list of forms, module and class


modules used in the project window

Properties:- It contains the list of properties for the selected control.

Toolbox :- It contains all the implicit controls used in VB.

Form Designer :- here we can design the form for vb project.

Object Browser :- It allow the user to browse through the various


properties, events, and methods that are made available, or exposed to the user.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:13

Q5. What is visual basic? From which language is it derived?


Ans.
Visual basic is an object-oriented language, which provides graphical
user interface just like Microsoft windows. Visual basic provides integrated
development environment. Visual basic provides three editions i.e. Learning
edition, professional edition & enterprise edition. Visual basic integrated
development environment provides editor, designing, compiler & debugging
capabilities. Visual basic provides Internet features, object linking and embedding
& various other capabilities to develop robust windows applications.
Visual basic applications provide excellent user interface & VB developer is
capable of being connected to various databases. Visual basic is derived from the
language Basic.
Q6. 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.
Q7. 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.
Q8.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:14

F = rec (x 1)
Rec =f
End If
Q9. 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 excel spreadsheets in your
VB applications. OLE container control hides all the complications of OLE from the
user & you can build OLE-capable applications.
Q10.
What do you understand by transactions?
Ans.
Transaction is a database terminology and it is a sequence of alterations
made to a table in the database. Transactions can be simply stated as any
changes made to the database tables. In visual basic we can make transactions in
the database with the help of various controls like DAO, ADO etc. We can create
record sets in VB with which we can manipulate the database tables. Visual basic
can store all the transactions that it is making, so that if there is any need then we
can undo them. There are three statements in VB namely BeginTrans,
CommitTrans, RollBack. BeginTrans makes the log of each & every transaction so
that at later stage we can undo them.
CommitTrans commits the changes to database. RollBack roll backs or undo the
changes made in the database.
Q11.
Discuss timer control with suitable example.
Ans.
Timer control is used to fire on event at specified internals 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
Me. caption = The timer has been fired & str (counter)& times!
End Sub
Q12.
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.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:15

Ans.
DIM MaxID as integer
Private Sub and Add_Click ()
If MaxID =0 then MaxID =1
If MaxID >8 then Exit Sub
MaxID = MaxID +1
Load optbutton (MaxID)
Opt button (O). 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
Q13.
Explain Scrollbar & Slider controls.
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.
Q14.
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 ()
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:16

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
End Sub
Q15.
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)
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:17

Labels (I).Visible = True


Textboxes (I).Visible = True
Next
End Sub
Q16.
Write about salient features of VB.
Ans.
Some features of VB are
1.
Full set of objects. So that we can design the application
2.
Lots of icons and pictures to use.
3.
Response to mouse and keyboard actions
4.
Clipboard and printer access.
5.
Full array of mathematical, string handling, and graphics function.
6.
Can handle fixed and dynamic variable and control arrays.
7.
Sequential and random access file support
8.
Useful debuggers and error handling facilities.
9.
Powerful database access tools.
10.
Activex support
11.
Package & deployment Wizard makes distributing applications simple.
Q17.
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.
Used to subtract two values
*
Used to multiply the two numbers.
/
Used to divide two numbers
\
It is integer division operator.
Mod
Used to find modules
Relational operators
<
less than
< = less than or equal to
>
greater than
> = greater than or equal to
=
to compare equality
!
Not equal to
Logical operators

String conciliation

AND, NOT, OR
String conciliation -------&
Q18.
Write the enhance comments of VB 6.0 over VB 5.0.
Ans.
Visual Basic 5.0 released in late 1996. New environment supports
creation of Active x controls. Deleted 16-bit application support.
VB 6.0 includes new features:

Faster compiler

New Activex data control object

Allows database integration with wide variety of applications

New data report designer.


Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:18

New package & report designers

Additional Internet capabilities.


Q19.
Explain the visual basic program development process.
Ans.
First step in creation of a VB program is to add project. From New tab
choose the project template.
After choosing the project type, add forms in your project. Set the properties of
form. Third step - Add controls, if it is a simple form, then use menu editor to
define the menu bar. Now add controls on the form and set their properties.
Define the code of controls for the actions events. Add module if necessary.
Save forms and project. Set the default form to run.
Q20.
What is use of static variables?
Ans.
You can preserve the value of a local variable by making the variable
static. Static keyword is used to declare the variable as static.
For example.
The following function calculates a running total by adding a new value to the total
of previous values stored in the static variable named Applesold:
Function RunningTotal (num)
Applessold= Applessold + num
Running Total= Applessold
End function
If Applessold was declared with DIM instead of static, the previous accumulated
values would not be preserved across calls to the function and the function would
simple return the same value with which it was called.
Q21.
Define constant and its sources.
Ans.
A constant is a meaningful name that takes the place of numbers or
string that does not change. Although constant some what resembles a variable,
you cant modify a constant or assign a new value to it as you can to a variable.
There are two sources for constants:
Intrinsic or system-defined:
These constants are provided by applications and controls
Visual Basic constants are listed in the visual Basic (VB) and Visual Basic for
applications (VBA) object libraries in the object Browser. Other application that
provide object Libraries also provide a list of constants you can use with their
objects, methods and properties. Constants are also defined in object library for
each Active X control.
Symbolic or user-defined constants are declared using constant statement.
Q22.
Write a program to authenticate user/password pair.
Ans.
Make a project using standard.exe.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:19

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
2.
Local
1.
Global: - 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: - 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 = ""
n = Text1
While n > 0
s = n Mod 2
Text2 = Text2 & s
n = Int(n / 2)
Wend
Text2 = StrReverse(Text2)
End Sub
Private sub cmdoct_click()
Text2=oct(text1)
End sub
Private sub cmdhexa_click()
Text2=hex(text1)
End sub
Q25.
Write a function subprogram to covert the temperature provided in
Fahrenheit to Celsius.
Ans.
Public Function ftoc(f As Double) As Double
ftoc = 5 / 9 * (f - 32)
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:20

End Function
Using the following statements we can call that function on click of a command
button
Private sub command1_click()
Dim f a double
f=inputbox(enter Fahrenheit)
msgbox ftoc(f)
End sub
Q26.
Write an application that will put a new Textbox control on the
form every time you click the command button?
Ans.
Dim i As Integer
Private Sub Command1_Click()
i=i+1
Load Text1(i)
Text1(i).Visible = True
Text1(i).Top = Text1(i - 1).Top + Text1(i - 1).Height
End Sub
Private Sub Form_Activate()
i=0
End Sub
Q27.
Create a project that contains a picture box and two buttons
labeled smile and frown. The smile button will display a happy face in the
picture box and frown will display a sad face. Use graphics methods to draw
the two faces.
Ans.

Private Sub Command1_Click()


Picture1.Cls
Picture1.FillStyle = vbSolid
Picture1.FillColor = vbYellow
Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2), 500
Picture1.FillColor = vbRed

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:21

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
Private Sub Command2_Click()
Picture1.Cls
Picture1.FillStyle = vbSolid
Picture1.FillColor = vbGreen
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 + 300), 200, 0,
3
End Sub
Q28.
Briefly describe the difference between the design and run mode.
Ans.
The VB provide two types of modes for an application. These modes
are
1.
Design mode
2.
Run mode
1. Design mode: - When a form is opened in this mode then we can place
different controls that we want, on the form. These controls then appear on the
form at run time. If we want that some the drawn controls must appear on the
form, but we do not want them to work. Then we can specify the disable property
of these controls at design time as False. Some of the properties of controls those
we can not specify at run time these can be specified at design time. At design
time using form layout window we can also position the form for the run time
appearance. Shape and line control doesnt provide any event so it is normally
used at design time.
2. Run mode: - this mode specify the codes that will execute when we run the
form. In which we can specify the control position according to form size at
runtime. The code for events those 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:
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:22

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 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.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:23

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.
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.

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.
Q32.
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.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:24

Graphical User Interface


Multiple UI
ActiveX Control Provision
Q33.
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.
Q34.
What is the Purpose of Toolbar? How does a menu vary from a
toolbar?
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.
Q35.
What are the benefits of building applications for components?
Ans.
Components are the main elements of VB applications. VB components
are divided into the following categories.
1.
Modules 2. Methods 3. Events 4. Controls
All are useful to develop good component application. Building of an application
for components, provide the following methods.
1.
Once a component is designed and coded it provide more interaction than
the character-based program.
2.
Any user can interact with components because components raise events
when any action is preformed on component. These different actions can manage
only in component-based programming.
3.
After developing a component, it can be reused in different softwares, so it
provides reusability.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:25

Q36.
Distinguish between static and dynamic page.
Ans.
A web site contains both the static and dynamic web pages. Both are
needed to develop to good application.
Static pages: - Static pages are those pages, which provide static information
means, which can not be modified or changed at runtime. They do not response
the query of client at runtime. These pages are only view able for different users.
Dynamic pages: - Dynamic pages of the site provide more user interaction. To
convert any static page to interactive, scripts are used for both client side and
server side. Server side Technology (ASP) is also used to make interactive web
pages. Any user can pass different types of queries and web pages respond
according to the users query.
Q37.
Write VB code to place colored dots randomly on the form.
Ans.
Place a timer control on the form and set interval to 5.
Specify the following code in the form.
Dim i As Integer
Private Sub Form_Load()
i=0
End Sub
Private Sub Timer1_Timer()
For j = 1 To Rnd * 100
Me.Circle (Rnd * Me.ScaleWidth, Rnd * Me.ScaleHeight), 1, QBColor(i)
Me.Circle (Rnd * Me.Width, Rnd * Me.Height), 1, QBColor(i)
i=i+1
If i > 14 Then
i=0
End If
Next
End Sub
Q38.
What are various control structures in VB? Give their syntax.
Ans.
Select Control structure
Control structure are 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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:26

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.

A new Standard EXE project is opened and a TEXT Box and


CommandButton 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
Counter =counter +1
Loop
The variable counter is initialized to 1 and then the Do While loop starts
Do.. Loop While Statement
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:27

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)
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 by an Exit For statement . Consider the
following statement block.
For I= to 100
Text1.Text =Str (I)
If 1=50 Then
Exit for
End if
Next
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:28

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
. Font. Size =16
. Font. Italic =True
. Height =235
. Text="Welcome to Visual Basic6.0"
End with
In the above coding, the object Text price (The Name property of Textbox has
been changed to text price) is evaluated only once instead of being evaluated for
every associated property or method. This makes the coding simpler and efficient.
Q39.
(a) Explain various data types available in VB.
Ans.
Data types available in VB
Data
Memory
Range
type
(Bytes)
Byte
1
0 to 255
Integer
2
-32,768 to +32767
Long
4
-2147483648 to 2147483647
Single
4
-3.402823*103 to 1.401298*1045 for
negative values
1.4401298*10-45 to 3.402823*1038 for
positive values.
Double
8
-1.79*10308 to 4.94*10-324 for negative
values
4.94*10-324 to 1.79*10308 for positive
values
Currency 8
-922,337,203,685,477.5808
to
922,337,203,685,477.5807
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Boolean
Date
String
Variant

2
8
1
16

Object

Page:
Page:29

True or False
January 1, 100 to December 31, 9999
0 to approx. 2 billion character.
A general-purpose variable that can hold
any type of variable values.
A variable declared as an Object can
have any object reference assigned to it.

(b) Explain various relational and logical operators in VB.


Ans.
Operators are symbols used in an expression to perform operations on
the operands. There are different types of operators in VB.
Relational operators
<
Less than
< = Less than or equal to
>
Greater than
> = Greater than or equal to
=
To compare equality
<> Not equal to
less than(<) : return true if first value is less than second.
Less than or equal to (<=): return true if first value is less than or equal to the
second
greater than (>) : return true if first value is greater than second
greter than or equal to (>=) : return if first value is equal to or greater than second
equal to (=) : return true if both values are equal
not equal to(<>) : return true if one value is not equal to the second
Logical operators: - Logical operators are used to combine the result of two
expressions to a common result. These operators are
1.
AND 2. OR 3. NOT
1.
AND: - It combines the result of two expressions. If the result of both the
expressions return true then the result of AND is true else false.
2.
OR :- If one of the expression produce true result than the result of or is
true
3.
NOT :- to create complement of the expressions result.
Q40.
Write a program that reads in the radius of a circle as an integer
and print the circle diameter, circumference and area on the form using
print method.
Ans.
Place a command button on the form and do the following code in the
code window
Private Sub Command1_Click()
Dim r As Integer
Dim d As Integer
Dim cf, a As Double
r = InputBox("Enter radius")
d=2*r
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:30

cf = 2 * 3.142 * r
a = 3.142 * r * r
Print "Radius
:", r
Print "Diameter
:", d
Print "Circumference :", cf
Print "Area
:", a
End Sub
Q41.
WAP that prints 100 asterisks to the form one at a time. After
every tenth asterisk your program should print a line break.
Ans.
Place a time control on the form and its interval property to 100.
Timer1.interval=100
Write the following code in the code window
Dim i As Integer
Dim j As Integer
Private Sub Form_Load()
i=1
j=1
End Sub
Private Sub Timer1_Timer()
Print "*
";
i=i+1
j=j+1
If j > 10 Then
Print
j=1
End If
If i > 100 Then
Timer1.Enabled = False
End If
End Sub
Q42.
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.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:31

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.
Q43.
What is a variant? What are the advantages and disadvantages
associated with the use of variants?
Ans.
Variant is a default data type. When you declare variables implicitly they
automatically got declared in VB, this data type is known as variant type in VB.
The variable declared as variant can hold the value of any type. The memory
space taken by the variant variable is 16 bytes.
Variant Type provides a number of advantages 1.
They can hold any type of values
2. It will automatically adjust and convert type accordingly to the value stored
into the variable.
3. Very useful, when implicit declaration is used in the program.
Disadvantages
1.
It automatically declares the variables, which are not declared explicitly in
the application, the use of these variables in the program, makes the program
more error prone. The errors caused by these variables are difficult to find.
2.
Another disadvantage of variant data type is that, it consumes more
memory spaces as compare to the other data types.
Q44.
Write a VB code in a click event of a Button to draw X across a
form by using line function.
Ans.

Private Sub Command1_Click()


Me.Line (Me.ScaleLeft, Me.ScaleTop)-(Me.ScaleWidth, Me.ScaleHeight)
Me.Line (Me.ScaleWidth, Me.ScaleTop)-(Me.ScaleLeft, Me.ScaleHeight)
End Sub
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:32

Q45.
Find the number of items in a combo box. How you will set the
item number of 2 top most items in the visible portion of the list box?
Ans.
Following program will count the number of items in the combo box and
will set the item number of 2 top most items in the visible area of the list box.
Using following steps.
1.
place one combo control,list control and two command buttons.
2.
add item in combo using the list property of the combobox
3.
Write the following code to count number of items in the combobox with
help of button.
Private Sub Command1_Click()
MsgBox Combo1.ListCount
End Sub
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

Q1. Describe difference between testing and debugging.


Ans.
Testing is the procedure to check the application if it is working properly
and according to the requirements specified before coding or not.
Whereas Debugging is the technique to find errors and removing them, so
that the application could work properly.
Q2. Differentiate between control array and control collection.
Ans.
Control array can contains number of controls but of same type
whereas the control collection can contain a group of controls of heterogeneous
type i.e. various type of controls could be the part of a control collection.
Q3. How will you define a menu hot key?
Ans.
Put the & sign before the letter whom you want to make the hot key, in
menu editor.
Q4. What is the name of two controls required for creating a toolbar?
Ans.
First is windows common control
Second is image control.
Q5. How form templates are useful while creating a toolbar?
Ans.
Template is used to choose the form type. For example- MDI form,
from.
Q6. Differentiate between MDI and SDI.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:33

Ans.
Single Document Interface is an application that can support only one
document at a time.
Multiple Document Interface allows you to create an application that maintains
multiple forms within single container form. An MDI application allows the user to
display multiple documents at the same time with each document display in its
own windows.
Q7. Explain immediate windows briefly.
Ans.
The immediate window is a window inside the visual basic environment
in which you can view program values and can print the message during the
programs execution.
Q8. What is native code and P-code?
Ans.
Visual basic used to produce executable program file in p-code i.e.
(pseudo code it is a technique for expressing operation of a computer program
or an algorithm in a natural language such as English. It was develop as an
alternative of a flow chart) rather than native code. But with the later versions of
visual basic the compiler started translating the visual basic, which people can
understand, into executable programs consisting of native machine code that
computer can read and understand.
Q9. What do mean by breakpoint?
Ans.
A breakpoint works as a marker in the code that tells the visual basic
where to suspend the program execution. Breakpoint is purely temporary in
nature means it is not stored permanently in the code.
Q10.
Explain the debug. print statement.
Ans.
This print method sends the output to the immediate window.This could
be done by including the following statement in the code
Debug. Print [item];
Q11.
What is an array .How to declare an array.
Ans.
A sequence of variable by the same name can be referred using arrays.
The individual elements of an array are identified using an index number.
e.g.-Dim salary (9) as integers
Q12.
List three important properties of a command button.
Ans.
Caption: This property specifies the text that appears on the command
button.
Picture: This property specifies a graphic image that appears on the command
button in place of caption.
Style: This property specifies whether a command button display a text caption or
picture.
Q13.
Ans.
1.
2.
3.
4.
5.
6.

Name the functions used to create menus with Bitmaps.


Functions used to create menu with bitmaps are:
GetMenu( )
GetSubMenu()
ModifyMenu( )
CreateCompatibleDC( )
CreateCompatibleBitmap( )
SelectObject( )
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:34

Q14.
What do you understand by term debugging?
Ans.
Debugging a program means correcting the errors in the program while
it is running. Immediate window is used help in debugging a program, which is
running in visual basic. Immediate window helps to display the values of the
program variables, change the value of the variables. During debugging, you can
insert statement in the code, change the value of variable and then continue
running your program
Q15.
Define the RGB( ) function.
Ans.
For defining colors, visual basic provides the RGB() function, which
accepts three arguments.
RGB (Red, Green, Blue)
With RGB() function, you can define any color. The red, green & blue
arguments accept values from 0 to 255. e.g. to change the background color. The
red, green & blue arguments accept values from 0 to 255 e.g. to change the
background color, you can write form1.backcolor = RGB (255,255,0).
Q16.
What is pop up menu?
Ans.
Pops up menus are also called context menu or shortcut menu that the
user can invoke by right clicking a form or control. This pop up menu is regular
menu & can be displayed anywhere on the form. Pops up menus are invoked with
the PopUpMenu method.
Q17.
Explain the difference between Modules & Class modules.
Ans.
Modules store variable declarations and code, which are available to all
the other components of an application. But if procedures are to be used for
several projects then class Modules are built.
Q18.
What is ReDim statement?
Ans.
Redim statement is used to define the size of an array dynamically at
runtime. This statement is used when we want to change the size of an array at
runtime.
syntax
ReDim FirstArray ( 4 to 12)
Q19.
What is the use of Preserve Statement in VB?
Ans.
Preserve statement is used with Redim statement to define array size
dynamically. Using the preserve keyword we can preserve the old values given to
the different memory elements of an array. while increasing the size with Redim.
Q20.
What is Step Into, Step Over and Step Out?
Ans.
The Step Into option is used to execute one line of code at a time. This
is handy when you want to continuously monitor your application as you go
through it line by line.
The Step Over option allows you to step over a procedure or function call
without having to single stepping through its individual lines of code.
The Step Out option moves the program execution back to the calling
procedure. This is the functional equivalent of Exit Sub or Exit Function. It simply
exits the current procedure without executing any more code in that procedure

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:35

Q21.
What is the difference between a drop-down menu and a pop-up
menu?
Ans.
Drop down menus show their options by clicking on the menus and we
can select one of the option from the list by just clicking on it. Whereas popup
menu appears by right click on the control to select the specified option from the
menu.
Q22.
How is an event procedure created, viewed or edited?
Ans.
Event procedures are created by using add procedure option of Tools
menu by opening code window. We can edit and view event procedures in code
window.
Q23.
What do you understand by control array?
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.
Q24.
What is syntax error and error handler?
Ans.
Syntax error appears when you misspell any instructions or variables.
Error handler is the mechanism used to find errors and to debug them. There are
different types of tools provided by vb to handle logical errors. Like -step into,
stepout, step over, immediate window, local window, watch window etc.

SUBJECT: VISUAL BASIC

Page:
Page:36

Q30.
What is the purpose of the input box button? How does the input
box function differ from the msgbox function?
Ans.
Input Box and message box both are modal dialog boxes. But the
message box dialog box is completely a message window that provides the user
message only whereas input box contains a textbox that can take data as input,
and then it produces the result on the basis of input data.
Syntax for Inputbox
Inputbox(prompt,title,defaultvalue,startx,starty)
Syntax for MessageBox
MessageBox(prompt,title,messageboxstsyle)
Q31.
How is the watch window opened with in the visual basic
environment?
Ans.
We can open the watch window by opening the forms code in debug
mode. Then select option watch window from the debug menu.

Q28.
How does a menu vary from a toolbar?
Ans.
Menus are the drop down instructions. These instructions appear
whenever we click on a specific menu whereas toolbar contains different type of
tools having specific instructions. And these instructions are execute by clicking.
Toolbar helps to visualize the instructions so that the user can easily understand
the purpose of the instruction.

Q32.
What are error codes? How can error codes be used with in an
error handler?
Ans.
Error codes are the specific numbers given to the specific errors. These
are helpful to set specific types of messages regarding the specific error.
Q33.
What is a modal form? How can a form be displayed as a modal
once it has been loaded?
Ans.
Modal forms are the forms that never transfer the control to the parent
form unless or until it is closed or unloaded. To display any form as modal just
specify the 1 in the show () method to the form
e.g
formname.show(1)
Q34.
What is a separator bar and how is it created?
Ans.
A Separator bar is a line, which separates the menu items. It is mainly
useful for obtaining clarity. In the Caption TextBox - is typed and assign name
like mnuSep in the Name TextBox. This adds a separator line, which is drawn
between the menu items.
Q35.
Write steps to create an MDI application.
Ans.
The Multiple Document Interface allows you to create an application
that maintains multiple forms within a single container form. To create an MDI
form and its child form use following procedure.
1.
Create MDI formby adding MDI form from project menu.
2.
Create the applications child form by setting forms MDI child property to
true.

Q29.
What is the purpose of a dialog box?
Ans.
Dialog boxes are used to provide information and to receive information
from the user at runtime. The dialog boxes are of two types.
Model and modeless
From model dialog box, the control cannot be transferred to the parent dialog box
without closing the dialog box whereas control can be transferred to the parent
dialog box without closing the dialog box in modeless dialog box type.

Q1. Write a short note on Procedure and their types.


Ans.
Procedure

Q25.
What is module and procedures?
Ans.
Module is the collection of procedure and variables. Procedures are
subroutine or function that can contain specific set of codes that will execute
whenever the procedure is called or specific event is fired.
Q26.
What single stepping is and how you use it to debug?
Ans.
Single stepping is the process to run code line by line. This is
accomplished by step into option use to find logical error in the debug process.
Q27.
What is the difference between subroutine and functions?
Ans.
Subroutine and function both are the types of procedures.
Using function we can return a value to calling function whereas nothing is
returned by subroutine to the calling function.

Prepared By:By:- Charanjiv Singh

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:37

SUBJECT: VISUAL BASIC

Page:
Page:38

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 paced in standard, class and form modules. 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.
Event Procedures
An event procedure is a procedure blook that contains the control's actual name,
an underscore (_) and the event name. The following syntax represents the event
procedure for a Form_Load event.

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 object.
Q3. Explain types of dialog boxes.
Ans.
There are three kinds of dialog boxes.
1)
Modal dialog box
2)
Modeless dialog box
3)
System modal dialog box

Private Sub Form_Load ( )


.. Statement Block ..
End Sub
Q2. 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.

Modal dialog box: - Model dialog boxes can be called as application modal dialog
box. This dialog box insists the user to respond to them, before continuing in the
same application. A modal dialog box can stop the running of your code until it is
being closed or being hidden. The show method of form uses VbModal style to
load the form as a modal dialog box. e.g.
Form1. Show VbModal.

Prepared By:By:- Charanjiv Singh

Modeless dialog box: - Modeless dialog box do not need to be closed to loose
their focus. They are just like any other form in your application and loose their
focus as soon as you click some other window outside the application. A form is by
default loaded in this state if no arguments are supplied to show method.
System modal dialog box: - A system model dialog box restricts the user from
continuing work on the system unless it gets unloaded. Screen saver with
passwords is example of system modal dialog box. The show method doesnt have
this style but in order to call a default message box in a system modal style, we
can use the following syntax.
MsgBox Message string , VbOkOnly + VbSystemModel.
Q4. Write a note on POP-UP menu.
Ans.
A popup menu is floating menu that is display over a form independent
of the menu bar. Popup menus are also called context menus, because the items
displayed in the pop up menu depend on where the pointer is located when the
right mouse button is clicked.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:39

Any menu can be display as a pop up menu at run time provided it has menu
item.
The following code displays the colours menu when the user clicks the right
mouse button over the form at run time.
Private sub_form_MouseDown (Button As Integer, Shift As integer, X As Single, Y
As Single)
If button =2 then
PopUpMenu mnuColors
End if
End Sub
Q5. Write a note on Dragging and Dropping.
Ans.
Dragging is the process of clicking the mouse button in a control and
moving the mouse while holding down the mouse button. The action of releasing
the mouse button after the dragging is called Dropping. The following dreg and
drop properties,events and methods are supported by VB DragMode property enables automatic or manual dragging of a control
 DragDrop event is recognized when control is dropped onto object
 Drag method starts or stops manual dragging.
Q6. Write a short note on common dialog boxes.
Ans.
A common work in most of the applications is to prompt user for
filenames, selecting files to open, saving the file on hard disk, font names & sizes
or colors to be used in applications. Common dialog control is peculiar & provides
services to the application but is not displayed on the form at runtime. Common
dialogs control provides built-in windows dialog boxes.
1.
Open - File open common dialog box lets user select a file to open.
2.
Save As - File save common dialog box lets users select or specify a file
name in which current document will be saved.
3.
Color - The color dialog box lets user select colors or specify custom
colors.
4.
Font - Font common dialog box lets user select font &style to be applied to
current text selection.
5.
Print - Print common dialog box lets user select and set up a printer.
6.
Help- help common dialog box displays help topics.
Q7. Explain immediate window.
Ans.
Whenever an application of VB is interrupted in run time by pressing Ctrl+Break, a window is shown at the bottom of the screen called immediate
window. When Visual basic commands are issued in this window, they execute
immediately with the help of immediate window, you can see the control flow of
the program & can work out which events are fired at what time. It is a debugging
aid & when an application is running, you can stop it and use the immediate
window to examine or change the values of the applications variables. You can
step into the code of the application while it is executing & can change the value
of the variables & can even insert statements in the code & then continue the
execution of an application.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:40

Immediate window can act as a calculator. For example if you enter following
statement in immediate window.
Print 1888/999 & press enter. The following result will be displayed1.889889889
Q8. Explain the following.
1.
Rnd function.
2.
Date function.
3.
Time function.
4.
Strcomp function.
5.
Instr function.
Ans.
Rnd function: - Rnd function generates random numbers that doesnt
follow any pattern. For example- If you write the following code in the form click
event.
Private sub form Click ()
Dim I as integer
For I = 1 to 5
Print Rnd
Next I
End sub
It will generate five random numbers between 0 & 1.
Date function: - Date function displays the system date eg.
Text 1. Text = Date
It will display the system date in the textbox.
Time function: - The time function will display the systems current time. eg
Text1. Text=Time
It will display system time in the text box.
Strcomp function: - This function can be used to compare strings. The strcomp
function will returns a value, such as for example
E.g.-If you set X=strcomp (A $, B $), then value of x is, 1 if A$ is less then B$, 0
if A$ equals to B$, 1 if A$ is greater than B$ and the value of x will be NILL if any
variable is empty.
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]
Q9. 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

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:41

save file that saves the contents of control on the disk and can load file that loads
the contents of file from the disk.
Q10.
Explain the terms passing by value & passing by reference.
Ans.
When you call a function or procedure, there are two ways to pass an
argument.
1.
Passing by reference.
2.
Passing by value.
When you pass an argument variable by reference, any changes to the
corresponding parameter inside the procedure will change the value of the
Original argument when the function or procedure finishes, when you pass an
argument by value, then original variable retains the original value even after the
procedure finishes. For example
Sub Triple (Num as Integer)
Num = 3 * Num.
Print I am in the procedure (pass by reference)
End sub.
Sub triple (BY Val Num as integer)
Num = 3*Num.
Print I am in the procedure (Pass by value)
End sub.
In visual Basic, passing an argument by reference is default. If we have to pass an
argument by value then we have to specifically mention the keyword By Val.
Q11.
What do you understand by term property pages?
Ans.
Active controls can have property pages. Property pages are similar to
the properties window and they allow the developer to set the controls properties.
Properly pages are better and have more flexible user interface.
The properties you set through the properties windows apply to the entire control
but the property pages of the control contain several pages on which related
properties are grouped. Property pages of a control can be displayed by Right
clicking the control & then by selecting properties from the pop-up menu .We can
design the property pages through the property page wizard.
Q12.
How an array can be passed to a function?
Ans.
An array can be passed to a function in two ways.
1.
By reference or by value of the elements when the function supports one
single argument only.
E.g.
Dim A(5) as integer
For x = 0 to 4
Print Sqrt ((x))
Next
2.
By reference when the function supports an array argument
Example.
Private function Fun (y () as integer) As Integer
Dim Z(3) as integer
For I = 0 to 2
Z (I) = Y (I) + Y (I)
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:42

Next I
Fun = Z
End function
Q13.
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 DirList
Box, DriveList Box & 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 all its
directories should be displayed in the DirListbox 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.
Q14.
Describe Menu Editor in VB.
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
Click the Menu editor button on the toolbar.
The two most important properties for menu controls are:
1.
Name: - This is the name you use to reference the menu control in the
code.
2.
Caption: - This is the text that appears on the control.
Q15.
Discuss the file handling facilities of VB.
Ans.
When we want to store data in visual Basic it can be in two forms: a
database or an ASC || file. ASC|| files contain data of all types and can be
formatted in a comma-separated values list; Three modes of files are1.
Sequential
2.
Random Access
3.
Binary
Sequential: - When you want to store or retrieve data in VB you may choose to
create a sequential file. A sequential file is a series of lines of text in ASC|| format.
Random access: - Random access also works to retrieve data from ASC|| 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.
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.
Q16.
Explain the menu creation through menu editor in visual Basic.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:43

Ans.
To design menu, click on the tools menu and then select Menu editor.
Menu editor dialog box will appear.
Enter caption property and Name property in the first two boxes of menu editor.
You can also choose a short cut key for the current menu control
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.
You can type a number in the index field to make the menu control array. These
are useful when you want to list like the ones you see at bottom of file menu in
various applications.
The help control ID field in 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.
Q17.
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.
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
Q18.
What are various types of modules used in VB?
Ans.
Visual Basic has three basic modules
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:44

Form module
Standard module
Class module.
1.
Form Module: Form module (.FRM file name extension) is the
foundation of the most visual Basic applications. They can contain procedures
that handle events. General procedures, and form level declarations of variables,
constant types and external procedure. The code that you write in a form module
is specific to the particular application to which the form belongs. IT might also
refer to other forms or objects within that application.
2.
Standard Module: Standard module has BAS extension. These are the
containers for procedures and declarations commonly accessed by other modules
within the applications. They can contain global or module level declarations of
variables, constants, external procedures, and global procedures. The code that
you write in standard module isnt necessarily tied to a particular application. A
standard module can be reused in many different applications.
3.
Class module: Its extension is .cls. These are used for object oriented
programming in VB. You can write code in class modules to create new objects.
These new objects can include their own customized properties and methods.
Q19.
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 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
Q20.
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
n = Input Box("enter number")
For i = 1 To 10
c=n*i
Debug. Print n, "*", i, "=", c
Next
Q21.
What modality is and how does it affect the behaviour 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 or not. There are two types of
dialog boxes.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:45

1 Modal
2.Modeless
1. Modal: - if the dialog box is of modal type then the control will not be transfered
to their master form until the necessary information has been ginen to the dialog
box or it has been closed. E.g of these dialog boxes are msgbox ,inputbox in VB.
2. Modeless: - if the dialog box are modeless type then the control can be
transferred to the master form without closing the dialog box. E.g of this type of
dialog box is find & replace dialog box.
Q22.
What do you understand by bug (error)? What are the different
types of bugs that you may encounter while programming with visual
basic?
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 bug: 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: 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 bug: Occurs when an application executes without syntax error or runtime 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.
Q23.
What are the common errors in the visual basic?
Ans.
In VB the error can be divided into the following category.
Syntax 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 a misspelled
variable.
Runtime error: 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 error encounters.
Logic Errors: Occurs when an application executes without syntax error or runtime errors, but the results are not what we intend. 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.
Q24.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:46

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
Q25.
Describe the basic concept of array handling in visual basic.
Ans.
Array is the group of elements with single or similar name and with
similar data type in continues memory locations. Concept behind defining the
array in vb is that it is difficult to manage a number of variables. But by using array
we can specify a number of variables in a single array variable, which are using
the same data type and can be given different values using the different index
values of an array. The following syntax is used to define the array in VB.
Syntax
Dim variable (upperbound) as datatype
e.g
dim rollno(5) as integer
In vb we can create the array of controls by defining the same control a number of
times in the form. This makes the control handling process easy. A single event,
which is common to all the controls, can be recognized by different controls
present in an array with their index numbers.
We can create the array of control by inserting the control on the form and then by
using copy and paste option at design time of the form.
Q26.
Explain DLL and immediate window.
Ans.
DLL Stands form Dynamic linking library. A DLL file is a file that
contains one or more functions and it is compiled, linked, and stored separately
from the processes using it. The operating system maps the DLLs into the
process's address space when the process is starting up or while it is running.
The process then executes functions in the DLL. In VB we can create DLL using
ActiveX DLL project.
Immediate window: - Show the immediate result of the calculation performed in
debug window. Print method of debug object is used to send the output to the
immediate window. So this window is a part of the debug process in VB which is
used to make the VB code error free. We can find result of an expression by
calculating directly in immediate window in break mode.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:47

Q27.
Explain the difference between SDI and MDI applications. Give
suitable example.
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 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

Single Document Interface Second Form

set firstform.mdichild=true
set secondform.mdichild=true
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:48

to change this interface to multiple document interface.


Q28.

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.
Syntex: 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.
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.
Q29.
Explain break mode.
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.
Q30.
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.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:49

A standard form can be distinguished


following differences.
STANDARD FORM
In a single project there are
number of standard forms
Standard form can become the
child of MDI FORM
We can place any type of
control on the standard form

SUBJECT: VISUAL BASIC

from a MDI form on the basis of the

MDI FORM
Only single MDI form is in the
single project
No MDI FORM could be the
child of standard form
On MDI form only menus,
toolbar
and runtime-hidden
control are place able. Like
timer control, common dialog
control etc.
To arrange the standard form MDI form can arrange its child
there is no property and method
forms in cascade and tiled style
with arrange method.
Q31.
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.
Component based design system has three different phases.
1. Component Design phase: In this phase the controls are placed on the form.
With proper orientation and alignment. Their properties are specified according to
the requirement using property window.
2.code phase: - In the code phase of the component design system. Programmer
will analyse the requirement of code and when the code will be executed and
appropriate event for that code will be handled in the code window.
3. Executing/Testing phase: -After the coding process, the source will be tested in
the testing/Execution phase by putting the dummy data on the components, if it
produce accurate results then they will finalize the source otherwise the debug
process will be performed to find the logical and syntax errors.
Design Phase

Code Phase

Testing /Execution phase

Debugging

Q32.
What is the difference between graphics methods and graphics
control.
Ans.
Graphics methods are useful to design any graphics object on the form.
There are graphics methods like
Circle :- Circle method is used to draw the circle on the form. It has the following
syntax
Sub Circle(Step As Integer, X As Single, Y As Single, Radius As Single, Color As
Long, Start As Single, End As Single, Aspect As Single)
Prepared By:By:- Charanjiv Singh

Page:
Page:50

Line :- Line methods is used to draw a line on the form we can also convert line to
rectangle. It has the following syntax
Sub line(flags As Integer, X1 As Single, Y1 As Single, X2 As Single, Y2 As Single,
Color As Long)
Graphics Controls :- There are different types of graphic controls provided by vb.
Like image control, picture box, shape control and line control.
Image control :- In image control we can load the image using load picture
method. We can specify the image size according to the image control using
stretch property.
Picture box: - picturbox control can also work as container for different graphics
objects and can appear like a canvas similar to the paintbrush window. But there
is no stretch property in this control.
Shape and line: - these are two controls those dont have any type of events.
Q33.
An Array Marks(40) contains marks of 40 students of a class. WAP
to count the number of students who scored more than 60 and who scored
below 33.
Ans.
Private Sub Command1_Click()
Dim MARKS(39) As Integer
Dim CM, CL As Integer
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
Q34.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:51

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 It can be added using add watch
break point option of the debug option of the debug menu
menu
It halts the execution of an It is monitored automatically by
application
and
gives
a the visual basic
snapshot to its condition at any
instant as the program is still
active
In break expression we can Watch expression is added into
check code using different the watch window and it force
the form to enter in a break
debug tools
mode where we can watch the
current result of the expression.

Q35.
Explain the creation of menu Through Menu Editor.
Ans.
To design menu, click on the tools menu and then select Menu editor.
Menu editor dialog box will appear.
Enter caption property and Name property in the first two boxes of menu editor.
You can also choose a short cut key for the current menu control
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.
You can type a number in the index field to make the menu control array. These
are useful when you want to list like the ones you see at bottom of file menu in
various applications.
The help control ID field in 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.
Q36.
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.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:52

Richtextbox1.loadfile commondialog1.filename
End sub
To open the same file in notepad select run option from the start menu than write
NOTEPAD in the text box click on ok.. Now select open option from the file menu
and open the same file.
Q37.
Explain in detail the use of Common Dialog Control available in
VISUAL BASIC.
Ans.
A Common work in most of the applications is to prompt user for
filenames, selecting files to open, saving the file on hard disk, font names & sizes
or colors to be used in applications. Common dialog control is peculiar & provides
services to the application but is not displayed on the form at runtime. Common
dialogs control provides built-in windows dialog boxes.
1.
Open - File open common dialog box lets user select a file to open.
2.
Save As - File save common dialog box lets users select or specify a file
name in which current document will be saved.
3.
Color - The color dialog box lets user select colors or specify custom
colors.
4.
Font - Font common dialog box lets user select font &style to be applied to
current text selection.
5.
Print - Print common dialog box lets user select and set up a printer.
6.
Help- help common dialog box displays help topics.
Q38.
What kinds of tools are available for aid in the debugging of vb
application? Explain each in brief.
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
respond 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.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:53

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.
Q39.
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.
ReDim New Array (Y+1)
The ReDim statement can appear only in a procedure , which is an executable
statement. The same way of declaration as used for fixed arrays is used for
declaring ReDim statements. ReDim is an executable statement. The lower and
upper limits for each dimension can also be specified explicitly as in the case of a
fixed size array. An example for this is given below.
ReDim FirstArray ( 4 to 12)
Each time on executing the ReDim Statement, the current data stored in the array
is lost and the default value is set. But if we want to change the size of the array
without losing the previous data, we have to use the Preserve keyword with the
ReDim Statement. This is shown in the example given below.
ReDim Preserve NewArray (Unbound (FirstArray) +1)
When the Preserve keyword is used, only the upper limit of the last dimension in a
multidimensional array can be changed. No other dimensions or the lower limit of
the last dimension can be changed.

Q1. What is MS flex Grid control? And why is it used?


Ans.
A MS flex Grid control in VB is used to create applications that present
information in rows and columns. It displays the information in cells. The user can
select a cell at run time but cannot change the contents.
Q2. What do objects of same class share?
Ans.
Objects of same class share all static members of the class.
Q3. What data binding is and how does it work?
Ans.
Data binding is the procedure of including code of other files, which are
actually not the part of current applications code. These are DLLs, which are
either predefined or made by the programmers.
Q4. Write a note on Msflexgrid.
Ans.
A MS FlexGrid control in Visual basic is used to create application that
presents information in row and columns. It displays the information in cell. The
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:54

user can select a cell at run time by clicking it or by using the arrow keys, but
cannot the edit or alter the cells contents. The MSFlexGrid control displays and
operates on tabular data. It is necessary that we add the MSFlexGrd.ocx file to
our project before we use a MSFLexGrid control in our application.
Q5. Define the term ADO.
Ans.
This is a programming model that eliminates the need to choose among
DAO and RDO and all other data access methods. It is designed to provide a
common bridge between different database, file systems and email servers.
Q6. Define Recordset.
Ans.
A recordset is an object that contains a setsof records from database.
Q7. Define Dynaset and Snapshot type Recordset.
Ans.
Dynaset Type Recordset
The dynaset type recordset object is a set of records that records that represents
a table, or attached table, or the result of queries containing fields from one or
more tables. A dynaset enables us to update data from more than one table.
Snapshot type Recordset
The snapshot type recordset can refer to any table, attached table or query. A
snapshot cannot be updated and does not reflect any change made by users.
Q8. List three important properties DateTimePicker control.
Ans.
Important properties of DateTimePicker control are
1.
Value: - This property gives the value of the date & time displayed n the
control.
2.
Name: - Name property sets the name of the dtpicker, which will be used
in coding.
3.
Format: - It specifies the format of the date or time to be displayed in the
control.
Q9. Write a note on MonthView control.
Ans.
MonthView control is used to display a calendar that shows one or
more months as specified. This control lets the user move from one place to
another. You can also specify selection of dates and specified dates can be
obtained from its value property. By default, the current month of the current year
is displayed.
Q10.
List four important properties of ListView control.
Ans.
Add Adds a new item to listeners collection
Count Returns number of items in collection.
Item Retrieves an item specified by and index value or key
Sorting Whether the items of listview will be sorted or not.
Q11.
Explain the function GetDriveType( ).
Ans.
GetDriveType () function determines the drive type & is declared as we
declare a private function Getdrivetype Lib Kernel32 _
Alias GetDriveTypeA (By Val ndrive as string) As long
You can pass the drive that you want to check with nDrive argument & the
function will return a long value, which describes the type of drive.
Q12.
Describe two ways of establishing a connection to database with
ADODB.
Ans.
Two ways of establishing a connection to database with ADODB are:
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:55

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.
Q13.
Define data integrity.
Ans.
Data integrity states that there should be no duplication of records &
database should always be in a consistent state. Each record in the database
should be uniquely identifiable.
Q14.
Write two important properties of data bound list.
Ans.
Two important properties of data bound list are
1.
Row source Specifies the source (recordset or data control) for
populating the list.
2.
Listfield Specifies the field that will be used to fill the list.
Q15.
Explain TableDef object.
Ans.
A TableDef object represents the definition of table in database object.
All TableDef object forms a collection, the TableDef collection.
Q16.
Explain QueryDef object.
Ans.
Database can contain query definitions. The queries that are commonly
used on a database can be stored in the database & can be called by name. All
the queries stored in database can be accessed through the QueryDef object.
QueryDefs object is a collection of QueryDef objects, one for each stored query.
Q17.
How SQL queries can be executed through active data object
(ADO)?
Ans.
SQL queries can be executed through Execute method of active data
object. E.g.
ADOconn.Execute Select * from employees
Q18.
List the advantages of COM.
Ans.
COM is a language independent object model that defines many types
of services & support for distributed objects. COM is the only model that provides
detailed & open specifications & helps to provide stability, effective
communication protocol & in process server support that developers & end users
need. COM provides easy to use tools & largest sets of available applications. It
provides Help for reusable components. COM supports thousands of available
applications.
Q19.
List two important properties of coolbar control?
Ans.
Two important properties of coolbar control are:1. Orientation: - This property specifies the orientation of the coolbar. It can be
oriented horizontally or vertically.
3.
Align: - Align property specifies the alignment of coolbar control on its
container object.
Q20.
What is an ActiveX control?
Ans.
Active X controls are user design controls, which have users specific
properties.
Q21.
Explain the difference between intrinsic controls & ActiveX
control.
Ans.
Intrinsic controls are those controls, which are there in the toolbox of
visual basic whereas ActiveX controls are custom made controls, which can be
build, by the users. Intrinsic controls are standard visual basic controls whereas
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:56

you can make controls that have user specific properties. E.g. You can design a
text box control which accepts only numeric values.
Q22.
Define Twip.
Ans.
A screen independent unit used to ensure that placement and
proportion of screen elements are same on all display systems. A twip is a unit of
screen measurement equal to 1/20 of printers point. There are app 1440 twips to
a logical inch or 567 twips to a logical centimeter.
Q23.
Write a short note on Microsoft Jet database engine.
Ans.
It is a database management system that retrieves and stores data in
user and system databases. The Microsoft Jet database engine can be thought of
as a data manager component with which other data access systems such as
Microsoft Access and visual Basic are built.
Q24.
What is dynaset?
Ans.
A type of Recordset object that returns a dynamic set of pointers to a
live database data like a table or a snapshot type Recordset, a dynaset returns
data in records (rows) and fields (columns). Unlike a table type Recordset, a
dynaset type recordset can be the result of a query that joins two or more tables.
Q25.
What do you meant by Data-bound Control?
Ans.
Data-bound controls are WinForms controls those can be easily bind
with data components. Data-bound controls have properties, which you can set as
a data component and theyre ready to present your data in WinForms.
DataSource and DisplayMember are two important properties.
Q26.
What do you understand by ActiveX components?
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.
Q27.
What do you mean by Cursors in VB?
Ans.
In database technology, it is a piece of software that returns rows of
data to the requesting application. A cursor keeps track of the position in the
result set, and multiple operations can be performed row by row against a result
set with or without returning to the original table. In other words, cursors
conceptually return a result set based on tables within the databases. The cursor
is so named because it indicates the current position in the result set, just as the
cursor on a computer screen indicates current position.
There are four types of cursors
1. AdOpenFarwordOnly 2. AdOpenkeyset 3. AdOpendynamic 4. AdOpenStatic
Q28.
What are different types of recordsets available in visual basic?
Ans.
Recordset contain the set of records that we can manipulate. In VB
there are following types of recordsets.
1. snapshot 2. tables 3. dynasets

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:57

Q1. 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.
Q2. Write down the various types of ActiveX controls.
Ans.
Visual Basic offers the user three different types of control .The
techniques for authoring all ActiveX controls are the same. The type we need to
build however depends on the requirement and the amount of functionality that is
required to be included in our control. The different types of ActiveX controls
offered by Visual basic are as follows.

User drawn control

Enhancement to existing Visual Basic control

New controls built with constituent controls


User Drawn Control
These controls are developed from scratch. The user is responsible for designing
the control's interface and is in control of its appearance and interface. The
implementation of these controls is very difficult, as every bit of functionality
starting from the control's interface to its appearance has to be written by the
developers/users. They also are the most flexible ones as the user does not have
to put up with the limitations of other controls.
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.
Constituent Control

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:58

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 are called constituent
control.
Q3. 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.
We will be working with a client server model. Here the application is client ,
which sends requests and the ActiveX Component is the server, which services
the request. Though ActiveX DLLs run within the same application as the client ,
they are considered as to be servers.
Q4.
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 dataaware 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 specifically designed to provide access to an SQL server
through a visual Basic Application.

Active Data Object (ADO) : This is a programming model that eliminates


the need to choose from among DAO and RDO and all other data access
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:59

SUBJECT: VISUAL BASIC

methods. It is designed to provide a common bridge between different database,


file system and e-mail servers.
Q5. Write a code in Visual Basic to Serach a Record in Database.
Ans.
Data

Object
Properties
Setting
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
Q6. Write a code in Visual Basic to update a record in Database.
Ans.

Object

Properties

Command button 1

Name
Caption
Name
Caption
Caption

Command button 2
Command button 3

Setting
Command 1
Modify
Command 2
Update
Exit

Data

Name
Data1
DatabaseName
c:\vb\Supplier.mbd
Record source
Supplier
The following code entered in the Command button1 click
Private Sub Command1_click()
Msgbox You are now modify the Current Record
Prepared By:By:- Charanjiv Singh

Page:
Page:60

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
Q7. Compare the conventional and Object Oriented Programming.
Ans.
Conventional Programming using high language such as COBOL ,
FORTRAN commonly know as procedure oriented programming.
1.Large programs are divided into smaller programs knows as functions.
2.Most of the function shares global data.
3.Data moves openly around the system from function to function.
4.Funtions transform data from one form to another.
5.Employs top down approach in program design.
Objecting Oriented Programming
1.Programs are divided into what are known as objects.
2.Data Structure are design such that they characterized the objects.
3.Functions that operate on the data of an object are tied together in the data
structure.
4.Data is hidden and cannot be accessed by external functions.
5.Objects may communicate with each other through functions.
6 Follows bottom up approach in program design.
Q8. Write a short note on masked edit controls.
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.
Q9. Write a short note on status bar control.
Ans.
Status bars are implemented in visual basic via the status bar control
and it runs along the bottom of an application window and provides the information
about the current status of the application. Status bar is a good place to put
information that helps users to keep track of program options they selected.
Status bar control is not an intrinsic control & can be added from components
dialog box named Microsoft Windows Common Control 6.0. status bar is always
added at the bottom of the form & you should set the forms border style to fixed
single so that user cannot change the size of the form.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:61

Q10.
What is recordset? Explain.
Ans.
Recordsets are objects that represent collections of records from one or
more tables .In database programming, Recordsets are the equivalent to variables
in regular programming. Tables of database cant be accessed directly. The only
way to view or manipulate records is via recordset object. A recordset is similar to
tables in database i.e. it consists of rows & columns and also it can contain data
from multiple tables. It is just like a grid and records in recordset. Recordsets are
the result of queries. Recordsets are object variables. It can store result of queries
or an entire table of the database. The contents of the recordset, however, have a
more complicated structure and each cell in this grid can be of a different type. To
access the contents of the recordset, you can use its properties & methods. So a
recordset is a view of some of the data in the database, selected from database
according to user specified criteria.
Q11.
Explain ADO object model in detail.
Ans.
ADO is active data object. ADO object model is similar to the DAO
model but it can handle more databases and has more features. ADO model
consists of three objects namely.
1.Connection
2.Command
3.Recordset
1.Connection: - It is a top-level object & represents a connection to the data
source. We establish a connection to a data source and issue a command against
the connection object to retrieve the desired records from the database or to
update the database.
2.Command: - This object represents a SQL statement or stored procedure that
can be processed by the data source. The command object doesnt return any
results if it updates the database or returns a recordset with the requested
records. To set up a command object, you specify the SQL statement or stored
procedure and its parameters. We can call the execute method to execute the
SQL statement or stored procedure against the data source. Another 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.
Q12.
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 back
round & 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.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:62

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-of-process 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.
Q13.
Explain ADO data control.
Ans.
Earlier there were DAO & RDO 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 (OLEDB) 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.
When ADO data control is placed & data source is specified we can bind various
other controls like textboxes, list boxes, comboboxes 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.
Q14.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:63

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.
Q15.
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
DIM Temp as student
Public sub enterdata ()
DIM | as Integer
For I= 0 to 10
S(I). Name= Inputbox (Enter name)
S(I).marks = Val (Input box (Enter marks) )
Next
End sub
Public sub show ()
DIM I As Integer, ) as Integer
For I = 0 to 10
For J = 0 to 10
IF S(I).marks > S(J).marks then
Temp = S(I)
S(I) = S(J)
End If
Next J
Next I
Msgbox S (1). name & is second
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:64

End sub
Q16.
What are classes and objects? Discuss how to add properties,
events and methods 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.
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.
Q17.
What are the different types of data reports? How are they
created?
Ans.
Data report: - It is created by using data environment .It may have
grouping on some data. To create data report we must have data environment.
After that add command for the report. Double click the Data Report object in the
Project Explorer window.

Arrange the Data Environment window and the Data Report window so
that both the windows are visible on the screen.

From data base environment drag the fields onto the appropriate
section to add selective fields or drag command object to include all the fields in
the report.

Each label control and text box control can be arranged in different
section of the report by dragging and dropping as per the requirement set the data
source property of Data Report object to the Data Environment and data member
property to command.
Crystal Reports: Crystal reports let you customize many of the programs default settings to fit the
layout of
your work. These settings affect such things as:
1.
Your working environment
2.
The way you select databases
3.
SQL and ODBC access
4.
The way various data types are formatted
5.
The fonts you use for fields and text.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:65

To create a crystal report1.


Open crystal Reports
2.
Click the new Report button on the button bar. The Report gallery
appears
(i)
Click one of Report creation expert buttons for step-by-step help
in creating a report.
(ii)
Click the another Report button to use another report as a
template for building your report.
(iii)
Click the custom button to build a custom report.
3.
When you click custom button the Report Gallery expands.
1.
Select report type
2.
Select data source
3.
Select the fields
4.
Format the fields and labels. Apply any others format required on
report.
Q18.
Explain the find methods to locate any record in the recordset.
Ans.
The find method can be used to locate a record in a dynaset or
snapshot type recordset. VB supports four find methods.
Find First: method finds the first record satisfying the specified criteria.
Findlast: method finds the last record satisfying the specified criteria.
Find Next: method finds the next record satisfying the specified criteria,
searching forward the current record.
Find Previous: method finds the previous record satisfying the specified criteria,
searching backward from the current record.
Q19.
Explain how a recordset can be created in Visual Basic.
Ans.
Recordset stores the results produced by the execution of command
object in a database. Recordset can be created without an explicit connection. To
access the fields of a recordset object, we can use fields collection.
Using the following code we can create recordset in vb
Dim cn as new adodb.connection
Dim rs as new adodb.recordset
Cn.open provider=Microsoft.Jet.Oledb.4.0; Data Source=c:\student.mdb
Rs.open select * from student,cn,adopendynamic,adlockoptimistic
To fetch the values from the recordset the following code is used.
Recordset.fields(fieldname)
Or
Recordset(indexno)
e.g
msgbox rs(0)
or
msgbox rs.fields(Name)

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:66

Q20.
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 exist-it 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.
Q21.
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.
Q22.
Explain in detail steps needed to modify the data in a database
record.
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

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:67

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
rno=inputbox (enter rollno to find)
rs.movefirst
rs.find rollno= & rno
if rs.eof then
msgbox record not found
else
txtrollno=rs(rollno)
txtname=rs(name)
txtclass=rs(class)
end sub
5. Modify data what ever u want to modify in the respective textboxes and click on
update button that have the followng code
private sub cmdupdate_click()
cn.execute update student set rollno= &txtrollno & , name= & txtname
&,class=& txtclass & where rollno= &txtrollno
end sub
Q23.
What care has to be taken while adding updataing and deleting
records from linked tables?
Ans.
Following things we have to care while adding , updating and deleting
records
1.
if any new record is added in the linked table it must have the reference
value from the main table otherwise no insertion is possible
2.
if any record is going to get updated then we should change reference key
in the secondary table
3.
before deleting the records from the parent table we all the reference
records must be deleted from the child table.
4.
Before updating the key field in parent table must remove the reference of
that value from the child table.

Q24.
What do you mean by ActiveX controls ? How they are useful in
application development?
Ans.
ActiveX controls add power to your Application form. In addition to
creating your own controls, you can use the Internet controls provided with the
Professional and Enterprise editions of Visual Basic to extend standard
applications with Internet technology. For example, you can use ActiveX controls
on a Web page to add customized menus to your Web pages, to add a scrolling
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:68

banner you can use to present advertisements or important announcements, or to


add animated effects. Window Common dialog control provides inbuilt dialog
mechanism that is used to create a simple notepad application.
ActiveX provide number of features those helps developers in development.
Q25.
Explain Application deployment with VB.
Ans.
The Package and Deployment Wizard packages your project .dll files
and all associated files into a "cabinet" or .cab file. The wizard can then deploy
this cabinet file and its associated support files to a location you indicate on a
Web server.
The application files that must be deployed include:
The .dll files for the project including the Visual Basic run-time DLL and
the .dsr and .dsx files for the project. These are automatically packaged into the
.cab file when you run the Package and Deployment Wizard.

The HTML page or pages associated with the project. The Package and
Deployment Wizard does not package these into the .cab file, but it copies them
to the indicated location on the Web site when you deploy the .cab file.

Any files referenced by the HTML pages, such as images. The Package
and Deployment Wizard does not automatically recognize these dependencies,
but you can add them to the list of additional files to deploy.

The Deployment Process


These are the steps in deploying your DHTML 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.
Q26.
Explain the different Advanced Data Access issues ?
Ans.
Following are five data access scenarios that are more complex than
simple Select queries.

Executing a Parameter Query

Performing a Parameter-Driven Stored Procedure


1.
Executing a Parameter Query : - ADO gives you a lot of flexibility here
more, in some cases more than RDO. Following commands are used to create
parameter query
Private Sub ParmQueryButton_Click()
If Cmd.CommandText = "" Then
Cmd.ActiveConnection = cn
With Cmd
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:69

.CommandText = "select * from authors where year_born = ?"


.CommandType = adCmdText
End With
With Parm
.Type = adInteger
.Size = 4
.Direction = adParamInput
.Value = QueryParam.Text
Cmd.Parameters.Append Parm
End With
End If
Cmd.Parameters(0).Value = QueryParam.Text
Set rs = Cmd.Execute()
ADOGrid1.ShowData rs
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

SUBJECT: VISUAL BASIC

Page:
Page:70

(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 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.

Q27. Explain the following


(a)Opening a table for exclusive use
Prepared By:By:- Charanjiv Singh

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:71

Q28.
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 runtime files that must be included with your application when it is distributed.

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.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:72

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.

Q29.
(a) 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.
Q30.
Explain briefly about COM and DCOM.
Ans.
Component Object Model
Component Object model (COM) is the basis for all OCX controls. COM is a
specification. It doesnt tell the user how to implement a control ; rather it
concentrates the way in which two process communicate with each other and
defines some standard interfaces for them to communicate.COM allows software
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:73

components to communicate with each other. It is a binary standard that allows


any two components to communicate regardless of the language the components
are written in. The only way to access and interact with a COM object is through
interfaces.
Distributed Component Object Model
Distributed Component is nothing but a network. It allows information exchange
over the internet , the local intranet or any other network. While COM is the basis
for OCX controls , DCOM is the basis for ActiveX controls as ActiveX itself is
nothing but internet enable OCX.
Q31.
Explain ActiveX Documents.
Ans.
ActiveX documents (.dob) are similar to forms, but are displayable in an
Internet browser such as Internet Explorer. The Professional and Enterprise
editions of Visual Basic are capable of creating ActiveX documents
Following steps are used to create ActiveX document.
1.
Determine the features your document will provide.
2.
Design the appearance of your document.
3.
Design the interface for your document; that is, the properties, methods,
and events your document will expose.
4.
Create a project consisting of your user document and any auxiliary forms.
5.
Add controls and/or code to the UserDocument object.
6.
Implement the interface and features of your document.
7.
Compile your document to create a .vbd file and test it with all potential
target applications
Q32.
Briefly explain the three types of recordsets.
Ans.
Recordset: Record sets are objects that represent collections of records from
one or more tables. Recordset are equivalent of variables in regular programming
you can access the tables of database only by manipulating the Recordset
objects. A Recordset is a view of some data in the database, selected from the
database according to the user specified criteria. In other word, A Recordset
represents the entire set of records from a table in a database or the result from
an executed command. A Recordset is a set of rows in which each row has
columns of data.
There are three types of Recordsets namely(1)Dynasets: :- This type of recordset can be specified with DAO object which is
an updateable view of data. Means we can update and modify the records both in
forward and backward direction.
(2) Snapshots, which is the static (Read-only) view of data
(3) Table, which is the direct views of table.
Q33.
What is a DLL? Write a suitable code to call windows API in VB
application?
Ans.
An operating system feature, that stores executable routines in
separate file having extension .dll, these subroutines execute only when it is
called by the calling program or by the user requirement. The dynamic link library
files are attached to application at runtime and share memory only at runtime.

Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:74

Following vb code will show how to shutdown the computer from the vb
form by click on button using appropriate API function
1. open vb project
2. place a command button on the form
3. open form in code window
4. write the following code in general section
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long,
ByVal dwReserved As Long) As Long
Private Sub Command1_Click()
Call ExitWindowsEx(1, 0)
End Sub

Q34.

How can you create an ActiveX control in VB? Give example.

Ans.
Steps to create an ActiveX control
1. Start a new project. Select ActiveX control as the project type.
2. Set the name property of the Project.
3. Set the name property of the UserControl
4. From the toolbox add the controls for your ActiveX control.
5. Set the properties of the controls according to the function you want to be
performed.
6. Code for your UserControl.
7. Save the UserControl form and Project
8. Before a control can be used, appropriate entries must be created for it in the
Windows registration database. Selecting the FileMake menu command can do
compilation. After it is compiled, the Control is registered on the computer.
Q35.
Explain in detail ADO object model.
Ans.
ActiveX Data Objects (ADO): ADO enables you to write a client
application to access and manipulate data in a data source through a provider.
ADO is ideally suited to consume data exposed by OLE DB providers. OLE DB
provides high-performance access to any data source, including relational and
non-relational databases, email and file systems, text and graphics, custom
business objects, and more. ADO connects to a database by means of OLEDB
provides OLEDB provides is a Microsoft lower-level database interface that
provides access to many different kinds of databases.
Possible Uses

Connect to a local or remote database.

Open a specified database table or define a set of records based on a


Structured Query Language (SQL) query or stored procedure or view of the tables
in that database.
Pass data field values to data-bound controls, where you can display or
change the values.
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:75

Add new records or update a database based on any changes you make to
data displayed in the bound controls.
Q36.
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
Q37.
Write the DAO object hierarchy.
Ans.
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
2. record set object.
1. The workspace object defines a session for the user. When your application
starts, the Jet engine creates sa 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.
Q38.
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
Prepared By:By:- Charanjiv Singh

SUBJECT: VISUAL BASIC

Page:
Page:76

1. select ActiveX control project from the new project Dialogbox


2. On the usercontrol form place the following controls
3. Label control, timer control and two command buttons
4. set border style property of label control to fixed single.
5. set the caption of the command1 to startclock and caption of the command2
to stop clock.
6. change the name of the usercontrol to timercontrol
7. specify view bitmap property of the usercontrol to specific image . it should
appear as on the form.

8. Change the name of the project from project property window.


9. Write the following code in the code window
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Time
End Sub
10. Now save the project
11. make timercontrol1.ocx.

Prepared By:By:- Charanjiv Singh

S-ar putea să vă placă și