Vous êtes sur la page 1sur 81

Page 1

What is vb?
Vb is a user friendly event driven and partly objected oriented programming
language using which we can develop:
a. Database application.
b. Web enabled application.
c. And variety of other window based application.
Who developed vb?
Vb is developed by Microsoft in 1991 as Visual Basic 1.0.
Why vb was developed?
Before vb window based application was being done using c and window
based compiler which was a slow and tedious process. It required lots of
coding. To speed up development of window based application vc++ and
Microsoft foundation class were developed. But the development process
was still tedious and slow. To boost development of window based
application easily and fastly vb was introduced.
What are the different editions of vb?
There are three editions of vb:1. Standard or learning edition: contains basic language feature and
tools.
2. Professional edition: contains more feature and tools when compared
to standard edition.
3. Enterprise edition: contains most advance feature and tools.
The edition which we are using is enterprise edition.
What are the hardware requirements to use vb?
The hardware requirements are as follows:
a. cd-rom drive
b. CD-ROM (1 to 7 cds). First cd rom contains compilers for various
languages like vb, vc++, visual FoxPro; visual internet developer etc.
remaining cds contains help, client server tools, samples etc.
c. Windows 9x Os.
d. 80 to 120 mb for installation of vb.
e. 40 mb free hard disk space for user generated program.
f. 16 mb ram minimum ( 32 mb ram recommended)
g. 80486 based micro processor ( Pentium 166 MHz recommended)
What is Event Driven programming?

Page 2

When a program consists of one or more than one event procedures and
those procedures accomplish the task to be done by program it is know as
event driven programming.
What is event?
Event is any action performed by either user or performed by program itself.
For example mouse-click, key press, window resize etc.
What are the difference between structured/procedure oriented and
event driven programming?
Structured/Procedure Oriented

Event Driven Programming

Program consists of one or more


procedure.

Program consists of one or more


event procedure.

Programming task is completed by


procedure.

Programming task is completed by


event procedure.

The order of execution of procedure The order of execution of event


is more or less predictable.
procedure depends on user
performed action.
Procedure oriented programming is
not suitable for window based
application.

Event driven programming is


suitable for window based
application.

What do you mean by IDE?


Ide stands for integrated development environment. It is collection of
program allowing composing and editing the program, testing the program,
running the program and debugging the program.
Describe working environment of vb?
Working environment of vb is composed of many elements:
1. title bar: where program title, project name and program mode is
displayed
2. Menu bar: contains menu and related commands.
3. Tool bar: consists of icons which are short cuts to frequently used
commands some toolbars are: standard, formatting etc.

Page 3

Toolbox: on the left side toolbox appears which contains controls.


Form designer: appears in middle where graphical user interface
element (controls) is placed.
6. Properties window: using this we can set properties of controls.
7. project explorer window: displays files which make up the project
8. Form layout window: displays form-icon used to set start up position
of form.
9. Immediate window: useful to test any statement or to print value of
variable.
4.
5.

What are the different modes of vb program?


There are three modes of vb program:
a. design: ( when designing form and writing code)
b. Run: when a program is running.
c. Break: when any occurred in program.
What is project file? Why it is needed?
Project file contains information about all those file which make the project.
it stores location of individual file with path. When saving project it saves all
files one by one inside project. When we open project it automatically opens
all files which are part of project we need not to open each file one by one
thus saving time. Project file has extension vbp.
What is executable file? How it is made?
To make executable file (exe) we have to go to file menu and have to select
make exe.
Copying of exe file to another computer and running the exe file does not
guarantee that the executable file will run there because a window based
program depends on many different file. it better to run distributable
package using package and deployment wizard.
What is module?
Module is collection of procedures and functions corresponding to a file in
disk will generate. Benefits are:
a. It provides code reusability and stability.
b. Avoids code repetition.
c. Testing and debugging becomes easier.
Type of module:
a. Form module: normally contains event procedures, other procedure
and function which will be used inside the same form module. extension is

Page 4

.frm
Basic module: normally contains global variables, procedure and
function which can be accessed across other modules. extension is .bas
c. Class module: contains definition of class, member function and
properties. extension is .cls
b.

How to use code editor window?


Code editor window can be brought forward using either of these methods:
1. select view-> view code
2. right click on form and select view code
3. Double click on any control or on double click on form.
4. From project explorer window select the form name and click on
button view code.
navigation of code editor window:
control+left arrow : move one word left
control+right arrow : move one word right
control +home : move to beginning of code view
control +end : move to end of code view
home : move to beginning of line
end : move to end of line
control+up arrow : move one procedure up
control+down arrow : move one procedure down
shift+f2: view definition of function or procedure under cursor
control+shift+f2: go to last position of cursor
What is documentation? Why it is needed?
Documentation of code is very necessary. Using documentation we can
increase readability of our program. Using documentation we can store
addition information like:
a. date and time of program
b. version no. of program
c. company for which it was created
d. author of the code
e. variables used and purpose
f. algorithm of program
g. explanation of statement
Documentation makes the program easily under stable. In future if we are
going to make modification in program it will help greatly. We use
(apostrophe) to write comments or rem keyword.

Page 5

How formatting of code is done?


Formatting of code make program easy to read. Indentation makes easy to
follow closing of control structure. different background and foreground
colors, fonts, font size can be assigned to normal text, keywords etc. using
tool->options->editor format tab. procedure separator line can also be turned
on to help to identify where one procedure is beginning and ending.
Describe environment options in vb?
Select tools->options->environment tab
a. under when visual basic starts
if option button selected is prompt for project: each time visual basic
starts a dialog box appears which lets us select type of project.
if option button selected create default project: each time visual basic
starts it automatically open standard exe project.
b. under a program starts:
if save changes: is selected when program is about to start it saves the
changes made in project.
if selected prompt to save changes: is selected when program is about to
start it will ask to save the changes.
if selected dont save changes: it will not save the changes made in
project and will run program.
c. Show templates for: we can have many templates available for use as
starting point for form, mdi forms, modules etc.
Describe editor options.
Select tools->options->editor tab.
1. Auto syntax check: if checked, when writing a statement and pressing
enter check the statement for error.
2. Require variable declaration: puts option explicit statement in
modules general declaration section which forces declaration of variable
before use as in c-language.
3. Auto list member: if checked gives popup list consisting of properties,
methods supported by object.
4. Auto quick info. if checked gives information about function
parameter and data type of parameter which current function will work on.
5. Auto data tips: if checked gives list of constant which can be assigned
to a variable or to parameter of a procedure or function?
Dim b as Boolean
Type b= then you will get true, false in a list
6. Auto indent: if checked starts new line just below the previous line.

Page 6

Tab width: specify the amount of space generated by a tab key.


Drag and drop text editing: if checked supports drag and drop in code
editor window.
9. Default to full module view: if not checked only one procedure will be
visible at a time.
10. Procedure separator: if checked draws line among procedures.
7.
8.

Describe automatic code completion feature of vb.


When we have to use any object property or any method of object we
have to type just a few letter of that property or method as soon as the
property or method is selected from popup list we can press control space
key combination to complete the whole property or method thus saving
key stroke.
What is Object?
Object is class variable which is composition of properties, methods and
data member. Object is fundamental requirement of any object oriented
language. Object has three characteristics:
1. State: state of any object defines identity of object.
2. Behavior: behavior of any object is decided by member functions
(methods) to which object can respond.
3. Method: it is also known as member function it performs computation
on data member or any kind of action.
What is property?
Property of any object is actually member procedure which allows to set
value in data member (working as mutator) or allows to retrieve value of
data member ( working as accessory).
How to create program in vb?
Steps are as follows:
1. First decide the controls which will be used to create graphical user
interface.
2. set properties of controls
3. Write event procedure coding.
How to get print of visual basic program.
1. save the project
2. select file->print
3. from the dialog box specify:

Page 7

Under range:
a. selection to print selected code
b. current module- to print current module
c. current project- to print all modules in current project
Under print what:
a. Form image- to print the image of form.
b. code- to print code
c. form as text- to print form as text format , resulting of printing of
controls along with properties and code
Under setup, specify paper size, orientation of paper and printer to use
Describe controlling objects. Or describe toolbox.
Control depends on interfaces which are properties, events and
methods.
Normally there are many controls found in visual basic. Some
controls are activex controls which can be included in toolbox using
project->component dialog. There is some control already available in
toolbox which is also known as intrinsic controls or standard controls.
Descriptions of standard controls are as follows:
a. Label control: it is useful to give user a prompt.
b. Text box: it is useful to input/output data for program.
c. List box: it is useful to give list of items and user can select items
from list.
d. Combo box: it is combination of text box and list box user can type
new item or can select an existing item from combo box list portion.
e. image box: can display picture
f. Picture box: can display picture.
g. directory , drive and file list box: allows to create a dialog box to
save , open file
h. Ole control: allows using feature of other existing application.
i. data control: useful to write data base program
j. Option button or radio button: allows selecting only one of several
available choices.
k. Check box: allows selecting many choices of several available
choices.
l. Frame: acts as container to place related controls together.
m. Command button or push button: useful to confirm action like close,
open, apply etc.
n. Timer: useful to execute certain piece of code after specified interval.

Page 8

Default property is enabled which takes true or false value.


o. shape: useful to decorate form
p. line : useful to draw line to decorate form
q. Scrollbar: useful to take input/output or scrolling data.
What is variable?
Variable is name given to computer memory location where we can store
value and retrieve the stored value by name.
Variable is fundamental requirement of any programming language.
Rule of naming variable or identifier:
1. Variable name must start with alphabet.
2. Later on digits can be used, under score can also appear.
3. variable name is not case sensitive
4. only a-z, 0-9 and _ can appear in variable Name
5. Space and special are not allowed.
6. variable name must not match with keyword
7. we can have variable name 255 characters long
8. name of control must not exceed 40 characters
What is data type?
Data type of variable defines range, memory and valid operation for a
variable
Data type
Range
Memory
1.Byte

0 , 255

2.Integer %

32767 , 0 , -32768

3. Single!

+/- 3.4 e +34

4.Double #

+/- 1.7 e+308

5.Date

1-1-100 to 31-12-9999

6.string(variable) $

2 billion characters

6.string(fixed) $
7.boolean

True, false

Page 9

8.object

Reference of any
object

9. variant

Range for number is


same as double
Range for string is
same as 2 billion
characters

How to declare variable?


(a) Dim x as integer, y as integer
Or
Dim x%, y%
(b) Dim x, y as integer
Then x will be variant and y will be integer
(c) Dim b as Boolean
Describe scope of variable.
Scope specifies the code range where value of variable is accessible.
a. Local variable: accessible inside a function or procedure. we use dim
keyword to declare local variable.
b. Module level global variable: accessible inside a module but not
outside from other module. We use dim or private keyword to declare
module level global variable and declare it inside general declaration of
module.
c. Global variable: accessible from every where. We use public or global
keyword to declare global variable inside general declaration of module.
What do you mean by shadowing of variable?
if global variable or module level global variable exists with name a and
a local variable also exists in a procedure or function it prevents
accessing of global or module level global variable because local variable
is given preference. to access value of global variable we can use
Module name .global variable e.g. form1.a
What are the operators in vb?
1. arithmetic operator:

Page 10

+ for addition,
- for subtraction.
* for multiplication
\ for integer division c=10\3 c will be 3
/ for float division c= 10/3 c will be 3.333
^ for power e.g. c=10^3 therefore c will be 1000
mod for modulo division c=10 mod 3 c will be 1
2. relation operator
>,>=,<,<=,=, <>
3. logical operator
and, or, not
3. assignment
=
Why do we need control structure?
We all need to alter our action depending on changing circumstances. For
example If weather is fine I will go Dongargarh on bike otherwise I will go
by train. In the same way vb language too must be able to perform different
action under one condition and different action under another condition and
this is made possible by control structure. Sometimes a given set of
statements are needed to run repeatedly this is done using loop control
structure.
Write notes on if control structure./ explain branching structure in vb./
write short notes on if statement/ write short note on select case.. End
select.
The general form of if statement is:
(A) if-endif statement
The general format of if statement is
If (condition is true) then
Execute this statement
End if
The keyword if tells the compiler that what follows, is a decision control
instruction. The condition following the keyword if is optionally enclosed
within a pair of parentheses. If the condition, whatever it is, is true, then the
statement is executed. If the condition is not true then the statement is not
executed; instead the program skips past it.
(b) If else-endif statement
If statement by itself can execute only one statement if condition is true. If it

Page 11

required running a group of statements when condition is true we have


to enclose those statements inside curly brace known as compound
statement. The above form of if statement mentioned in (a) will not do
anything when condition is false. If we want to run statement when
condition is false we need if-else construct.
General format of if-else construct is
If (condition is true) then
Execute this statement
Else
Execute this statement if condition is false
End if
Condition is specified using relational operator
x= y means x is equal to y.
x<>y means x is not equal to y.
x< y means x is less than y.
x>y means x is greater than y.
x<=y means x is less than or equal to y.
x>=y means x is greater than or equal to y
What is the use of logical operator? what is meant by logical testing?
Logical operator and, or, not are useful to join more than one condition
whereas not operator negates meaning of condition. These are required in
following situations:
* When it is be tested whether a value falls within a particular range or not.
* When after testing several conditions the outcome is either true or false.
* Reverse the logic of condition using not logical operator.
Control structures mostly depend on logical testing to perform some piece of
code either selectively or repeatedly.
What are the different forms of if else statements?
Different forms of if-else statement are as follows:
1. if (condition) then
do this
and this
end if
2. if (condition) then
do this
do this
else

Page 12

do this
do this
end if
3. if (condition) then single-true statement
4. if (condition) then single-true statement else single-false-statement
5. if (condition) then
if (condition) then
statement
else
statement
end if
else
if (condition) then
statements
else
statements
end if
end if
5. if condition then
statements
elseif condition then
statements
elseif condition then
statements
else
statements
end if
program to find division given percentage
Private Sub Command1_Click ()
Dim a!, b$
a = Text1.Text
If a < 33 Then
b = "fail"
Else
If a < 45 Then
b = "third"
Else
If a < 60 Then

Page 13

b = "second"
Else
b = "first"
End If
End If
End If
Text2 = b
End Sub
place label : having caption enter percentage
place text1: having text property cleared
place label2 : having caption division
place text2: having text property cleared
place command1: having caption find division
program to check leap year
Private Sub Command1_Click()
Dim a%
a = Text1
If a Mod 100 = 0 Then
If a Mod 400 = 0 Then
Text2 = "leap"
Else
Text2 = "not leap"
End If
else
If a Mod 4 = 0 Then
Text2 = "leap"
Else
Text2 = "not leap"
End If
End If
End Sub
Place label: having caption enter year
Place text1: having text property cleared
Place label2: having caption result of testing
Place text2: having text property cleared
Place command1: having caption check for leap year

Page 14

Program to print message teenage, child, old etc. according to given age
Private Sub Command1_Click ()
Dim a!
a = Text1
Select Case (a)
Case Is <= 8
Text2 = "child"
Case 9 To 14
Text2 = "teenager"
Case 15 To 20
Text2 = "young"
Case 21 To 28
Text2 = "adult"
Case Is > 28
Text2 = "old"
End Select
End Sub
Place label: having caption enter age
Place text1: having text property cleared
Place label2: having caption state
Place text2: having text property cleared
Place command1: having caption check age
State the difference between select case and if
select-case
if-else
1. All programs made using selectcase can be solved using if. Select
case takes different action
depending on value of a single
variable.

All programs made by if are not


possible to solve by select-case.
if leads to less structured

2. select-case leads to more


structured programming and level of Programming and level of
indentation is difficult to manage if
indentation is manageable even if
using nested ifs.
we have nested select-case.

Page 15

Multiple if

Nested if. else

1. Multiple if. Else contains more


than one end if. Each end if
corresponds to each if.

1. Nested if. Else contains more


than one else if but just one end
if..

2. Multiple if requires more


comparison. Therefore it is not
efficient.

2. Nested if requires less


comparison. Therefore it is efficient.

Write short notes on go to statement and its limitations.


Goto is a statement which is quite common in monolithic programming
paradigm. Some languages like basic, FORTRAN etc. use it deliberately.
Using go to we can do:
1.
Skipping of some statement without executing them.
2.
Transferring of control to a labeled statement.
3.
Coming out of loop whatever level of nesting of loop may be.
Note that break statement can take out of loop inside which it lies but goto
statement can take out of loops irrespective of level of nesting of loops.
Different type of goto can be:
a. Conditional-goto: if it is used with if statement.
b. Unconditional-goto: if it is not used with if statement.
Limitations of goto: unwise use of goto make it difficult to trace logic flow
of program and makes it difficult to remove logical error of program
therefore, as far as possible, we must avoid use of goto.
Program to print 1 to 10 using goto statement
Private Sub Command1_Click ()
Dim a%, b%, c%, t$
a = Text1
b = Text2
c = Text3
mm: t = t & a & " "
a=a+c
If a <= b Then Go To mm
Text4 = t
End Sub
Place label1: having caption enter starting term
Place text1: having text property cleared
Place label2: having caption enter stopping term

Page 16

Place text2: having text property cleared


Place label3: having caption enter value to step by
Place text3: having text property cleared
Place text4: having text property cleared
Place command1: having caption print series in text box
Why loop control structure is needed?
Without loops we execute the same series of actions, in the same way,
exactly once. Loops allows to execute same portion of program code
repeatedly a specified no. of times or until a particular condition is being
satisfied. This repetitive operation is done through a loop control structure.
There are four methods using which we can repeat a part of a program which
are:
* For statement
* while statement
* do-while statement
* Goto statement (not recommended)
Write short notes on while (entry level control structure/test and do)
loop.
In programming we require to execute same set of instructions a fixed
number of times. E.g. we want to calculate gross salary of ten different
persons; we want to convert temperatures from centigrade to Fahrenheit for
15 different cities. The while loop is suited for this.
Program to print 1 to 10 on form
Private sub command1_click ()
Dim a%
a=1
Do while a<=10
print a
a=a+1
loop
end sub
General format is
1.
initialize loop counter
do while(condition is true)

Page 17

do this;
increment loop counter;
loop
Write short notes on while (entry level control structure/test and do)
loop.
In programming we require to execute same set of instructions a fixed
number of times. E.g. we want to calculate gross salary of ten different
persons; we want to convert temperatures from centigrade to Fahrenheit for
15 different cities. The while loop is suited for this.
Program to print 1 to 10 on form
Private sub command1_click ()
Dim a%
a=1
do
print a
a=a+1
loop while a<=10
end sub
General format is
initialize loop counter
do
do this
increment loop counter
loop while(condition is true)
Differentiate between while/while. Wend and do-while loop.
Body of loop in case of while loop will not execute even once if condition
of while loop is false but in case of do-while loop body of loop will run at
least once because condition is tested at the end of loop body.
Format of do. Loop is
initialize loop counter
do
do this
increment loop counter
loop while(condition is true)
format of while loop:
initialize loop counter

Page 18

while condition
do this
increment loop counter
loop
format of while.. wend loop:
initialize loop counter
while condition
do this
increment loop counter
wend
Do while loop must test a condition that will eventually become false,
otherwise the loop would be executed forever, indefinitely known as infinite
or indefinite loop.
While loop or while. Wend loop test condition and if condition is true then
statements are executed if condition is false statements are not executed even
once.
Do.. While loop test condition later therefore if condition is false statements
are executed at least once.
While. Wend statement can not use exit do statement to come out of loop
whereas do. While and do. Loopwhile can use exit do statement to come
out of loop.
Write short notes on for loop.
For loop is most popular loop. For loop allows us to specify three things
about a loop in a single line which are:
1. Setting a loop counter to initial value.
2. Testing the loop counter to determine whether its value has reached the
number of repetitions desired.
3. Increasing the value of loop counter each time the program segment
within the loop have been executed.
The general format of for statement is as us under:
for variable= intialvalue to end value step step value
do this
and this
and this
next

Page 19

Write short notes on odd loop.


The loops in which no. of times statements inside loop body will execute are
known as finite or determinate loop. The loops which will never terminate
execution of statements inside loop body are known as infinite loop. The
loop about which we are not certain how many times statements inside loop
body will execute but we are sure that it will terminate after some time is
known as odd loop.
Write program to demonstrate loops to solve Fibonacci series up to n terms.
Private Sub Command1_Click ()
Dim i%, term1&, term2&, term3&, t$, n terms
term1 = 0
term2 = 1
Terms = Text1
' method A- using for loop
For i = 1 to n terms
't = t & term1 & " "
'term3 = term1 + term2
'term1 = term2
'term2 = term3
'Next
method B-using do-whileloop
'i = 1
'Do While i <= nterms ' do loop until i>nterms
't = t & term1 & " "
'term3 = term1 + term2
'term1 = term2
'term2 = term3
'i = i + 1
'Loop
method C- using doloop while
'i = 1
'Do
't = t & term1 & " "
'term3 = term1 + term2
'term1 = term2
'term2 = term3
'i = i + 1

Page 20

'Loop While i <= nterms ' loop while until>nterms


method D-using while wend
i=1
While i <= nterms
t = t & term1 & " "
term3 = term1 + term2
term1 = term2
term2 = term3
i=i+1
Wend
Text2 = t series will go into a text box
End Sub
Place label1: having caption enter no. of terms of Fibonacci series
Place text1: having text property cleared
Place label2: having caption series is
Place command1: having caption print series in text box
Write short Notes on exit do / exit for in Loop/write program to check
primality.
We often come across situations when we want to jump out of a loop
instantly, without waiting to get back to the conditional test. The keyword
exit do / exit for allows us to do this. When the keyword exit do / exit
for is encountered inside any loop statement, control automatically passed
to the first statement after the loop. An exit do / exit for is usually
associated with an if statement applicable to loop.
The keyword exit do / exit for takes the control out of the loop inside
which it is placed.
What is use of const keyword?
Const keyword is useful to declare a constant with a given symbolic name
whose value can not change during program run time.
Const pi =3.1415
What do you mean by nested loop?
Nested loop is a special case in which one loop contains other loop inside its
loop body. For each value of outer loop counter, inner loop counter changes
frequently.

Page 21

Program to print prime series between 1 to 100 using for loop and exit
for
Private Sub Command1_Click ()
Dim a%, b%, c%, n%, t$, i%
a=1
b = 100
For n = a to b
For i = 2 to n - 1
If n Mod i = 0 Then
Exit For
End If
Next
If i >= n Then
t=t&""&n
End If
Next
Text1 = t
End Sub
Place label1: having caption set to prime series is
Place text1: having text property cleared
Place command1: having caption print series in text box
Define Array.
Array or Subscripted variables:
Array is collection of variables having common name and common data
type. Individual variable in collection is identified by index or subscript.
Elements of array occupy contiguous memory location.
How can we declare a single dimension Array?
Declaration (single dimension numeric array):
Dim a (5) as integer
Or
Dim a %( 5)
a is name of array.
it means there are 6 variables viz. a(0),a(1),a(2),a(3),a(4),a(5) index or
subscript will ange from 0 to 5. All variables will be integers.
Dim b! (10)
Or

Page 22

Dim b (10) as single


It means there are 11 variables viz. b (0), b (1) b (5) index or subscript
will change from 0 to 10. All variables will be single.
How we can initialize an array?
Initialization of array is not supported by vb.
What are the usages/Applications of Array?
Application of arrays:
* It is useful to solve simultaneous equation.
* It is useful to solve problems of data structure like searching, sorting,
linked list, graph etc.
* Its is useful to solve such problems requiring variable of same data type in
contiguous memory location.
What is Multi Dimension Arrays? What are their usages?
Array declared with more than one dimension is known as multi-dimension
array.
Often multi dimension array is needed to store data for table and matrices.
Multi -dimension array has more than one subscript. Two dimension arrays
contains two subscript, three dimension arrays has three subscript and so on.
Program to add two matrix of order 3x3
Place three command buttons on form labeled input, sort, print
Dim a %( 2, 2), b %( 2, 2), c %( 2, 2), i%, j%
Private Sub Command1_Click ()
MsgBox "enter value for array a"
For i = 0 To 2
For j = 0 To 2
a(i, j) = InputBox("enter value")
Next
Next
MsgBox "enter value for array b"
For i = 0 To 2
For j = 0 To 2
b(i, j) = InputBox("enter value")
Next
Next
End Sub

Page 23

Private Sub Command2_Click ()


For i = 0 To 2
For j = 0 To 2
c(i, j) = a(i, j) + b(i, j)
Next
Next
End Sub
Private Sub Command3_Click ()
For i = 0 To 2
For j = 0 To 2
Print c(i, j) & " ";
Next
Print
Next
End Sub
Program to sort a given array
Place three command buttons on form labeled input, add, and print
Dim a%(4)
Private Sub Command1_Click ()
Dim i%
For i = 0 To 4
a(i) = InputBox("enter value", "data entry", 1)
Next
End Sub
Private Sub Command2_Click ()
Dim i%, j%
For i = 0 To 3
For j = 0 To 3 - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next
Next
End Sub

Page 24

Private Sub Command3_Click ()


Dim i%
For i = 0 To 4
Print a(i)
Next
End Sub
What is dynamic array?
Dynamic array is an array whose no. of elements is not specified earlier. No.
of elements can be requested from user at program run time. Redim keyword
can be used to allocate memory for such no. of elements. After allocating
memory we can store value in elements of array.
Dynamic array saves memory because we have to allocate memory for such
many elements which we want to use.
Program to sort an array using dynamic array
Dim a%(), n 'note element is not specified
Private Sub Command1_Click()
Dim i%
' take no. of elements required
n = InputBox("enter no. of elements")
'allocate memory
ReDim a(n - 1) ' workout
For i = LBound(a) To UBound(a)
a(i) = InputBox("enter value", "data entry", 1)
Next
End Sub
Private Sub Command2_Click ()
Dim i%, j%
For i = LBound(a) To UBound(a) - 1
For j = LBound(a) To UBound(a) - 1 - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next
Next
End Sub

Page 25

Private Sub Command3_Click()


Dim i%
For i = LBound(a) To UBound(a)
Print a(i)
Next
End Sub
Place command1: having caption set to input
Place command1: having caption set to sort
Place command1: having caption set to print
Program to add two matrixes using non-dynamic array.
Dim a%(2, 2), b%(2, 2), c%(2, 2), i%, j%,t$
Private Sub Command1_Click ()
MsgBox "enter value for array a"
For i = 0 To 2
For j = 0 To 2
a(i, j) = InputBox("enter value")
Next
Next
MsgBox "enter value for array b"
For i = 0 To 2
For j = 0 To 2
b(i, j) = InputBox("enter value")
Next
Next
End Sub
Private Sub Command2_Click ()
For i = 0 To 2
For j = 0 To 2
c(i, j) = a(i, j) + b(i, j)
Next
Next
End Sub
Private Sub Command3_Click ()
For i = 0 To 2
For j = 0 To 2
t=t & c(i, j) & " "
Next

Page 26

t=t & vbcrlf


Next
End Sub
Place command1: having caption set to input
Place command1: having caption set to add
7place text1: having multiline property true and scrollbars set to 2 for both
Place command1: having caption set to print
Program to multiply two matrixes using dynamic array.
Dim a%(), b%(), c%(), i%, j%, m%, n%, p%, q%
Private Sub Command1_Click()
m = InputBox("enter no of rows in matrix a")
n = InputBox("enter no. of columns in matrix a")
p = InputBox("enter no of rows in matrix b")
q = InputBox("enter no. of columns in matrix b")
If n <> p Then
MsgBox "invalid matrix order for multiplication"
Exit Sub ' come out of event
End If
MsgBox "enter value" & m * n & " for array a"
ReDim a(m - 1, n - 1) 'allocate memory before storing value
For i = LBound(a, 1) To UBound(a, 1)
For j = LBound(a, 2) To UBound(a, 2)
a(i, j) = InputBox("enter value")
Next
Next
MsgBox "enter value" & p * q & " for array b"
ReDim b(p - 1, q - 1) 'allocate memory before storing value
For i = LBound(b, 1) To UBound(b, 1)
For j = LBound(b, 2) To UBound(b, 2)
b(i, j) = InputBox("enter value")
Next
Next
End Sub
Private Sub Command2_Click()
ReDim c(m - 1, q - 1)
For i = LBound(a, 1) To UBound(a, 1)

Page 27

For k = LBound(b, 2) To UBound(b, 2)


c(i, k) = 0
For j = LBound(a, 2) To UBound(a, 2)
c(i, k) = c(i, k) + a(i, j) * b(j, k)
Next
Next
Next
End Sub
Private Sub Command3_Click()
For i = LBound(c, 1) To UBound(c, 1)
For j = LBound(c, 2) To UBound(c, 2)
Print c(i, j) & " ";
Next
Print
Next
End Sub
Place command1: having caption set to input
Place command1: having caption set to multiply
Place command1: having caption set to print
What is use of preserve keyword?
Preserve keyword is useful to let the dynamic array remember the older
contents it has.
e.g.
Private Sub Command1_Click ()
Dim a %()
'Redimension
ReDim a (2)
a (0) = 10
a (1) = 20
a(2) = 30
Print a(0), a(1), a(2)
'Resize array without using redim
ReDim a(3)
a(3) = 40
Print a(0), a(1), a(2), a(3)
End Sub

Page 28

Private Sub Command2_Click()


Dim a%()
'redimension
ReDim a(2)
a(0) = 10
a(1) = 20
a(2) = 30
Print a(0), a(1), a(2)
'change array size and use preserve
ReDim Preserve a(3)
a(3) = 40
Print a(0), a(1), a(2), a(3)
End Sub
Place command1: having caption set to test without preserve
Place command1: having caption set to test with preserve
What is function?
A number of statements grouped into a single logical unit are referred to as a
function which returns a value and which is made to complete a specific
task. A program can be made of many functions.
Types of functions:
User defined function: these are those functions which are made by
programmer for his programming convenience.
Library function: these are those functions which are readymade and are
provided by compiler, uses of which are possible by including corresponding
header files. Source code of library function is not available to programmer
but its object codes are available in precompiled form.
What is procedure?
A number of statements grouped into a single logical unit is referred to as a
procedure or subroutine which does not return any value and which is made
to complete a specific task. A program can be made of many procedures.
What are the usages/applications of functions/procedures?
Usages are as follows:
1.
Function/procedure avoids code repetition: - once a
function/procedure has been made we can call the function/procedure to
complete the task when and where necessary.

Page 29

Function/procedure used carefully makes the process of error


removing easier called debugging.
3.
Once function/procedure is tested and satisfies the ones needs,
one can convert it in to library, and can distribute it others for use.
4.
Function/procedure allows breaking bigger task into smaller
manageable subtasks which is soul of modular programming.
5.
Recursive function/procedure (function/procedure calling itself
at least once) solves some typical programming tasks easily and with
few lines of coding which otherwise would have taken several lines of
code.
2.

What do you mean by recursion? what are recursive function explain


with an example.
Expressing an entity in terms of itself is known as recursion. When
function/procedure calls itself at least once the function/procedure is called
recursive function/procedure. Recursive function/procedure contains a
function/procedure call statement to call itself normally kept inside if-else
construct. Putting function/procedure call inside if-else construct allows
termination of recursive function/procedure call after some time.
While defining a recursive function/procedure we must take care of these
two points
* Each time a function/procedure calls itself it must be closer, in some sense
to a solution.
* There must be a decision criterion for stopping recursive
function/procedure call otherwise it will execute till the stack overflows.
Write program to find factorial using recursive function
Private Sub Command1_Click ()
Dim n%, m&
n = Text1
m = fact(n)
Text2 = m
End Sub
Private Function fact&(n As Integer)
If n <= 1 Then
fact = 1
Else
fact = n * fact(n - 1)
End If
User interface:

Page 30

Create a command button: having caption find factorial


Create text1: having text property clear
Create text2: having text property clear
Create label1: having caption property set to enter a value
Create label2: having caption property set to factorial is
write program to find factorial using function.
Private Sub Command1_Click ()
Dim n%, f&
n = Text1
f = fact(n)
Text2 = f
End Sub
'Private Function fact&(byref x%) by default calling by reference
'Dim i%, f&
'f = 1
'For i = 1 To x
'f=f*i
'Next
'fact = f
'End Function
Private Function fact&(ByVal x%)
Dim i%, f&
f=1
For i = 1 To x
f=f*i
Next
fact = f
End Function
user interface:
Create a command button: having caption find factorial
Create text1: having text property clear
Create text2: having text property clear
Create label1: having caption property set to enter a value
Create label2: having caption property set to factorial is
Explain call by value and call by reference
'When called routine is not able to change value of actual argument
'Through dummy argument it is known as call by value
Private Sub Command1_Click ()

Page 31

Dim a%, b%
a = Text1
b = Text2
swap a, b
'after call
Text5 = a
Text6 = b
End Sub
Private Sub swap(ByVal a%, ByVal b%)
'default is call by reference
Text3 = a
Text4 = b
Dim temp%
'interchange
temp = a
a=b
b = temp
End Sub
call by reference:
'When called routine is able to change value of actual argument
'Through dummy argument it is known as call by reference
Private Sub Command1_Click ()
Dim a%, b%
a = Text1
b = Text2
swap a, b
'after call
Text5 = a
Text6 = b
End Sub
Private Sub swap(Byref a%, Byref b%)
'default is call by reference
Text3 = a
Text4 = b
Dim temp%
'interchange
temp = a
a=b
b = temp

Page 32

End Sub
user interface:
6 textboxes: having text property clear and having default name text1,
text2
6 labels: having caption enter value of a, enter value of b, within called
subroutine value of a, within called subroutine value of b, after call to swap
value of a, after call to swap value of b
1 command button: having caption swap and having default name
command1
Write program using passing array to function to sort and find sum of
element of an array
'passing array to function
Private Sub Command1_Click ()
Dim a%(4), x%
input_array a
sort_array a
print_array a
x = sum_array(a)
Print "sum=", x
End Sub
Private Sub input_array(a%())
'array is always passed by reference
Dim i%
For i = LBound(a) To UBound(a)
a(i) = InputBox("enter value for element")
Next
End Sub
Private Sub print_array(a%())
'array is always passed by reference
Dim i%
For i = LBound(a) To UBound(a)
Print a(i)
Next
End Sub
Private Sub sort_array(a%())
Dim i%, j%, t%
For i = LBound(a) To UBound(a)
For j = 0 To UBound(a) - 1 - i

Page 33

If a(j) > a(j + 1) Then


t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next
Next
End Sub
Private Function sum_array(a%())
Dim s%
For i = LBound(a) To UBound(a)
s = s + a(i)
Next
sum_array = s
End Function
user interface:
command1: having caption set to input, print, sum of element
Write program to sum two matrix of order 3x3 using function.
Private Sub Command1_Click ()
Dim a%(2, 2), b%(2, 2), c%(2, 2), i%, j%
MsgBox "enter value for elements of array a"
input_array a
MsgBox "enter value for elements of array b"
input_array b
sum_array a, b, c
print_array c
End Sub
Private Sub input_array(a%())
For i = 0 To 2
For j = 0 To 2
a(i, j) = InputBox("enter value")
Next
Next
End Sub
Private Sub sum_array(a%(), b%(), c%())
For i = 0 To 2
For j = 0 To 2
c(i, j) = a(i, j) + b(i, j)

Page 34

Next
Next
End Sub
Private Sub print_array(c%())
For i = 0 To 2
For j = 0 To 2
Print c(i, j) & " ";
Next
Print
Next
End Sub
user interface:
command1: having caption input,add and print
Differentiate MsgBox and InputBox
InputBox

MsgBox

Input box can be used to get user


input of data and data can be
numeric or string

MsgBox can be used to get user


input of data in integer form only
when used function format of
MsgBox. When used subroutine
format of MsgBox it can display
message only.

Input box has ok, and cancel button


only and text area to enter data.

MsgBox can have various button


like, ok, cancel, abort, retry, ignore
etc. it can display graphical symbol;
we can set focus to command
button.

Input box has following syntax

Input box has following syntax

Prompt: the text which will appear


in client are

Prompt: the text which will appear


in client are

Title: the text which will appear in


title bar

Button: button which will appear in


client area, the graphics which will
appear and the focus.

Default: the default value already

Page 35

will be shown in text area


X,y : to position InputBox at
particular location
Helpfile:specify help file which
contents help
Context: specify help context id for
input box

title: the text which will appear in


title bar
Helpfile:specify help file which
contents help
Context: specify help context id for
input box

Write program to demonstrate various string functions.


Private Sub command1_click ()
Dim d$()
a = "Hello Dear"
b = UCase(a)
Print "uppercase=" + b
b = LCase(a)
Print "lowercase=" + b
b = StrReverse(a)
Print "reverse string=" + b
a = "i am going"
b = StrConv(a, vbProperCase)
Print "proper case=" + b
a = "big mouse"
b = Mid(a, 2, 4)
Print "starting from position 2 and no. of character 4 of string 'big mouse'
will be=" + b
a = "big mouse"
b = Left(a, 3)
Print "leftmost 3 characters of string 'big mouse' is =" + b
a = "big mouse"
b = Right(a, 3)
Print "rightmost 3 characters of string 'big mouse' is =" + b

Page 36

a = "big mouse"
b = Replace(a, "m", "h")
Print "when 'm' is replaced by 'h' string 'big mouse' becomes=" + b
a = " ranu "
b = LTrim(a)
Print "removing extra space of string ' ranu ' from left=" + b + "ok"
a = " ranu "
b = RTrim(a)
Print "removing extra space of string ' ranu ' from right=" + b + "ok"
a = " ranu "
b = Trim(a)
Print "removing space from both side of string ' ranu ' from right=" + b +
"ok"
a = "i am beautiful"
d = Split(a, " ") ' each word will be stored in different
' element of dynamic string array d
Print d(0)
Print d(1)
Print d(2)
b = Join(d, ",")
Print " content of dynamic string array is joined by seperator comma:" + b
a = "i am beautiful"
n = InStr(a, "am")
Print " string 'am' appears in string 'i am beautiful' at position =" & n
End Sub
Explain date and time related functions
Private Sub Command1_Click()
Differentiate now and date functions
Print "current date and time=" & Now
Print "shows or set current date only=" & Date
Print "shows or sets current time=" & Time
Print "date part of current date=" & Day(Now)
Print "month part of current date=" & Month(Now)

Page 37

Print "year part of current date=" & Year(Now)


Print "hour part of current time=" & Hour(Now)
Print "minute part of current time=" & Minute(Now)
Print "second part of current time=" & Second(Now)
explain dateadd and datediff functions
Dim d As Date
d = #10/13/2004#
Print "three days added to date 10/13/2004 will be" & (d + 3)
Print "three days subtracted to date 10/13/2004 will be" & (d - 3)
Print "three months added to date 10/13/2004 will be" & DateAdd("m", 3, d)
Print "three days added to date 10/13/2004 will be" & DateAdd("d", 3, d)
Print "three year added to date 10/13/2004 will be" & DateAdd("yyyy", 3, d)
Print "10/13/2004 and 2/4/2003 has no. of days between=" & DateDiff("d",
#2/4/2003#, #10/13/2004#)
Print "10/13/2004 and 2/4/2003 has no. of months between=" &
DateDiff("m", #2/4/2003#, #10/13/2004#)
Print "10/13/2004 and 2/4/2003 has no. of years between=" &
DateDiff("yyyy", #2/4/2003#, #10/13/2004#)
End Sub
write program using format function to demonstrate use of format function
Private Sub Form_Click()
Dim d As Date, t As Single
d = #10/4/2004# 'date formatting
Print Format(d, "m/d/yy")
Print Format(d, "mm/dd/yyyy")
Print Format(d, "mmm/ddd/yyyy")
Print Format(d, "mmmmm,yyyy")
Print Format(d, "long date")
Print Format(d, "short date")
t = 23.45678 'number formatting
Print Format(t, "##.##")
Print Format(t, "####.##")
Print Format(t, "0,0.00")
Print Format(t, "000,0.00")
Print Format(t, "fixed")

Page 38

Print Format(t, "scientific")


Print Format(t, "00,.00") 'divide no. by 1000 and show value
Print Format(t, "0000,.00")
u = "Raman" 'format string
Print Format(u, "<") 'in small letter
Print Format(u, ">") 'in capital letter
Dim v As Date 'formatting time
v = #10:12:20 AM#
Print Format(v, "hh:mm:ss AM/PM")
Print Format(v, "long time")
Print Format(v, "short time")
End Sub
Understanding User Interface:
What is form?
Form is a container control it means that form can contain other control
inside itself. Form is a control where programmer populates other control to
construct graphical user interface. a form is instance(object) of generic class
form and we know object has certain properties or methods this is also true
for form.
List out common properties of form/write any seven properties of form.
(i)Name: this is the property possessed by any control which lets the control
identified inside code.
(ii)Appearance: forms look can be flat or 3d.
(iii)Auto redraws: if it is true control remembers what is drawn on surface of
control.
(iv) Back color: controls background color of form.
(v) Border style: controls many settings related to border, sizing of form,
placement of buttons on title bar etc.
None: no title bar, no control box, no border
Fixed: appears close button, title bar, border, form is not sizable.
Sizable: this is default and appears title bar, close, minimize, maximize,
control box all are visible.
Fixed tool window: appears close button and title bar with half height.

Page 39

Sizable tool window: same as fixed tool window except it can be sized.
(vi) Caption: returns or sets title bar text.
(vii) Draw mode: draw mode controls behaviors of newly drawn pixel on
form with existing pixel.
(viii) Draw style: controls line type of lines drawn e.g. dotted, dash dot.
(ix) Drawwidth: outline width can be set or retrieve using this property.
(x) Enabled: if enabled is true form can fire event as well as control placed
on form.
(xi) Fill color: controls color of fill pattern.
(xii) Fill style: allows to set fill pattern used to fill object which are closed.
(xiii) Font: set font name which will be used by print statement.
(xiv) Forecolor: color that controls outline color of drawing methods and
print statement.
(xv) Height: gives height of form including title bar.
(xvi) Icon: set icon which will appear in title bar.
(xvii) Key preview: keyboard event of object is invoked later on forms key
event.
(xviii) Left: gives horizontal distance of form with respect to its container
(screen or mdiparent form)
(xix) Maxbutton: set true if required maxbutton
(xx) Mdichild: makes a form mdichild form if set true.
(xxi) Maxbutton: set true if required maxbutton
(xxii) Mouse icon: set mouse pointer property to custom and set mouse icon
property to your choice.
(xxiii) Movable: if true form can be moved
(xxiv) Picture: use this property to set form background picture.
(xxv) Scale height: this property gives height of form without height of title
bar. You can use this property to divide overall height into a specified no. of
units.
(xxv) Scale width: this property gives width of form. You can use this
property to divide overall width into a specified no. of units.
(To be printed...)
Write any seven events of form.
(i) Initialize: this event is called before load event. it is fired once.
(ii) Load: this is an event which is fired automatically when a form is about
to show( due to call of method show) or load (due to call of method load).
(ii) Resize: this event is fired once when form is about to show and fired
next time when size of form changes.

Page 40

(iii) Activate: this event is fired when form is about to show and fired next
time when current form becomes active.
(iv) Deactivate: this event is fired when form becomes deactivate due to
click on title bar of other form.
(v) Unload: this event is fired when form is about to close.
(vi) Query unloads: this event is fired when form is about to close. this event
has an argument.
(vii) terminate: this is the last event fired when form is about to close.
Describe methods of form.
Method is as follows:
Though there are many methods some are of related to graphics and some
are related to control working of form.
Those which are related to working of form are as follows:
1. Show: this method causes the form to show. if form is hidden it becomes
visible.
2. Hide: this method hides the form but form still consumes memory in
computer.
3. Load: this method causes form to consume memory resources and
whatever statements are written in form load and form initialize are run but
form is not visible.
4. Unload: this method is useful to free memory resources taken by form. if
form is visible it becomes invisible.
Write program using forms demonstrating use of multiple forms./ program
to add two nos. multiply to nos. etc. each applied on different form
start new standard exe project:
it will have a form already included, type following code in form1s code
view:
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Command2_Click()
Form3.Show
End Sub
Private Sub Command3_Click()
Form4.Show

Page 41

End Sub
Private Sub Command4_Click()
Form5.Show
End Sub
Private Sub Command5_Click()
End
End Sub
user interface for form1:
command1: set caption to add
command1: set caption to sub
command1: set caption to divide
command1: set caption to multiply
command1: set caption to exit
Private Sub Command1_Click()
Text3 = CSng(Text1) + CSng(Text2)
End Sub
Private Sub Command2_Click()
Unload Me 'me means current form
Form1.Show
End Sub
user interface for form2:
label1: set caption to enter first value
label2:set caption to enter second value
label3:set caption to result
command1: set caption to add
command2:set caption to back
similary design interface and code for form3, form4, form5 etc. but dont
forget to change operator sign and caption of command button1.
Explain frame control. List the advantages of using a fame control in
vb?
Frame is a container control. it means that this control can be used to place

Page 42

other controls inside it.


Advantages of frame control:
1.
We can use frame control to place option buttons and create different
set of option buttons user can choose any one option button from each set. if
we dont use frame we can not create different sets of option buttons and
user can select only on option button.
2.
Controls used on form if are logically related we can place them
inside frame to give use clue that those controls are interrelated thus
increasing readability.
3.
Frame control decorates form.
4.
If we set enabled property to false of frame control all it child control
will become disabled and vice versa.
Useful property: caption-the text which appear in frame upper left corner.
Enabled-if set true child controls will be enabled otherwise disabled.
What are menus? Explain the process of creating menus in vb:
Menus are convenient means to place and organize commands that
application supports in structured manner. Menu avoids putting of several
command buttons to initiate the same sequence of commands supported by
application. Menu prevents overcrowding of form from command buttons.
Menu is composed of following items:
a. Menu bar: the place where first level menu items appear are known as
menu bar. The first level menu are placed on menu bar and provided hot
keys and are known as menu pads. Menu pads can not have short-cut.
b. Pull down menu: when menu pad is activating pull down menu
appears which is the next level menu items.
c. Submenu or cascading menu: second level menu item normally
initiates a command or another submenu (which is actually third level menu
items). Though we can have fourth level submenus yet these are not
frequently used.
Process of creating menu:
Demo using menu to make text box text bold, italic, underline.
Press control+e to bring menu editor dialog:
Enter following information in menu editor dialog use left or right arrow,
right arrow key to change indentation level, next button to create new item
as necessary.
Caption
Name
Shortcut
Indentation level
&Format

MnuFormat

First

Page 43

&Bold

Mnubold

Ctrl+b

Second

&Italic

Mnuitalic

Ctrl+i

Second

&Underline
Mnuunderline
Ctrl+u
place a text box on form with name text1
and type following event procedure codes :
private sub mnubold_click()
text1.fontbold=not text1.fontbold
end sub
private sub mnuitalic_click()
text1.fontitalic=not text1.fontitalic
end sub
private sub mnuunderline_click()
text1.fontunderline=not text1.fontunderline
end sub
run the project and click on menu items.

Second

Describe options of menu editor.


Options are as follows:
Name: allows you to enter a control name for the menu item. a control name
is an identifier used only to access the menu item in code; it doesnt appear
in a menu.
Index: allows you to as a numeric value that dermjines the controls position
withing a control array. This position isnt related to the screen position.
Shortcut: allows you to select a shortcut key for each command.
Help context id: allows you to assign a unique numeric value for the context
id. This value is used to find the appropriate help topic in the help file
identified the help file property.
Negotiate position: allow you to select the menus negotiate position
property. The property determined whether and how the menu appears in a
contain form.
Checked: allows you to have a check mark appear initially at the left of a
menu item. It generally used to indicate whether a toggle option is turned on
or off.
Enabled: allows you to select whether you want eh menu item to respond to
events, or clear if you want the item to be unavailable and appear dimmed.
Visible: allows you to have the menu item appear on the menu.
Window list: determines if the menu control contains list of open mdi child
forms in an mdi application.

Page 44

Right, left, up, down arrows: allows menu item indent, outset, move up,
move down.
Menu list: a list box that displays a hierarchical list of menu items. Submenu
items are indented to indicate their hierarchical position or level.
Next: move selection to the next line.
Insert, delete: insert inserts a new menu item and delete deletes a menu item.
ok: make menu item changes applied.
Cancel: to abandon changes in menu items.
Differentiate menu and submenu.
Menu

Submenu

Menu contains submenu

Submenu may contain other sub


menu

Menu appear in menu bar

Submenu appears in pull down


menu when menu pad is click

Menu is first level menu item in


menu editor

Submenu is second or further level


menu items

Menu cannot have shortcut keys

Submenu can have short cut keys

Menu can have window list item


turned on in case of mdi application

Submenu does not uses this setting.

differentiate sub-procedure and function procedure.


Subroutine
Function
Sub procedure is more commonly
known as procedure only.

Function procedure is more


commonly known as function.

Subroutine does not return a value


to calling routine therefore a
variable can not appear in left side
of assignment operator.

Function returns a value to calling


routine therefore a variable can
appear in left side of assignment
operator.

Subroutine is used commonly when


results many result are being
produced.

Function is used commonly when a


single result is being produced.

Page 45

It uses sub..end sub keywords

It uses functionend function


keywords.

Differentiate list box and combo box.


List box
List box contains list of items and
user can select more than one items
from list box

Combo box
Combo box contains list of items
and user can select any one item
from list

List box does not have text area


Combo box has text area and user
where user can type new item not in can type new item not in list
list portion.
List box has two style settings:
Combo box has three style settings:
standard and check. check style puts simple, dropdown and dropdown
check box before each item and user list.
can tick mark items to select
It has properties: multiselect,
columns, selected, selcount which
are not available in combo box.

It has properties: sellength, seltext,


selstart which are not available in
list box.

Height of list box can be changed

Height of combo box is constant


and can not be changed.

It has item check event.

It does not fire item check event.

Differentiate check box and option button.


Checkbox

Option button

Check box control displays


rectangle where user can click to
item select/unselect.

Option button displays circle where


user can click to put dot to select
item.

We can have multiple check boxes


selected

We can have only one option button


selected among set of option buttons

Page 46

The value property of check box


contains 1 if tick mark present or 0
if tick mark is absent.

Option button value property is true


when dot is present in circle
otherwise false.

It is not compulsory to put check


boxes in container control like
frame or picture box to create many
sets.

It is compulsory to put option


buttons in container control like
frame or picture box to create many
sets

These controls are useful when we


want user to select more than one
items

These controls are useful when we


want user to select any one out of
more than one items.

Differentiate binary and random file


Binary
Random
It is to read or write data such as
data of ole controls, image files,
data field in a table of data type
blob(binary large object) etc. less
commonly used to read text data.

Random files are used to read write


text data in terms of fixed record
length. less commonly used to
read/write binary data in terms of
fixed length record.

It does not allow random access

It allows random access of data.

Binary can make use of input


function

Random can not make use of input


function.

Type..end type statement is not


useful.

Type..end type statement is used to


created user defined data type
which helps to create fixed record
length.

differentiate sequential and random access file.


Sequential
Random
Sequential does not use record of
fixed length.

Random uses record of fixed length.

Sequential is useful to read text data Random can be used to read text

Page 47

in sequence.

and binary data in terms of fixed


record length.

Sequential allows slow access of


record

Random allows fast access of record


randomly.

Sequential file can use following


statements which random file can
not use: input, input#,line input
,print #,write#

It can use get and put statement


which can not be used by sequential
file.

differentiate image box and picture box.


Image box
Picture box
Image box is designed specifically
for displaying picture.

Picture box is designed for


displaying picture as well as
drawing graphics.

It consumes less system resources


and redraws picture fastly.

It consumes more system resources


and redraws picture slowly.

Image box is not a contained control Picture box is container control it


it means that other control can not
means that we can place other
be placed inside it.
control inside it.
If has properties and methods dissimilar to form. it has stretch
property which when set true
picture is stretched to fit in image
control.

It has properties and method similar


to that of form therefore it is some
times known as form within form. it
has autosize property which when
set true picture box resizes itself to
fit picture.

write short notes on keyboard events.


Private Sub Command1_Click()
MsgBox "name=" & Text1 & "age=" & Text2 & "salary=" & Text3
End Sub
Private Sub Text1_Change()
'this event is fired when textbox contain changes

Page 48

End Sub
Private Sub text1_GotFocus()
'select text if text1 receives focus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
'this event is fired when user presses a key reports ansi value of key pressed
If KeyAscii = 13 Then 'ascii value of enter key
SendKeys "{tab}"
End If
'avoid appearance of invalid keys
'keyascii for backspace is 8
If InStr("ABCDEFGHIJKLMNOPQRTSTUVWXYZ ,.",
UCase(Chr(KeyAscii))) = 0 And KeyAscii <> 8 Then
KeyAscii = 0
End If
'turn on letters to appear in caps
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End If
End Sub
Private Sub Text1_Keydown(KeyCode As Integer, Shift As Integer)
'this event is fired after keypress , when key is released
'keycode reports code , shift reports control,shift,alter keys status
If Chr(KeyCode) = "A" And Shift = vbCtrlMask Then 'means control+A
Text1.SelText = "Mr."
ElseIf Chr(KeyCode) = "A" And Shift = vbAltMask Then 'means alter+A
Text1.SelText = "Mrs."
ElseIf Chr(KeyCode) = "A" And Shift = vbCtrlMask + vbShiftMask Then
'means control+shift+A
Text1.SelText = "Miss"
ElseIf KeyCode = vbKeyF1 Then
Text1.SelText = "Welcome"
End If
End Sub

Page 49

Private Sub Text1_Validate(Cancel As Boolean)


'this event is fired when text box is about to lose focus
'if cancel argument is assigned value true, text box can not lose focus
If Len(Trim(Text1)) = 0 Then
MsgBox "please type name"
Cancel = True
End If
End Sub
What is mdi form?/write short notes on mdi form/ what are benefits of
mdi form?.
mdi form is a form which can be used to create mdi application. only one
mdi form can be used in a project as soon as an mdi form is added the
command becomes unavailable. more than one mdi childs can be attatched
to a single mdi-parent form. some application like ms-word, ms-excel are
using mdi concept. the benefits of using mdi application are as follows:
a. user can open more than one document
b. data easily can be transferred from one document to other
document.
c. we can view more than one file side by side using tile command
of windows menu.
d. we can not move document window( mdi child form) outside
border of mdi parent window.
e. when menu system is defined on both mdi-parent and mdi-child
as soon as mdi child window appear it replaces menu system defined in mdiparent.
f. when menu system is defined only in mdi-parent appearance of
mdi-child window does not cause dis-appearance of mdi-parent menu.
g. closing of mdi-parent window causes closing of all mdi-child
windows.
Write steps involved to create mdi form.
let us define steps involved in creating mdi forms:1. start a new standard exe project: project will contain a form name
form1
2. from project menu select add mdi form : name of mdi form is
mdiform1
3. select form1 and set its mdichild property to true
4. inside code view of mdiform1 :

Page 50

declare an array by using statement


dim f(2) as new form1
in general declaration section
insert following statements in mdiform_load event of mdiform1
f(0).Caption = "document1"
f(0).Show
f(1).Caption = "document2"
f(1).Show
f(2).Caption = "document3"
f(2).Show
5. make the mdiform1 as startupobject : use project->properties->startup
object->mdiform1
6. run the project using f5
What is short cut for running the project?
f5
Describe Select Case..End select/
select case.. end select statement
The control statement which allows us to make a decision from the number
of choices is called a select, or more correctly a select case case else- end
select. Since these three keywords go together to make up the control
statement. They most often appear as follows:
select case(integer or string expression)
case is >= constant1:
do this
and this
case constant2
do this
and this
case constant 3 to constant 4
do this
do this
case constant5,constant6 , constant7
do this
do this
case else
do this
do this
end select

Page 51

the integer expression following the keyword select-case is any vb


expression that will generate an integer value or string constant. It could be
an integer constant like 1,2,3 or an expression that evaluates to an integer or
any string constant .
When a match is found, then program executes the statements following that
case, and all subsequent cases and default statements are not executedl. If no
match is found with any of the case statement, only the statements following
the case-else are executed. A few examples will show how this control
works.
Write program to demonstrate mdi form arrange method, menu
replacement and opening and saving text file.
ans:
in form1 design following menu
mnufile
&File
mnuopen &Open
mnusave
&Save
mnusep
mnuclose &Close
mnuwindow &Window (turn on window list check box)
mnuarrange &Arrange Icons
mnucascade &Cascade
mnutilehor Tile &Horizontal
mnutilever Tile &Vertical
in mdiform1 design following menu
mnufile
&File
mnuopen &Open
mnusep
mnuexit
&Exit
form form1 set mdichild property true
for mdiform1 set autoshowchildren property false
place text1 on form1 and set its multiline true and scrollbars to 3.
(A)type following code in form1:
Private Sub Form_Resize()
Text1.Move 0, 0, Form1.Width, Form1.ScaleHeight
End Sub

Page 52

Private Sub mnuArrange_Click()


MDIForm1.Arrange vbArrangeIcons
End Sub
Private Sub mnucascade_Click()
MDIForm1.Arrange vbCascade
End Sub
Private Sub mnuClose_Click()
Unload MDIForm1.ActiveForm
End Sub
Private Sub mnuNew_Click()
MDIForm1.mnuNew_Click
End Sub
Private Sub mnuOpen_Click()
MDIForm1.mnuOpen_Click
End Sub
Private Sub mnuSave_Click()
Dim filename As String
If InStr(UCase(Me.Caption), "DOCUMENT") <> 0 Then
filename = InputBox("enter text file name to save with complete path")
Else
filename = Me.Caption
End If
Open filename For Output As #1
Me.Caption = filename
t = Text1
Print #1, t
Close #1
End Sub
Private Sub mnutilehor_Click()
MDIForm1.Arrange vbTileHorizontal
End Sub
Private Sub mnutilever_Click()
MDIForm1.Arrange vbTileVertical
End Sub
(B) put following coding in mdiform

Page 53

Private Sub mnuExit_Click()


End
End Sub
Public Sub mnuNew_Click()
Dim f As New Form1
Static i%
f.Caption = "document:" & (i + 1)
i=i+1
f.Show
End Sub

Public Sub mnuOpen_Click()


'coding to open file
Dim filename As String
filename = InputBox("enter text file name with complete path")
Open filename For Input As #1
Form1.Text1 = Input(LOF(1), 1)
Form1.Caption = filename
Close #1
End Sub

What is meant by event driven programming in vb? Event driven


programming vs procedure oriented programming.
When a program consists of one or more than one event procedures and

Page 54

those procedures accomplish the task to be done by program it is know as


event driven programming.
Event is any action performed by either performed by user or performed by
program itself. For example mouse-click, key press, window resize etc.
Structured/Procedure Oriented

Event Driven Programming

Program consists of one or more


procedure.

Program consists of one or more


event procedure.

Programming task is completed by


procedure.

Programming task is completed by


event procedure.

The order of execution of procedure The order of execution of event


is more or less predictable.
procedure depends on user
performed action.
Procedure oriented programming is
not suitable for window based
application.

Event driven programming is


suitable for window based
application.

Write control instruction with example.


Control instruction decides the flow of control of the program. There are
many control instructions available in vb. Control instruction can be
categorized as :
1. Conditional branching: conditional branching statement allows to execute
some statement under one condition and other statements under some other
condition. It is also known as selection statements.
it includes if..else.endif, select case end select
2. Looping: if we want to run some set of statement again and again till the
given condition is true, we can use loop controls.
It includes do loopwhile, do while loop, while wend, forend for
For example of each control instruction please refers other pages in notes.
What is various types of operators in vb list them in each category.
Arithmetic operator:
+ For addition,
- For subtraction.
* For multiplication
\ For integer division
c=10\3 c will be 3\

Page 55

/ For float division c= 10/3 c will be 3.333


^ For power e.g. c=10^3 therefore c will be 1000
Mod for modulo division c=10 mod 3 c will be 1
Relation operator
>,>=,<,<=,=, <>
Logical operator
And, or, not
Assignment =
Write data types used in vb.
Data type of variable defines range, memory and valid operation for a
variable
Data type
Range
Memory
1.Byte

0 , 255

2.Integer %

32767 , 0 , -32768

3. Single !

+/- 3.4 e +34

4.Double #

+/- 1.7 e+308

5.Date

1-1-100 to 31-12-9999

6.string(variable) $

2 billion characters

6.string(fixed) $
7.boolean

True, false

8.object

Reference of any
object

9. variant

Range for number is


same as double
Range for string is
same as 2 billion
characters

Page 56

What is mdi form, write five main differences between mdi and sdi
application.
What is mdiform ? How will you create mdi parent and child form.
What is SDI? Explain it.
What do you understand by MDI? Write with example? How it is better
than SDI.
mdi form is a form which can be used to create mdi application. Only one
mdi form can be used in a project as soon as an mdi form is added the
command becomes unavailable. more than one mdi Childs can be attached
to a single mdi-parent form. Some application like ms-word, ms-excel are
using mdi concept.
the benefits of using mdi application over sdi application are as follows:
h. user can open more than one document while in sdi only one
document can be opened at a time.
i. data easily can be transferred from one document to other
document using drag and drop and we can see content of more than one
document at a time.
j. we can view more than one file side by side using tile command
of windows menu.
k. we can not move document window( mdi child form) outside
border of mdi parent window.
l. when menu system is defined on both mdi-parent and mdi-child
as soon as mdi child window appear it replaces menu system defined in mdiparent.
m. when menu system is defined only in mdi-parent appearance of
mdi-child window does not cause dis-appearance of mdi-parent menu.
n. closing of mdi-parent window causes closing of all mdi-child
windows.
Sdi application on the other hand allows to open only one document at a
time. If we have already open a document and try to open another document
the application will ask to close the current document only then we can open
other document.
Steps involved to create mdi form.
let us define steps involved in creating mdi forms:7. start a new standard exe project: project will contain a form name
form1
8. from project menu select add mdi form : name of mdi form is
mdiform1 by default and this form will be mdiparent form
9. select form1 and set its mdichild property to true then this form will
be mdichild form.

Page 57

inside code view of mdiform1 :


declare an array by using statement
dim f(2) as new form1
in general declaration section
insert following statements in mdiform_load event of mdiform1
f(0).Caption = "document1"
f(0).Show
f(1).Caption = "document2"
f(1).Show
f(2).Caption = "document3"
f(2).Show
11. make the mdiform1 as startupobject : use project->properties->startup
object->mdiform1
12. run the project using f5
10.

Describe scope of variable.


What do you mean by scope and duration of a variable.
Scope specifies the code range where value of variable is accessible.
d. local variable: accessible inside a function or procedure. we use dim
keyword to declare local variable.
e. module level global variable: accessible inside a module but not
outside from other module. we use dim or private keyword to declare
module level global variable and declare it inside general declaration of
module.
f. global variable : accessible from every where. we use public or global
keyword to declare global variable inside general declaration of module.
Duration of a variable is also known as life time of variable, it means how
long memory remain allotted to a variable?
Explain procedure in vb.
What is procedure?
a number of statements grouped into a single logical unit is referred to as a
procedure or subroutine which does not return any value and which is made
to complete a specific task. A program can be made of many procedures.
Usages are as follows:
1.
Function/procedure avoids code repetition:- once a function/procedure
has been made we can call the function/procedure to complete the task when
and where necessary.
2.
Function/procedure used carefully makes the process of error

Page 58

removing easier called debugging.


3.
Once function/procedure is tested and satisfies the ones needs, one
can convert it in to library, and can distribute it others for use.
4.
Function/procedure allows breaking bigger task into smaller
manageable subtasks which is soul of modular programming.
5.
Recursive function/procedure (function/procedure calling itself at
least once) solves some typical programming tasks easily and with few lines
of coding which otherwise would have taken several lines of code.
Example of procedure:
Demonstration of call by value and call by reference
'When called routine is not able to change value of actual argument
'Through dummy argument it is known as call by value
Private Sub Command1_Click ()
Dim a%, b%
a = Text1
b = Text2
Swap a, b
'After call
Text5 = a
Text6 = b
End Sub
Private Sub swap (By Val a%, By Val b%)
'Default is call by reference
Text3 = a
Text4 = b
Dim temp%
'Interchange
Temp = a
a=b
b = temp
End Sub
Call by reference:
'When called routine is able to change value of actual argument
'Through dummy argument it is known as call by reference
Private Sub Command1_Click ()
Dim a%, b%
a = Text1
b = Text2
Swap a, b

Page 59

'After call
Text5 = a
Text6 = b
End Sub
Private Sub swap(Byref a%, Byref b%)
'Default is call by reference
Text3 = a
Text4 = b
Dim temp%
'Interchange
Temp = a
a=b
b = temp
End Sub
user interface:
6 textboxes: having text property clear and having default name
text1,text2
6 labels: having caption enter value of a, enter value of b, within called
subroutine value of a, within called subroutine value of b, after call to swap
value of a, after call to swap value of b
1 command button: having caption swap and having default name
command1
What is IDE? Discuss any five components.
Ide stands for integrated development environment. it is collection of
program allowing to compose and edit the program, test the program, run the
program and debug the program.
Major components of vb Ide:
1. Project startup dialog box: when we start vb program we get a dialog box
which gives choice of project type to start.
2. Project explorer window: project explorer window allows browsing
different modules that make up our project. We can switch from one module
to other module. We can see the object view, code view of the module. We
can make save and save as the module, we can add new module from within
the project explorer window.
3. Form layout window: using form layout window we can set the startup
position of a form on screen.
4. Immediate window: using this window we can set new value for a
variable while the project in debug window. We can check syntax of
statement and function and we can use it as calculator also.

Page 60

5. Toolbox: toolbox contains various controls which we can place on form.


6. Properties window: using this window we can set properties of a selected
control or module.
7. Form window: here we can place various control to design GUI for
program.
Describe in brief all mouse events with example.
Explain mouse events in VB
Mouse events are those events which are generated by mouse actions such as
1.
Mouse down: this event is fired when mouse button is hold down.
This event reports mouse coordinate and button number which was press
2.
Mouse up: this event is fired when mouse button is left up. This event
reports mouse coordinate and button number which was press
3.
Mouse move: this event is fired when mouse is moved. This event
reports mouse coordinate.
4.
Click: this event is fired when mouse button is hold down and left up.
This event reports mouse coordinate and button number which was press
5.
Dblclick: this event is fired when mouse button is double clicked. This
event reports mouse coordinate and button number which was press
6.
Drag drop: this event is fired when control is dragged and dropped
over other control.
7.
Drag over: this event is fired when control is being dragged and enters
the region of control on to which it is to be dropped.
Start new standard exe project in vb and in code view window type
following code to observe mouse events:
Private Sub Form Click ()
Print "i am mouse click"
End Sub
Private Sub Form_DblClick ()
Print "i am mouse dblclick"
End Sub
Private Sub Form_MouseDown (Button As Integer, Shift as Integer, X As
Single, Y as Single)
Print "i am mouse down reporting mouse coordinate and button"
End Sub
Private Sub Form_MouseMove (Button As Integer, Shift as Integer, X As

Page 61

Single, Y as Single)
Print " i am mouse move"
End Sub
Private Sub Form_MouseUp (Button As Integer, Shift as Integer, X As
Single, Y as Single)
Print "i am mouse up reporting mouse coordinate and button"
End Sub

Explain data report.


or
Write down the step of generating report in vb through data
environment
or
What do you mean by data report and how will you create data report?
Explain crystal report.
Data report
Data report is a reporting tool available in vb6.0. it is new feature of vb6.0.
We can create, maintain, and access databases from within a visual basic
application. The final piece of this set of building blocks is the capability to
report on the data stored in the database. With vb6.0 we have a built-in
reporting designed that works with the new data environment. Data report
designer gives the capability to create database reports without using any
third-party tools such as crystal report writer. It has following
Features of data report:
a.
Drag and drop field placement: we can drag and drop the fields
needed in report from data environment and vb automatically sets data
member and data field property.
b.
Toolbox controls: the data report designer has its own set of control,
which are automatically added to the toolbox on their own tab named Data
report
c.
Print preview: we can print the report in code by using the print report
method or clicking the print button on the toolbar when in preview mode.
d.
File export: we can export the report in html, text or Unicode format
using the export report method.
Steps of creating Data report using data environment:
Suppose there is an ms-access database file having name: StudentInfo.mdb

Page 62

Suppose it contains a table having name: student


Suppose the table contains following fields: roll no, name, class
It is required to prepare the report file then the steps required will be as
follows:
(1) Setting the data environment:
A. project-> add data environment
B. in project explorer window double click on dataenvironment1
C. right clicks on connection1 and selects properties
D. double click on Microsoft jet 4.0 ole db provider
E. on select or enter database name click command button with caption
F. selects the database student info from the location
G. click on ok to close data link properties dialog box.
H. right clicks on connection1 and select add command.
i right click on command1 and select properties
j on database object select table
k on object name select student
l click on ok
(2) Preparing data report
A. project-> add data report
B. select the data report and set its data source property to
dataenvironment1, and data member property to command1
C. right click on data report and select retrieve structure and click on yes
D. drags the command1 from dataenvironment1 and drops it on detail
section
Properly adjust the fields on detail section
e.
click on rptlabel on toolbox on data report tab
And draw it on report header section and set its caption property to Student
List
(3) Set data report1 as startup object for this, use project->properties->start
up object-> datareport1
Save and run the project
Crystal Report:
We can create, maintain, and access databases from within a visual basic
application. The final piece of this set of building blocks is the capability to
report on the data stored in the database.
Crystal report is a third party report writing tool. It is created by Seagate
technology it ships with visual basic6.0. Newer version of crystal report
writer 9.0 supports use of data environment as data source and variety of
other data sources that is used with crystal report 9.0. it takes approximately

Page 63

300 mb of Hard disk space to install


f.
Drag and drop field placement: we can drag and drop the fields
needed in report from data environment and crystal report automatically sets
data member and data field property.
g.
Toolbox controls: the crystal report designer has its own set of control
h.
Print preview: we can get print preview.
i.
File export: we can export the report in html, text or Unicode format
j.
Provides it own set of formulas for complex calculation.
k.
Provides reporting based on condition which makes a single report to
be used on multiple situations.
What are dialog boxes? Explain different type of dialog boxes available
in vb?
Dialog boxes are windows that are quite commonly used for displaying
some message or to collect some data from the user so as to perform some
operation. Dialog boxes have fixed border and cannot be resized. It has close
button, title bar and we can work on any other window in same application
until we close it normally.
VB offers two dialog boxes ready to use
InputBox
MsgBox
Input box can be used to get user
input of data and data can be
numeric or string

MsgBox can be used to get user


input of data in integer form only
when used function format of
MsgBox. When used subroutine
format of MsgBox it can display
message only.

Input box has ok, and cancel button


only and text area to enter data.

MsgBox can have various button


like, ok, cancel, abort, retry, ignore
etc. it can display graphical symbol;
we can set focus to command
button.

Input box has following syntax

Input box has following syntax

Prompt: the text which will appear


in client are

Prompt: the text which will appear


in client are

Title: the text which will appear in

Button: button which will appear in

Page 64

title bar
Default: the default value already
will be shown in text area
X,y : to position InputBox at
particular location
Helpfile:specify help file which
contents help
Context: specify help context id for
input box

client area, the graphics which will


appear and the focus.
title: the text which will appear in
title bar
Helpfile:specify help file which
contents help
Context: specify help context id for
input box

What is property?
Property of any object is actually member procedure which allows to set
value in data member (working as mutator) or allows to retrieve value of
data member (working as accessory).
Properties of textbox for example are:
1. name: this is property by which a textbox can be differentiated from
other control
2. height: height of the text box control
3. width: width of the text box control
4. locked: controls whether content of text box can be edited(locked:
false) or cannot be edited(locked: true)
5. Enabled: controls whether the text box can fire event or not.
6. Text: controls the text that is to be shown in text box Etc.
What do you understand by front-end tool and back-end tool?
Front end-tool normally provide graphical user interface or collect data or
service request from the user. Front end tool require some data in order to
fulfill requirement of user service for which it depends on back-end.
Programming languages normally works as front end tool. For example
visual basic application for library management system is a front end tool. In
order to save, retrieve and report data it requires support of back end tool
such as ms-access, oracle etc.
What are the connectivity features?
Or

Page 65

What are DAO, ADO AND RDO?


Or
Write the features of ado and difference between ADO, RDO and DAO
ADO (ActiveX data access Object):
It uses Universal data access specification that means ADO can use data
from variety of data sources. ADO is the application programming interface
used to access information. Using ADO we can perform the following
sequence of actions.
1. Connect to a data source. Optionally you can ensure that all changes
to the data source occur either successfully or not at all
2. Specify a command to gain access to the data source
3. Execute the command if the command causes data to be returned in
the form of rows in a table, store the rows in a cache that you can easily
examine, manipulate or change.
4. if appropriate, update the data source with changes from the cache of
rows
5. Provide a general means to detect errors.
Features of ADO
Typically we will use all theses steps in the programming model. However,
ADO is flexible enough that we can do useful work by executing just part of
the model.
ADO object hierarchy is less hierarchical than RDO. Size of ADO object
library is less than RDO and DAO. ADO is faster than RDO in performance.
ADO provides greater no. of events than RDO and DAO. It uses command,
connection, error, field, parameter, property, recordset objects. It uses errors,
parameters, fields, properties collections
DAO (Data access Object):
DAO is the oldest data access technology available in vb. Primary it was
developed to write desktop database application with no client/server data
base application development in mind.
It can uses data through MS-jet database engine and ODBC. DAO object
hierarchy is hierarchical. Size of DAO object library is larger than RDO and
ADO. DAO is slower than ADO and RDO in performance. DAO provides
least no. of events than ADO and RDO.
It uses dbengine, workspace, error, database, tabledef, querydef, recordset,
field, index, parameter, user, group, relation, property, container and
document objects.
It uses databases, users, groups, properties, errors, querydefs, recordsets,

Page 66

containers, relations, tabledef, fields, indexes, parameters, connections,


workspaces, collections.
RDO (Remote Data access Object)
RDO was developed after DAO. It was primary aimed to develop
client/server database application development.
It can use data through ODBC. ODBC was created to access data from only
relational database. RDO object hierarchy is less hierarchical than DAO.
Size of RDO object library is less than DAO. RDO is slower than ADO in
performance. RDO provides greater no. of events than DAO.

DIFFERENCE AMONG ADO, DAO, RDO


ADO

DAO

RDO

It uses Universal data It can uses data through It can use data through
access specification
MS-jet database engine
ODBC. ODBC was
that means ADO can
and ODBC
created to access data
use data from variety
from only relational
of data sources. ADO
database.
is the application
programming interface
used to access
information.
ADO object hierarchy
is less hierarchical than
RDO

DAO object hierarchy


is hierarchical

RDO object hierarchy


is less hierarchical than
DAO

Size of ADO object


library is less

Size of DAO object


library is large

Size of RDO object


library is less than
DAO

ADO is faster than


RDO in performance

DAO is slower than


RDO in performance

RDO is slower than


ADO in performance

Page 67

ADO provides greater DAO provides least no. RDO provides greater
no. of events than RDO of events
no. of events than
DAO
It uses command,
connection, error, field,
parameter, property,
recordset objects.

It uses db engine,
workspace, error,
database, tabledef,
querydef, recordset,
field, index, parameter,
user, group, relation,
property, container and
document objects.

It uses errors,
parameters, fields,
properties collections

It uses databases, users,


groups, properties,
errors, querydefs,
recordsets, containers,
relations, tabledef,
fields, indexes,
parameters,
connections,
workspaces,
collections.

What is dynamic array? What are the advantages of Dynamic Array?


Dynamic array is an array whose no. of elements is not specified earlier. No.
of elements can be requested from user at program run time. Redim keyword
can be used to allocate memory for such no. of elements. After allocating
memory we can store value in elements of array.
Dynamic array saves memory because we have to allocate memory for such
many elements which we want to use.
EXAMPLE: PROGRAM TO SORT AN ARRAY USING DYNAMIC
ARRAY
Dim a %(), n 'note element is not specified
Private Sub Command1_Click ()
Dim i%
take no. of elements required
n = InputBox ("enter no. of elements")

Page 68

'Allocate memory
ReDim a(n - 1) ' workout
For i = LBound(a) To UBound(a)
a(i) = InputBox("enter value", "data entry", 1)
Next
End Sub
Private Sub Command2_Click()
Dim i%, j%
For i = LBound(a) To UBound(a) - 1
For j = LBound(a) To UBound(a) - 1 - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next
Next
End Sub
Private Sub Command3_Click()
Dim i%
For i = LBound(a) To UBound(a)
Print a(i)
Next
End Sub
place command1:having caption set to input
place command1:having caption set to sort
place command1:having caption set to print

Write various data conversion function along with its syntax.


Functions whose name begins with c<type> convert an express from any
data type into the specified data type.
Sample syntax:
A=cbool(int) convert from integer to Boolean
B=cbyte(int) convert from integer to byte
C=ccur(dbl) convert from double to currency
D =cdate(dbl) convert from double to date

Page 69

E=cdec(hex) convert from hexadecimal to decimal


F=cdbl(vint) convert from variant to double
G=cint(long) convert from long to integer
H=clng(vint) convert from variant to log
I= csng(curr) convert from currency to single
J=cstr(dbl) covert from double to string
K=cvar(lng) convert from long to variant
Explain the use of progress bar in vb. Write the step to print a progress
bar on form.
or
Explain the use of progress bar and timer control in vb.
Progress bar control is a control to give the user feedback that some process
is going on and the user must wait for some time to finish the current ongoing process. Progress bar uses timer control which helps in fill in the
progress bar.
Example: following example lets the user wait for two seconds
Steps
1.
start new standard exe project
2.
project->components -> place tick mark before Microsoft windows
common control 6.0 (sp2)->ok
3.
place progress bar, and timer control on form.
4.
set timer interval to 100 ( timer event of timer control will fire in
every 1/10 th second)
5.
set max to 60 and min to 0 for progress bar control
6.
right click on form and select code view window and type following
code
Private Sub Timer1_Timer()
If ProgressBar1.Value < 60 Then
ProgressBar1.Value = ProgressBar1.Value + 6
End If
End Sub
What do you mean by ODBC?
ODBC stands for open database connectivity. It is set of application
programming interface written generally in c, c++ and assembly language to
interact with wide variety of database supplied by different database
vendors.
ODBC provides a set of application programming interface that all

Page 70

developers could use, to connect and use databases and it was ODBCS and
ODBC drivers responsibility to figure out how to talk to the database. As
long as an ODBC driver was available for the database management system
you were using, you only had to write your application to access the ODBC
API. If an ODBC driver was not available, you had have to write to that
DBMSS API, or you had have to find some other method to access the
database though some middleware product, such as Intersolvs Q+E data
drivers.
Write a program for storing the item database with field item name,
item number, price, rate per item in sequential file and read data from
the file.
Steps
1. start new visual basic standard exe project
2. place five labels, five text boxes and two command buttons
set following properties:
label1 caption
enter name
label2 caption
enter item number
label3 caption
enter sale price
label4 caption
rate per item
text1 text
clear
text1 name
txtname
text2 text
clear
text2 name
txtitemnumber
text3 text
clear
text3 name
txtsaleprice
text4 text
clear
text4 name
txtrateperitem
text5 text
clear
text5 name
txtrecord
text5 multiline
true
text5 scrollbars both
command1 caption
addrecord
command2 caption
showrecord
command1 name
cmdaddrecord
command2 name
cmdshowrecord
3. write following code in code view window
Private Sub cmdaddrecord_Click()
Open "data" For Append As #1
Print #1, txtname

Page 71

Print #1, txtitemnumber


Print #1, txtsaleprice
Print #1, txtrateperitem
Close #1
txtname = ""
txtitemnumber = ""
txtsaleprice = ""
txtrateperitem = ""
End Sub
Private Sub cmdshowrecord_Click()
Dim a$
Open "data" For Input As #1
txtrecord = "name,item number,sales price,rate per item" + vbCrLf
Do While Not EOF(1)
Input #1, a
txtrecord = txtrecord + a
Input #1, a
txtrecord = txtrecord + "," + a
Input #1, a
txtrecord = txtrecord + "," + a
Input #1, a
txtrecord = txtrecord + "," + a + vbCrLf
Loop
Close #1
End Sub
Differentiate different type of recordset.
Recordset is set of records in memory resulted due to execution of query.
Dynaset
Table type
Snapshot
This type of recordset
is updateable

This type of record set


is also updateable

This type of recordset


is read-only and
forward

We can use sql query


for this type of record

We can use table name


and we can not use sql

We can use table name


and sql query

Page 72

query
It may take less than or It takes higher memory It may take less than or
equal to memory taken
equal to memory taken
by table type
by table type
It is slower

It is slower in
performance

It is faster

We can use find


command and we can
use index

We can make use of


index to faster search
the record

We can use find


command and we can
use index

Write short notes on VBP.


or
What is project file? why it is needed?
Project file contains information about all those file which make the project.
It stores location of individual file with path. When saving project it saves
all files one by one inside project. When we open project it automatically
opens all files which are part of project we need not to open each file one by
one thus saving time. Project file has extension vbp.
Write short notes on list box and combo box
List box:
List box contains list of items and user can select more than one items from
list box
List box does not have text area where user can type new item not in list
portion.
List box has two style settings: standard and check. check style puts check
box before each item and user can tick mark items to select.
It has properties: multiselect, columns, selected, selcount which are not
available in combo box. Height of list box can be changed. It has item check
event.
Combo box:
Combo box contains list of items and user can select any one item from list.
Combo box has text area and user can type new item not in list. Combo box
has three style settings: simple, dropdown and dropdown list.
It has properties: sellength, seltext, selstart which are not available in list

Page 73

box. Height of combo box is constant and can not be changed.


It does not fire item check event.
Both list box and combo box can be used to give user many choices and user
can select choice from the list.
Following are the common properties:
1. List: it is an array property which holds the item in the list portion.
2. List index: it is a property that gives index of the item selected and we
can make an item selected. If no item is selected then it value is -1.
3. Sorted: if true then items are arranged.
4. List count: gives no. of items in list portion.
Following are the common methods:
1. Clear: it is useful to remove all items from list portion.
2. Add item: it is useful to add an item in list portion.
3. Remove item: it useful to remove an item from list portion.
Write short notes on immediate window.
Immediate window is a window that normally appears in bottom.
We can use immediate window to know value of variable
Print x
We can use immediate window to assign new value to variable when
program is in break mode
X=10
We can use immediate window to check syntax of a function
Print Len(rama)
Differentiate toolbar and menu bar.
Toolbar

Menu bar

Toolbar contains icons which starts


a command

Menu bar contain menu pads which


is made of text, normally menu bar
opens pull down menu. Pull down
menu may have item with icons
which may start other submenu or
command

Toolbar contains short cuts to start


some command

Menu bar doesnt contain short cut

Toolbar doesnt contain highlight


character

Menu bar contains highlight


characters

Page 74

Explain different types of data file in vb.


Binary:
It is to read or write data such as data of ole controls, image files, data field
in a table of data type blob(binary large object) etc. less commonly used to
read text data. It does not allow random access. Binary can make use of
input function. Type. end type statement is not useful.
Random:
Random files are used to read write text data in terms of fixed record length.
less commonly used to read/write binary data in terms of fixed length record.
It allows random access of data. Random can not make use of input function.
Type...end type statement is used to created user defined data type which
helps to create fixed record length.
Sequential:
Sequential does not use record of fixed length. Sequential is useful to read
text data in sequence. Sequential allows slow access of record. Sequential
file can use following statements which random file can not use: input,
input#, line input ,print #,write#
Random:
Random uses record of fixed length. Random can be used to read text and
binary data in terms of fixed record length. Random allows fast access of
record randomly. It can use get and put statement which can not be used by
sequential file.
Write short notes on Form Layout Window.
Form layout window is useful to set startup position of the form on screen
graphically. To use form layout window we must run our project at least
once then icon of the form appears in form layout window. Using mouse we
can adjust position of form icon within form layout window. Now if we run
the project the form will be in new position according to setting done within
form layout window.
Write short notes on Option button (Radio button)
Option button displays circle where user can click to put dot to select item.
We can have only one option button selected among set of option buttons.
Option button value property is true when dot is present in circle otherwise
false. It is compulsory to put option buttons in container control like frame
or picture box to create many sets. These controls are useful when we want
user to select any one out of more than one item.
Commonly use properties are as follows:

Page 75

Name: name properties are useful to identify one option button out of
several controls in code view.
2. Caption: this is the text that appears along with control.
3. Value: this property is true when option button is selected otherwise
its value is false.
4. style: this property changes the look and feel of the radio button
1.

What is purpose of Val function?


Val function extracts numeric value from string. If string starts with numeric
value it gives numeric value. If string starts with non-numeric value it gives
0.
Dim a#
a = Val("123.456")
Print a
print 123.456
a = Val("hello")
Print a
prints 0
a = Val("hello12")
Print a
prints 0
a = Val("hello 12")
Print a
prints 0
a = Val("12hello")
Print a
print 12
a = Val("12 34 .456hello")
Print a
prints 1234.456
Write short notes on Startup form
We can have many forms in our projects. When we run the project one of the
forms will be startup form. To change the startup form we can use project>properties->startup object and we can specify the startup form from the
combo box and we click on ok

Page 76

Write short notes on visual data manager


Visual data manager is a tool that ships along with VB. As its name employs
we can use it to manage database.
Following are operations we can do in visual data manager: (Add ins->
visual data manager)
1. creating new database
2. Opening existing database, redefining structure of table.
3. Creating tables, renaming tables, deleting tables, creating primary key,
unique key and defining fields.
4. Setting validation text, rule for fields.
5. compacting and repairing Microsoft access database
6. find and replace value in a field based on criteria
7. Data adding, editing and deleting in table.
8. Running sql query and saving the query.
Write short notes on data control.
VB provides a very useful control called data control that lets you access
data coming from a database. You can perform most data access operations
using data control without writing any code at all. The data control enables
you to move from record to record and to display and manipulate data from
the records coming from.
Following are the properties which are quite commonly used:
1. Database name: determines the path and filename of the database file.
2. Exclusive: if this property is set to true, then when you open the
database only you will have exclusive access to the database and others cant
access the database.
3. Options: determines access constraints for the tables you are working
on.
4. Read-only: when true, you can not update the database.
5. Record source: determines the source of the set of records retrieved by
the data control.
What are the type of recordsets available in DAO
Differentiate different types of recordset in DAO
There are 5 types of recordsets available in DAO but 3 are available in
design time.
1. Table-type: it represents the base table in a code form. It can be used
to add, change, or delete records from a single database table.

Page 77

Dynaset type: it represents the result of a query that can have


updatable records. It can be used to add, change, or delete records from one
table. Fields can come from one or more database tables.
3. Snapshot type: it is a static copy of a set of records that you can use to
find data or generate reports. It can contain fields from one or more database
tables. It is not updateable.
4. Forward only: this recordset is identical to a snapshot except that no
cursor is provided. You can only scroll forward through records.
5. Dynamic type: it represents a query result set from one or more base
table in which you can add, change, or delete records from a row-returning
query. Further the records added, deleted or edited by other users, in the base
tables also appear in your recordset.
2.

Write short notes on bound controls


A bound control is also called data-aware control is a control that can
provide access to a specific column or columns in a data source through a
data control. A data-aware control can be bound to a data control through its
data source and data field properties. When a data control move from one
row to the next, all bound controls connected to data control change to
display data from columns in the current row. If user changes in a bound
control and then move to a different row, the changes are automatically
saved in the data source.
For e.g.
Textbox, checkbox, label etc.
What is control Array? What is its utility?
A control array is group of controls that share same name and type. A control
array has at least one element and can grow up to 32767 elements. The
elements of the same control array may have their own property settings
The control arrays are useful for following things:
1. Control arrays use fewer resources than multiple controls of same
type.
2. Code can be shared among the elements of a control array.
Write short notes on activex control.
Or
.ocx
Activex controls which exist as separate files within .ocx file name
extension. An activex control is an interactive object that can reside on any
form that supports OCX( Ole controls) controls. An activex control is an

Page 78

extension to the visual basic toolbox. You can use activex controls just as
you would use any of the standard built-in controls such as a scrollbar.
Theses include controls that are available only in the profession and
enterprise editions. Many third-party activex controls are also available.
Adding activex controls to the toolbox
1. from the project menu, choose components
2. select the check box next to the name of the desired .ocx control, then
choose ok
To remove an activex control
1. Remove all instances of the control from the forms in your project.
Delete any references to the control in the projects code. If references to a
deleted control are left in your code, an error message will display when you
compile the application.
2. from the project menu, choose components. Clear the check box next
to the name of the .ocx control, and then choose ok.
Write short notes on Ole control.
The ole container control enables you to add insert able object to the forms
in visual basic project. With ole control we can:
1. Create a placeholder in our application for an insert able object. At run
time we can create the object that is displayed within the ole control or
change an object we placed within the ole container control at design time.
2. Create a linked object in application.
3. Bind the ole container control to a database using the data control.
Commonly used properties:
1. class: the property that returns the name of the application that
produced the object.
2. sourcedoc: the property that returns the data or a reference to the data.
3. sourceitem: the property that returns the image of the data. This
applies to linked objects only.
4. sizemode: the property controls how ole control is sized
5. oletypeallowed: this property determines whether source document is
embedded, linked or both
Commonly used method
1. create embed : useful to create embedded object.
2. create link: useful to create linked object.
What are the categories of controls?
There are three categories of controls in vb:
1. Intrinsic controls: these controls are contained inside the visual

Page 79

basic .exe file. Intrinsic controls are always included in the toolbox.
2. activex controls: it exists in separate files having .ocx extension.
3. Insert able objects: some objects such as Microsoft excel sheet, word
document can be added into toolbox and can be used like control.
Write short notes on Drawing Methods.
Following are the graphics methods:
1. cls : clears drawing area
2. line: using this method line can be drawn, even rectangle can be
created.
3. circle: using this method we can draw arc, circle, pie slice and ellipse
4. pset: it is used to draw a point
5. print: we can print some text on control
What is dll?
Dll stands for dynamic link library file. Dll file contains some functions and
subroutines written in any language that supports creation of dll files. More
than one application programs can call functions and subroutines in a dll file.
More than one copy of dll file is not needed if more than one application
programs are using same function or subroutine because dll file is used in
shared environment. So disk space is saved and memory space is also saved.
Write short notes on animation in vb
A common user for timer control is to create graphics animation, because the
way you create animation is by displaying successive frames of the
animation sequence at intervals. That is good job for the timer control.
To see how this works, we will create an example now. In this example, we
will just switch back and forth between two simple images, image1.bmp and
image2.bmp, which are simple strips of solid color, red and blue.
Step
1. start new standard exe project
2. place a picture box control and timer control
3. set interval property to 1000 for timer control and enabled property to
true
4. add following code to code view window
private sub timer1_timer()
static blnimage1 as Boolean
if blnimage1 then
picture1.picture=loadpicture(image1.bmp)
else

Page 80

picture1.picture=loadpicture(image2.bmp)
end if
blnimage1=not blnimage1
end sub
Write short notes on on error, resume statements in VB.
Vb provides many tools for debugging project
1. on error goto label/line no: when you execute an on error goto
label/line no statement in your code execution is transferred to the code
starting at label if a trappable error has occurred. The code following that
label is your error handler.
2. on error goto 0: if you want to turn off error trapping at some point in
your code, you can execute the statement on error goto 0 just before that
piece of code . then again you can give on error goto label statement for
error trapping after that piece of code.
3. on error resume next: on error resume next statement provides an easy
way to disregard errors, if you want to do so. Once you execute this
statement, execution continues with the next line of code if the current line
generates an error, and the error is disregarded.
4. resume: when you are writing code for an error handler, you can
return control to the main body of the procedure using the resume statement.
Program execution starts again with the line that caused the error, and this
can be very valuable if you are able to fix the error in the error handler.
5. resume label: when your are writing code for an error handler, you
can return control to a particular line in the main body of the procedure
using the resume label statement. To a label a line, you just place the labels
text directly into the code, followed by a colon.
6. resume next: this statement resumes program execution in the line
after the one that caused the error.
What are err object and error function?
Err: err is an object if we use err. Number then it gives error no. that
occurred in statement, if we use err. Description it gives short description of
the error occurred, if we use err. Raise we can raise an error intentionally.
Error: it is a function if we give error no. as argument to it, it gives us error
description.
Write short notes on debugging tools in vb.
Visual basic offers a powerful suite of debugging options-notable the ability
to single step through your code as it is executing. The standard way to

Page 81

debug is to place a breakpoint at a particular line in your code, and when


execution reaches that line, it will halt and visual basic will enter the debug
state, give you access to your code and variables. You can examine the
contents of those variables and work through your code line by line,
watching program execution behind the scenes.
To move through your program step-by-step you can select these stepping
options in the debug menu:
1. Step into-single step though the code, entering called procedures if
encountered.
2. Step over- single-step through the code, stepping over procedure calls.
3. Step out- step out of the current procedure.
Setting debugging breakpoints
Breakpoints are the foundation of vb debugging. When you set breakpoints
in a program and run that program, program execution continues until one of
the breakpoints is encountered and program execution stops, making vb
enter the debug state. You place a breakpoint in code by moving the text
insertion caret to that line and either selecting toggle breakpoint in the debug
menu or pressing f9.
Examining variable and expression: just select the expression and press
shift+f9 to evaluate variable and expression.
Adding debug watch windows: you can add a watch window to your
debugging session and display the values of selected variables or
expressions in that window continuously as you execute your program line
by line.
Immediate window: when debugging, you can use the immediate window to
examine expressions or variables immediately, just by typing them in.

Vous aimerez peut-être aussi