Académique Documents
Professionnel Documents
Culture Documents
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
Page 3
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.
Page 5
Page 6
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
0 , 255
2.Integer %
32767 , 0 , -32768
3. Single!
4.Double #
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
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
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.
Page 15
Multiple if
Page 16
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
Page 20
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
Page 23
Page 24
Page 25
Page 26
Page 27
Page 28
Page 29
Page 30
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
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
Page 35
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
Page 38
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
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
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
Page 45
Combo box
Combo box contains list of items
and user can select any one item
from list
Option button
Page 46
Sequential is useful to read text data Random can be used to read text
Page 47
in sequence.
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
Page 50
Page 51
Page 52
Page 53
Page 54
Page 55
0 , 255
2.Integer %
32767 , 0 , -32768
3. Single !
4.Double #
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
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
Page 58
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
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
Page 62
Page 63
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
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
Page 66
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
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
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
Page 69
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
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
Page 73
Menu bar
Page 74
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.
Page 76
Page 77
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