Professional Documents
Culture Documents
MillenniumYear®
Second Edition
Standard: MY07/11
Serial Key: 2007RVB6P1070705000107
Rohit Birla
1 MY®
Review VB6.0 Second Revised Edition
PREFACE:
VB is modified version of basic language. We have discuss here the basic visual basic version 6.0.
Questions and answers given here onemust try them on omputers. Try to beat microsoft simple projects
likenotepad, wordpad, word, excel and calculator etc… . reader must go with a basic VB book liike
mastering vb6 or peter norton to teach yourself VB or teach yourself VB in 21 days or black book and be
contineue with both book and these notes.
08 Oct,2009
Best of luck
CONTACT DETAILS:
rohitkumarbirla@gmail.com
Rohitbirla_rb@yahoo.com
Your suggestions are always invited.
Our projects in VB
# we assume, you are comfortable with ‘C’ and have gone through Review ‘C’atleast once.
2 MY®
Review VB6.0 Second Revised Edition
Intro:
Many programmers tends to dive in and start coding right off bat, but you get into habit of planning like
sit down with blank sheet of paper and sketch out what user interface you want.
VB window:
- Menu bar
- Tool bar
- Tool box
- Form window
- Code window
- Project window
- Properties window
- Form window
3 MY®
Review VB6.0 Second Revised Edition
VB window:
Variables:
Varibables are used for storing data. A varible has a name and a datatype.
The variable name is used to refer to value in variable and datatype determine the type of data the
variable cans store. A varibale is capable of storing
Declaring variables:
Vb provide us a facility to declare or not variable before complier use them., it’s a good practise
to declare varibales in advance for compiler (explicit declaration) so that compiler produce
efficient code.
Explicit declaration:
4 MY®
Review VB6.0 Second Revised Edition
Private: declare using dim statement and use only for single procedure and scope is local to that
procedure only.
Module: declare using private or dim, delcare at top of code window, use by all procedure in
that code window
Public: declare using public keyword, can be use by all forms and all procedures in all modules of
project or application.
Datatypes in VB:
5 MY®
Review VB6.0 Second Revised Edition
cbool boolean
cbyte byte
ccur curency
cdate date
cdbl double
val/cint integer
clng long
csng single
cstr string
cstr string
cvar variant
cverr Error
First vb program:
1. Drag and drop three text box on your form and then four command button as shown in figure
2. Select command1 and change its caption property ot ‘+’, same with command2 ‘-‘, command3
‘*’ and command 4 ‘/’.
3. Double click on command1 and in code window write,
Text3.text=cint(text1.text) + cint(Text2.text)
Follow same for command2, write – in between, for command3, write * and command4 for /
4. Press F5, then write a number in text1, second number in text2, press +, -, *, / , to see result
6 MY®
Review VB6.0 Second Revised Edition
If-else:
Msgbox:
Print statement:
7 MY®
Review VB6.0 Second Revised Edition
Structure of VB program:
Varible declaration
Subroutines or functions
Procedures
Built in datatype:
Try yourself
8 MY®
Review VB6.0 Second Revised Edition
Arrays:
Occupy continuous memory. Each element in array is referenced by same name and index value.
Dim <array name> (size) as type
Note: these array elements are referenced as a(1),a(2) etc… and a(20) means it will save 0 to 20
elements.
Write ‘option base 1’ between array declaration, and all arrays will start from 1 not with
zero.
Control arrays:
1. Copy textbox (which is on form) and paste on form. It will give a message, do you want to
create control array, say yes. Now both textbox have same name ‘text1’ but differ by their
index value 0 and 1 respectively.
2. Similarly try to create control array of label, command button etc…
3. Load statement are used to create run time control arrays
a. Load text1(k)
b. Unload text1(k)
9 MY®
Review VB6.0 Second Revised Edition
Arithmetic operators:
^ exponential
+ add
- minus
* multiply
/ division
\ integer division
mod reminder
Boolean operators:
Concatenation operator:
Dim s as string
S=”hello”
S=s & “!” & “how are you”
Print s
S = s & “a=” & a & “b=” & b
Print s
10 MY®
Review VB6.0 Second Revised Edition
Try to solve:
Looping:
11 MY®
Review VB6.0 Second Revised Edition
a control array have at least one control element and can grow up to 32767 elements
each control must be of same type
each control have same property (name)
each control is identified by unique index value
we can remove only those controls which are added at run time
we usually make control arrays differ by top and left properties
12 MY®
Review VB6.0 Second Revised Edition
Events:
An event is user action directed at application like clicking with mouse. VB has given subroutines
or events handlers for handling events. The combination of control name and events name is unique.
There are many types of events like of mouse - click, dbclick, mouse down, mouse up etc…
Properties of form: backcolor, borderstyle,caption, forecolor, control box, name, window state
Scale modes: have you noticed that scalex, scaley, scale width, scale height. Change these properties
and check difference.
With statements:
With text1
.name=”text”
.caption=”hello”
.forecolor=vbred
End with
13 MY®
Review VB6.0 Second Revised Edition
Printer object:
printer.print “hello”
printer.print str
printer.print text1.text
printer.fontname=”Tahoma”
printer.fontsize=16
printer.font bold=true
printer.new page
printer.enddoc
printer.line(x1,y1)-(x2,y2),color
printer.circle(x,y),r,color
check other properties like fill color, fill mode, draw mode, draw width, draw style, scale mode
etc.
printer1.paint picture picture1.picture,x1,y1,width,height,x2,y2
printer.copies
printer.orientation=vbporlandscapre
a=printer.page
printer.port
printer.zoom
Colors:
[hint: goto project menu, click components, select Microsoft common dialog control, click ok.
cd1.showcolor
Cd1.showopen
cd1.filename
cd1.showprint
cd1.showsave
cd1.color etc… try these out]
14 MY®
Review VB6.0 Second Revised Edition
MAPI:
Mail application programming interface, you can send-receive email via your vb application, but
it is not quite easy as it seems this control is related to outlook express and it is not quite handy if you
didn’t configure your setting in outlook express or so… it is basically a universal provider for shelring bits
of functionality in email applications such as outlook and outlok express etc…MAPI has been drastically
deemphasized in windows due to the outbreak of self spreading worms (email viruses). A modern easy
to use MAPI is CO.
MAPI is a system built into Microsoft windows that enables different email applications to work
together to distribute mail. as long both applications are MAPI enables, they can share mail message
with each other.
Q: creating menus [hint: click on menu tool box from tool bar,
15 MY®
Review VB6.0 Second Revised Edition
Error handling:
16 MY®
Review VB6.0 Second Revised Edition
API examples:
17 MY®
Review VB6.0 Second Revised Edition
File handling:
18 MY®
Review VB6.0 Second Revised Edition
It is mechanism used by DBMS for sharing of data. Atomicity, consistency and isolation are
achieved through currency control and locking. The amount of data that can be locked with single
instance or group of instance defines granularity of lock.
SDI vs MDI:
SDI have single data window ex: wordpad, notepad. You can open one document at a time. Single
document interface. Multiple document interface. One parent form and that form contain other forms
and control them known as child form ex: word
Features of MDI:
19 MY®
Review VB6.0 Second Revised Edition
Send keys:
Is a module for windows which can be used to send one or more keystrokes or their combination to
active window.
+ shift
^ ctrl
% alt
ctrl a given as ^a
shift abc is given as +{ABC}
{BACKSPACE}
{BREAK}
{CAP}
{DOWN}
{DEL}
{up}
{LEFT}
{RIGHT}
{HOME}
{END}
{HOME}
{LWIN}
{RWIN}
{ADD}
{MULTIPLY}
{DIVIDE}
{SCROLLLOCK}
{PRTSC}
{NUMLOCK}
{PAGEUP}
{PAGEDOWN}
{INSERT}
{ESC}
{F1}…{F24}
{TAB}
20 MY®
Review VB6.0 Second Revised Edition
Ans:
import sendkeys
Sendkeys.sendkeys { “””
{LWIN}
{PAUSE .25}
R
NOTEPAD.EXE {ENTER}
{PAUSE 1}
HELLO
{PAUSE 2}
%{F4}
N
“””}
21 MY®
Review VB6.0 Second Revised Edition
22 MY®