Professional Documents
Culture Documents
~ 1998
. 21
- 189 03
. : (01) 46.63.419, 094-410.042
Fa : (01) 46.65.356
E-mail: poseidon@compulink.gr
Web: http://www.poseidon.gr/press
Q-ARTS . & . .
:
8 & 26
. : 92.41.571 -2
Fa: 92.31 .293
ISBN: 960-861-230-6
, ,
, , ; .
~o , - t
1.
,
.
,
.
,
. , -
. ,
.
Eo,ywrn -.uu
K~Wo 1
n n _
_
Textbox control _
Command button control _
_
_
_
(templaIes) _
- _
calculator _
_
_
K~o 2
( Project5 _
_
, project _
, _
Custom Controls _
project _
compilation _
_
_
_
_
_
_
(camparisan)
--
_
- - - - - - - - - - -- - -
--J
_
_
(Structures) ..,- _
Enums _
_
- (Object Variables) _
_
_
_
"" _
_
main _
U Visual Basic _
_
_
_
_
DoEvents _
_
11... Then _
Select Case _
_
(Melhods) _
_
(Debugging) _
Asserts _
_
_
_
Meru _
Menu Editor ~--:---,--- ------------------
Menu Conlrol _
Submenus _
,---- _
_
- menus _
_
_
--
K~o5
~o6
[a _
_
_
Pset _
line _
_
C rcle --.;
a i nt ctu re -
lilll
l -
DrawWidth ---iMill
DrawStyle ---1l1iii
FillColor FiIIStyle -------------------lIiiii
DrawMode ---iMilliil
-------------llil
---iiw
-----------------------li
oo
il
...........
a 110 ~
(mouse events) ~
8tt R'I
Shift ~
Drag and Drop
D
Drag and Drop
~
nT'I
n.
--
ll
K~o 8
) nJvv -1IiI
-IIIili
-----'...."""
l1 coTItroI5 ...
cantrals
Frame
Labe . '-.
nbutton ~
Chec kBox R
List ~
Com bo ~
Scro11 Bars n
Rle - System Controls
ore List
Directory List ;
""
~
"'
Fle ist ~
Time '
Imag e IIJ'
PictureBox ~
Shape rr.n
Line
Data - L
Custam cantrals rr.n
"'
~
--
lll - -- - - - - - - - - -
I'r.'!"t
-
Animation ~
K&tPlvo 10
-------------1111ii1
clipboard -I
DDE _
D --------------------------IilliI
_
_
K~o l1
Datl C;oTItro l _
_
Data Contral -Iilill
data control _
RecordSource _
Recordset --I
data control, _
data control --Ii
Transactions - - -- - - - - - - - - - - - - - - - - - - --1
Bound controls _
Data Bound Grid control
Eo
1
---Ii
L:
O ~iIIiII
-----,----------------Iiil..
_
-,-------,------------------IiIiiiI
(Indexes) ---ii
DD - - -- - - - - - - - - - - - -- -- -- 11
Visual Basic 5.0 ------------Iii
D ---------------Ii
-iilii
--
index '
- -- - - - - - - - - - - -
(relations) (Referential lntegrity) _
--------------
D D _
SQL _
l (Aggregate Functions) - -- - - - - - - -- w
_
D _
DEETE -ii ...
_
- - - - - - - -- - - - W
- _
_
K~o 13
K_-,---- -iilil
l (objecl) _
l _
_
l _
--------------------IWI
_
OI Kl -liII~
----------------------lilil~
Automalion Servers -------- ------- ------ililil
w rd -5Ii
. -------------------lilliI
Eol -liiI1IiI
---"''-&8'''0
Ac;ttveX coJjtrol5 _
AcliveX controI -------------------liiI...
ActiveX Interface controI Ward -;i
l Internet
--
controls
..o...,.,,..
OCX control, _
AcliveX control ' ----------;,;;
" " AcliveX control, -liI
K~o 15
nwj l t er et --
TCP/IP -IOIIIiJ
Server --------------------Cii
Server -I1IOIi
UDP --------------------IlIOIill
Microsofl lnternet Transfer Control --------------~~1I
--------------- ------11i1..
SECURE ---- ----------- -fIill
FTP - - - - -- - - - - - - -- - - - - --c
, --'=:.
K~o 16
Help -----------------Ii
_
help ------------------
help Visual Basic _
K, --'=c.
Crystul Reports _
formula fields _
--
Crystal Reports Visual Basic ELL::
- -- - - - - - ------
~ _ _. _
__
IJII
--------------Im
Kefo 1.8
--
X ll
A ctVe){ DocurneJIts
Visual Basic 5.0
L. AcliveX
Document. UserDocumenl,
, , , '
OCX conlrol, AcliveX
Object Browser
Objecl Browser. TOl1lbar,
Code Window ,
. Object Browser
Visual Basic, ' ,
,
coJItrols
controls 5.0 , MSChart, MSFlexGrid, UpDown, Winsock
Internet Transler control.
.
:
l Typed Oplional
C+ + Visual Basic.
:
Asserts
Debug
(executable) .
.
Enums
AcliveX controls, ' .
Property OplionaI
, Properly Lel Property 6el,
(Optional argumenls).
, ActlveX conlrol,
Evenl, , RaiseEvent.
--
AddressOI
, (pointer)
" " . u Addre ssOf,
Professional
Visual Basic. ,
, , Hints &
, . ,
, - , .
,
Vi sual Basic 5.0. e-mail
.
r
E-mail: vbtrain@poseidon.gr
http://www.poseidon.gr/vbonline
1997
- - - -- - - - - - - -- --
--
Visual Basic 5.0, m project controls,
text boxcontrol commandbutton control.
, controls, .
, , ' button textbox,
Windows m ,
.
M ax im jZ ~B o x
SyntmMen.Bcx C apt.ion
( Clo~
Mi:i miz eBox
MeDJB",.
~~!IIIIIII""
EIle fd ~ ~e arch t!elp
_ _~
V etic ~ Scfol1 Bar
~ ClientAfe~
. 1 .1 . Wndows 95.
--
, . OCX, Visual Basic, -
1
controls. , control ,
, (fonts) .. , .
control button. ,
, "" , ,
, . button, ,
xr 1.2.
: Fo rm1 I!lIiJD
Object: j Coua<nd1
~1~ e Sub Command l C!1ck( )
-
End Sub
. control
, (events).
. , Visual BasIc,
( , controls . .) ; .
Windows events ( ) ,
.
. () , () .
, (project) ( .frm)
controls , , .bas (modules),
. frm
controls . , ,
, , .cls,
. ,
. ,
, :
.
controls (buttons, text boxes ..) .
@) events controls .
--
Toolbars .
2
t) ,,"~'tI-~.V-~ .o<> l_~,",, ~ _toiI> .&Wl!J
.; - ~ . " ~g P<tI .., r . ':!.~_~:'5~
, ~ . ~ /;i. (j . ;j. $ 8
.1
. '
-
.:J
. 1.3. i su al Basic5.0 .
, . ,
. ' cl . '
, ' cap~on (back-
ground). " Propertes Windows" Toolbar Visual Basic, "F4",
1#1.:.11
!Form l Form -.
:] '
-- ,." ""
,. .,
...........
Nme ) F om l
,
~i!.Z
~
. Siz
F_ I
,~
...
,~
I3CoyPtro
,
"""
...........
,~
'n.e.... ""
- ..-.sprett
" onoor....,
"'
. &--t(OIOO ~
X:bon
Rensjsets thetM: dspI.ayed rI n clectS.ttIe b.:
. 1.4. .
, '
' . 1.4.,
.
(design ~me),
(run ~me) .
-- 3
,
:
BackColor . , -
.
ClipControIs True, /
.
S!artUpPos"ion
.
Tag .
--
control , , -
.
, (dragging) .
, , ,
.
~ ~A
I'b "~J
r. " !J
lm :!!! .~
ll 'O
~i--"
1OiJ ~ 'i!
Textbox coJjtrof
. . ". "." .. .
.. :I;~' .
1.6., control , 8
, ' , , '
.
--
text box control,
5
. .
:
Locked textbox.
MaxLength control .
MultiLine True - False control .
PasswordChar ~
. , .
ScrollBars m , -
ovo , - , 1 - H oZontal , 2 - Ve~ical , 3 - Both, -
, , , , .
SelLength .
SefT eX .
ForeColor control.
Height Jo control. controI.
H e lpCo nle XI D , , u (Help) ,
F1 topic. u
.
Index m controls
, . contrOI
( control)
32767 .
-- 6
Le" control /
.
IConw>d ~ ::=::J
"......" ",,
~ ICateQOflled
t~=~=::~~~ ,.",
""""""'.
,
,""""""
Hffl
->
->
- >
......
,
~~-'~,'"
~
~
MS Sns Setl
--
. 1.7. command bunon control .
7
,
, (events)
cantrals ( , ) . ,
. cantrals, text
box cammand buttan cantrals. , : text box,
caption command button
, b tton caption .
controls
. 1.8. .
_ lal,
~ : ' : ::.
"""""'" :::: ..
. 1.8. controls .
, textboxcontrol.
( control), editor,
'
CodeWindow. 1.9., editor .
(Object) controI ( Name), (Proc)
o ~ control, .
1~1
Pr l v a l;e 3
J
T"xl;l_ Ch.. n",,, O
1-- .
J
~
3
~
-
,.~
~
..- '.
;&
--
. 1.9. Code Window text box control events.
8
, editor (
' ) , :
, Index Index
control. ' controls event.
Object, control '
' events ( 1.10).
.m
,
-: !
~~ ~I
. 1.10. conlrols, .
events controls. ,
. Clck DblClick
control, . event GotFocus control
( ) , , , LostFocus
( ' ) . events
Change.
controls , .
Form Object, Proc even-
ts ( ) . . event
Laad , . :
Pri v ate Sub F o r...Lo ad ()
End Su b
-
~ - - - - -- - - -- - - - -
Unload . ' :
Cancel , ,
Windows event QueryUnIoad.
.
Click / .
DblClick .
MouseDown, . .
MouseMove,
MouseUp
KeyDown, . .
KeyPress,
KeyUp
Resize .
Paint .
, Change lext
button conlrol :
Privat e Sub Text L-Change ()
commandl .Caption = t ext l . Text
End Sub
controIs
, .
(read only),
(read - write) . Caplion command button Tex1 text box
control ' . , ,
:
FormName!ControlName.P r o pe rty
events , FonnName,
:
conlrol, :
. ,
, , caption button
lext box contraI.
,
, Click button Command2:
--
10
Pr iva t e Sub Command2_C l i c k ()
command l .Caption = command2 .Capt ion
End Sub
Caption button command1 button
command2, " " .
" " , "F5"
Start Run Visual Basic. ,
, 1.1 1.
Fo rml I!!I~EJ
. 1.11. , .
,
, " " Visual Basic.
designtime
, 1.1 2 . View Code
codeeditor controls ,
Editor ,
.
i; F onl1 I!!I~EI
: . -
. 1.12. .
--
. Paste
11
clipboard, , , Properties .
. 1.13. .
, , Open Prajecl...
File vbp. , New Project
project . , mod-
u1es ( )
' Project Explorer ( 1.14.).
View Form , View Code
,
events controls .
, ( module ) ,
( Name). ,
, , modules .
!
Ei ! fl -
8 ~ Ssmd (5smd3Z.b)
, ""'"
&<S
'- ~ AIcwOtjrs(AIoYoot:.fr)
;- ~ 8cm=orm (lrsr.-.,. Frm)
j- -t1 CoIor1'm (CoIofs.FRM)
,, ;- t1 find:>lo (~. frm)
- ~ IM.F. " ;j
tl ShowOtQns ($howOpt,frm)
f __t'1""\ :: etdform (VTIChiId.frm)
""""'"
"--.::.ssr-cH(S5HJl.6A5)
--
. 1.14. ProjecI Explorer .
12
frm vbp,
. File Make ...
1.15. .
..- ?
FIe Qme:
1-
Ir ~
-..-
~
. 1.15. .
, (Application Ti~e)
(Icon) , , ,
Intel p-code.
OptIons... . ( 1.16)
Make Compile. p-code
(Compile to P-Code) Intel (Compile Native Code) .
(optimizations) in .
--
utMMi!t@' ;M'.!
~I~ I
Yer sionlnber
~IO<'
.
., ., ,"";11,
- ItIe': 1,I,0000
.. -
IF;nI
/>4OInernen:
k
D.
Yt<SIOfI l'it:rl'MtiOtl
?', :!:......:
It,;.;,_..... )J :J
.:J
~I$IeArneds'
ConJIj:/I~~,1
--
c::::::J'~ ~
. 1.16. .
Visual Basic
Intel (native) p-code.
. .
--
native .
13
5.0. d,
Visual Basic .
' : run time Msvbvm50.dll,
( ) .
native ; (optimizations)
. VC++.
Pentium Pro .
(debug symbols) .
LL debugger, Developer Studio
VC ++. (multithreaded)
( 5.0),
threads Visual Basic.
( ) , Msvbvm50.dll,
, , custom controls
OCX, , ,
System Windows, reg-
Istration, . , Setup Wizard,
DLLs OCXS.
'
'-'4 ;
NZ=:I ~I
- . ::: #.
.;;:.
\lBDat ~F<r",
Wizard
.
.oJ>out Oi<>Iov
::: :::
L09 In ~ Oti<n. DiaIog
"'
? !
:::
s,s! So:r~
... ~
:::
" n.
'"'-
:::
".'"
:::
ODBCLo ln
.-
:::
..::
Di:J
""'"
[~
I r:oon~ mowt~ <lo ir he ly1ure
.1.17 . .
-
.-
1-4 - -- - - - - - - - - - - - -
-
calcuJatol
boxes controls command button.
commandbutton, 30 box control boxes controls.
Visual Basic , boxes controls
commandbutton control. control Text3, Locked nu ,
. .
CodeEditor Load , :
Load . , ,
(caption) . ,
command button control, :
Private Sub Commandl-C lick()
, tXEl n
Exit Sub
End I f
\ Q
,
. Val,
. ,
. 1I - End 11
, . ,
. F5, 1.17.
1=
""
. 1.18. .
--
15
,
File Save Project As... ,
, , exam1.Vbp.
1.
Visua/ Basic; m.
Basic DOS -
2. project r Visua/Basic;
3. ;
6. ; r.
9. (events); r , ra
text box controt command button control.
10. OCXcontro/s;
1. tet boxes
controls command button control. . focus tet boxes
controls, . , command
button, ' caption tet box control.
--
16 - - - - - - - - - - - -- - -
Projects
project.
[
,
projects.
:
(.FRM).
, controls (properties)
(binary) , (.FRX).
(.CLS).
module (.BAS).
custom controls (.OCX) .
resource (.RES).
project (.VBP) .
project ,
,
. , Project Explorer
project, custom controls.
project,
in-process DLLs ActiveX controls.
, Project Explorer projects '
Project Group, .vBG.
Visual Basic:
form Modu/e5
.FRM , ASCII, ( )
controls , (form-Ievel)
, , , (events)
--
.
17
crfA~~ IJ o d u I e~
class madules, ,CLS, madules ,
(user-Inter1ace).
, ( Visual Basic).
StfAdfArd Iodule~
standard madules, .BAS, (public) (fa m - level)
,
.
Re~ource~
Resources, .RES, ASCII
, bitmaps, . . , ,
, resource
, .
resource, , , , resource
ed~ar campiler, AppStudio m Microsoft Visual C+ + .
StflJldflrd COJltroI ~
Standard Cantrals Visual Basic
Toolbox, L ActIveX custom controls, Inselable Objects,
Taalbax, . Standard Controls
textbox c m man d button cantrols . .
, n ~ project
File, ,
project Projecl Group.
praject, New Praject. praject,
--
-
18
2.1., project . default
Standard .
~
@@,
908
ActiYeX EXf
17
A;tieX/
-
17
C""'.
'"
1"~ck' l
"..
:~"
"',,'"
~
Ac.tiveX
~
s Ak4ton Enterprse
"'"""
cor trols
~
- ~
Act~
-""
'- ... -
. 2.1.
-
.
ActiveX , L
Automation Serer , . ActiveX DLL
in-process L Automation Serer , ActiveX control
ActiveX controls. Application Wizard wizard "
" , , ,
Web. ActiveX Document DLL ActiveX Document in-process ActiveX L
Automation Sere rs " " Intemet Expiorer, Addin
template add-in Visual Basic. ,
Enterprise Edition Controls EnterprIse Q controls
. project, project,
, Open Project project,
project. Project Explorer , modules
project, Toolbox custom controls.
Add Project project.
in-process DLLs ActiveX controls.
project group, projects.
project, Save Project Save Project As
project form, standard class modules
project. projects, Save
Project Group Save Project Group As, projects
project group.
roo~Jj , n~JjJ)
Proje ct,
, Form, module, class module, User control . . ,
--
, ' '
19
. , Remove ... ,
Save ... Save ... As File.
projects project
(references) . .
drag-and-drop
Explorer Windows, File Manager Netword Neighborhood Project Explorer
. .OCX, " " Toolbox.
ComponenIs
D MosoftComecn~ S. O (SPZ)
OMicrosoft ~ Bod Gd Control
O Mi:rosoft Dt" BOt.Ind List ConI:rols 5.0 (SP2) ! j
D Microsoft FeGd Cootrol5.0 (SP2)
D Miosoft Forms2.0 Object bI'fY
MiosoI' GrldControl
.
[] l'Icrost Intemet:COftrols
O lo'crosoft Intemet Transfer CortroI 5.0 (51)2)
~
.:.:J
..
Mosdt Cnor DaIoJ (000015.0 (SP2)~~",,"~~~~~'i1
~0Y>'Se .
I.obon: C:\WII'OOWS'\SYSTEM\CCMX.G32.00:
, ,
check box Toolbox. control
,
l1n pro)ect
Project, Project Properties,
--
project project, ' project .
20
ProJ<<;t !i=:
IProe<t!
!j$fl>""""
" o ;.: DesVO" "
. 2.3. project.
General ,
.
ProjectName project .
(.) .
Help File Help project.
HelpContextlO context 10 topic Help, -
F1 , (object library) project
Object Browser.
Project Description project, Object Browser.
project Make,
Compile p-code native code. ,
Component standalone
ActiveX S ere r (ActiveX Component).
#Else
--
#EndIf
21
, compilation Personal True,
, .
compilation.
Make Project Propert es , Conditional
CompiIatIon Arguments Personal = 1, .
, :
, compilation declaration
module,
'Const Greek = True
Project Properties
declaration
module. , ,
' modules , ,
module.
1.
;
projec/ S/andard.
2. projec/ .
. projec/s ;
3. modu/e. ;
4. cus/om con/ro/ .
.
projects,
module.
--
22
OuickBasic OOS,
Basic. -
, , OOS.
V sua l Basic (procedures) (functions),
OuickBasic.
(Oecision Stn ctres) ,
, modules
. .
.
, ReOim Preser e,
. .
- .~p
.
. ,
:
"" +
, .
,
. ,
,
. :
(string). , .
. , :
--
23
- 20
2 bytes . ,
, -32,768 32,767, 2 bytes.
-2,147,483,648 2,147,483,647,
4 bytes. ,
,
.
$, , .
:
$ = "Visual Basic"
,
( . . , , Tabl .. )
() . [ [:
.
@ ( . . + + ) ,
- +
, ..:
* ( - ) 1 1 * -
@) ,
. , ;
: ( + 1) * (C-6) : ( + 1) (C -6)
:
+ * / C - 55
10 * + Si n ( X) + 3 . 4 * Co s ( 3 . 14 * )
D~J)v Dwv
:
Mod
MyNumber = 2 + 2 4.
--
24
MyNumber = 4 257.04 + 98112 E ~ ~ 102369. 04 .
MyVa lue 2 2 .. 4.
MyVa l ue = 3 3 3 ~ 19 683 .
My Va l ue = ( - 5) 3 ~ 125.
My Re s u l t 10 Mod 5 . .
MyRes u lt 1 0 Mod 3 1.
MyResult 12 Mo d 4. 3 . .
1
.
2 / , .
3 +- .
4 +- , .
~ onoia i
. , , = +*C/+-F 2
i :
1. = FA 2
2. = B*C
3. = /
4. = +
5. = +
6. = -
, , , . .
--
. 3.1. Cray-1 100 .
25
Visual Basic D READ Basic.
(concatenaUan). u ; & +. , , :
$ = "Vis ua l"
$ = "Ba s i c "
C$ - $ . & $
C$ Visual Basic.
+ ,
.
, .:
(:) .
(crnur)
C , .
;
' C :
- ...
<> ...
< ...
> ...
<= ...
> ~ ...
;
, : (True)
(False), -1 . ,
, = 1 = 4, :
= False <> ru e
--
. Visual Basic Basic
26 - -- - - -- - - - - - - -
ASCII.
(
32) .
, ,
, , .. "ABCZ" " ABXl"
.
, , .. ,
"ABC ">HABC"
True, .
, MySesult
:
Va r l = "5 ": Va r2 = 4
MyResu l t = (Var l > Va r 2 ) \ n l. l. Tru e .
, ,
(LogicaI) ,
, And, Or Nor. .
And :
True, True.
False, False.
:
~ 1 0: ~ : C - 6
My Che ck A >BAndB > C True .
MyChe c k B > A And B > C . Fa lse.
MyCheck nd : ]. 8 (b i twi s e : ) .
Or :
True, True.
:
-
MyChe ck
10: =
:
>
C
Or
-
6
> C : : Tr ue.
MyCheck > Or > C l. : Tru e.
MyCheck Or 1 0 : 1 0 (b i t wi s e .}.
, :
--
27
, True, False .
:
~ 10 : ~ 8: C = 6
MyChec k No t (A > ) E ~ 1 False.
MyCheck Not(B > ) 10 True.
MyCheck Not 0 - 1 1 (b i t wi s e 0).
bitwise bits .
' 1 (bit).
v aJjv
.
:
Variant, default
Visual Basic. (Integer, Long, Single . .)
, (date,ltime) .
Variant ,
. , Deftype ( De!lnt
-) , Variant, Dim
, 1.0 Visual Basic default
Single. :
Variant ,
--
VarType, :
28
vbEmpty Empty
vbNull 1 l l
vblnteger 2 Integer
vbLong 3 Longinteger
vbSingle 4 Single
vbOouble S Oouble
vbCurrency 6 Currency
vbO,te 7 O,te
vbString 8 StrIng
vbObject 9 L Autom,tionobject
vbErro 10
vbBoolean 11 Boolean
vbVariant 12 Variant ( u Variants)
vbO,t,Object 13 Non-OLEAutomation object
vbByte 17 Byte
vbArray 8192 Arr,y
Ex i t Sub
End If
rf IsReal(Num) Then
MsgBox " (real nurnber). " Else
Ms g Bo x " 6
--
29
- - -- - - --
( real number) ."
- - -- ---
End If
End Sub
End If
End Func t i o n
11 End 11, . .
, :
Dim S As String
(variable-Iength string)
(f ie d -Ie ngth string):
Dim S As String * S i z e
size ; ( ) . strIng
, string , :
st rY ''10 2 . 4 4 ''
intX = strY
.
. Basic (
, C Pascal), default .
deciaratian ( . 2.3.) module :
Opt ion Ex p l i c i t
module Dim.
:
Deflnt -
-- 30
declaration, Integer .
8asic,
; .
. ' !,.,. _! l
I j General)
J ! (DeClar8t iOl1S)
J
Optio lJ Expl i c i t
Pr i v a t e 3 ub Fo r m_ Load ()
..
End 5 Ub
-;
3 I ..1..:J ~
. 3.2. Declaration .
Dim ( StatIc)
(Iocal) ' . ,
Dim Declaration
module, module.
(global) ,
. Declaration module (
) , Public Global, .
Declaration lorm module,
Public. , :
Public ID As I n t e g e r
Declaration Form1 ,
:
Form l. ID
Private Dim,
Module .
class modules Public
.
3.3,
module CITelnet.Frm, module.
, 3.4. Public
modules . , module Modem. 8as
Const. '
.
& , WM_USER .
.
Dim StatIc
, .
, Static
, :
--
31
' .1, ,,:., _ l '
11~ I) J Ine-,,-I J
l1 c
::J
,.
~
-.: a e 1D01:I,s.xlte !.3 Cb ) ee >:. ."", P['QCo"",,Co nB :o l
( :
riva.e ",iReceiveColor U n eQ er
J
P ub l tc ( = lPP NAm .. "G a 1 . D e 1 u e"
P ubl1 c (= lI'R_Us ER - ' 11'100
Putll l C ( Il5 TJU.NS_CNC L
Putll l C ( 5 TJUNS _R ENJ.llE
Putll1c ( = TRllIS OVlRVR I Tt
: Co = t 111<1<1e; Con fe re nce . ...... !a _",,,age,,, "
Putl l I C Co=t Gal a !Iir:er "'io n '" ~Gala i1J!!:-Ver 5 1 0 n : 1 .0"
: Co = 1;., COnt en>:._Type " c on>:. e n >:. - Tvpe :"
P ubl lC Co ns1;., C OD t.eDt_Sl~ e "Cn>:.en -S 1::e: "
PI.IbH c Co nst 1'1...",,,, I d - " fIe ",,,,a oe - ID : "
-
Pub lIC EIb I! 5 Lono Enable_Co nf... ...nc... 5 Inte oe r
,. :~7 '~. ~ r-~.? ~n_e :;.~I:'~A:""-"~.~.,,,,~.,,n~ ~
. 3.4. GlobaI .
Visual Basic .
, Currency, CCur:
Pa y Pe r Wee k = Cc ur ( hou r s * h ourlyPay)
(con-
version function):
--
(array) . ;
32
Visual Basic Basic.
, Dim Redim.
, .
. :
41 . 11
16. :
() 256
(l) = 324
(2 ) = 100
(40) = 55
.
1 ( ), :
, Declaration, :
, Dim,
Declaration module. ; , '
.
module Dim
, Declaration, :
, :
( ) ,
Redim Static Dim . , Public Global Dim
Declaration,
j modules , :
, :
Public MyArray( ) As I nt e g e r
.
( )
.
,
. EuX , Viusal Basic Preserve,
--
Redim. ' ( ) , -
33 - - - - - - - - - -- - - - -
.
' ' .
,
, :
UBound , LBound
. , Erase (
) .
(Long Integer) , - 2 3 2 232 -1 .
Array,
. Variant
. :
Option Base 1
Array
Data Basic DOS.
j (Structures)
Visual Basic
,
( ) .
Type . Declaration
module. , Private. ,
.
, Declaration module:
Type Sy stemI nfo
CPU As Variant
Me mory As Long
Di skD r i v e s ( 3 0) As St ring
Cost As Cur rency
End Ty pe
Systemlnfo . :
Systemlnfo.
, , :
--
34
AllSystem(2) .CPU - ' 3 8 6SX'
AllSy s tem(2) .OiskDr i ve s(1 0) " 1.44 MB If
.
( DiskDrives ) . . m
Declaration Standard modl e, ,
Private Public, modle
. ' Form Class modl e , .
, Systemlnfo ' Standard
module :
End Typ e
ET1um5
Visual Basic 5.0 enum,
' . :
1 Sunday, 2 ( ) Monday . .
, :
Di m Week as DaysOfTheWeek
ArrivalDate = Mon day
! ArrivalDate < M on day Then
){nj nv
(collections) ,
,
. ,
ReDim.
, .
:
Pub lic co lURLHist ory As New Collection
Add ' :
co l URLHi s to r y . Add URLAddress
-- 35
oi] :
13.
F
Form1 .
Form1, :
,
, Form1 .
New Dim. , :
. Show
F.Show
(instances) Fomn1 ,
. , :
' control :
Dim a ny Co nt r o l As Cont r o l
control , ! bo:
, , controls. .
--
. , Form1:
36
Ca l l Sh owForm (F orml)
text
box control. :
Visual Baslc 5.0 (
) .
NoKeyPress.
Declaration NoKeys:
Pub l ic Ev e nt NOKeyPresses ( Key$ )
KeyPress :
" , RaiseEvent .
NoKeys, Dim, , W1hEvents :
Pub l i c WithEv e nts Foo As NoKeys
Set Fo o : Ne w NoKe y s
Fo o .Show
, :
Priva t e Su b Foo-NoKeyPress e s ( Ke y$ )
MsgBo x ~ 1 \n & Ke y$
End Sub
>
--
m , modules ( bas), ( CLS ) , ,
37
OCX .
events controls .
(private) , module.
public, .
modules. ( )
(
public, default standard modules).
,
, ,
Sub, Function ( ) Properly.
.
Sub , , Property
(custom) .
Sub (procedure) .
End Sub
Sub Pa r s e Pa t h (file $, d %)
End Sub
ate , , fomn
standard module , Public ,
. , Slatic
, .
(default) Private, ' standard
module Public. .
(arguments) ,
. .
:
--
Pa rsePat h "Derno " , va l ue %
38 - - - - - - - - - - - - - - -
m SomeSub Public ' module
Form1, , :
Windows
(even's), ,
, .
, (resources)
. Visual 8asic
Windows.
( , )
:
End Sub
, Form
eventname , :
Form1 .
.
, controls ,
' button text box con'rol. :
Private Sub Co ntrolname-eventname ( a rgurnents)
End Sub
, . Visual
8asic Sqr, Chr . . ,
--
. :
39 - - - - - - - - - - - - - --
[ Pr i v ateI Public] [Static] Function f unctionnarne ( argli s t } [As t yp e ]
End Function
Exist = re t %
End Funct i on
:
(property procedures)
read-only ,
standard modules .
, module . Visual Basic
' , :
Property Let .
PropertyGet .
Property5e! ' .
,
Inverted . Public
module :
V = Fo rml . Inverted
Private,
,
module. . Private
Islnverted re LeI :
--
Pr ivate IsInverted As Boolean
40
Property Let Inverted ( As Boolean )
IsInverted = !
IsInverted Then
El s e
End !
End Property
, j ' uj :
j .
Property Get.
Pr operty Get Inverted ( ) As Boolean
In verted = I sInverted
End Property
oj:
End Property
End Property
Property Get :
End Property
Demo ( a, b, c ) = d
--
"1
Property Le t Demo (w, , , )
End Property
, praject PROP_IND.VBP.
Property Let Property Get,
. , text box
j , , command b tton, label control
lndex . Label controI .
. lndex textbox
command button, label .
Declare ,
, intlndex, .
Load , ,
.
button.
Labe13.Caption = i nt l n de x
t xtNewValue.Text
End Sub
" .
,_ .. -
1rJe" vv6c.o V 2
) IrcIe. 12__
1" n:px{:o rou!ndex """ ...
I~-]I
. 3.5. .
Let Demo ,
--
, vntDemo, :
- 42
Proper~ y Le t Demo (In dx As Intege r , As Vari an t )
Indx > UBou nd (vntDemo ) The n
button.
Privat e Sub -C i c k ( )
If Tr i m$ ( txt NewKey .Text ) = n. Then Ex i t Sub
, Get 1 0
Get Demo ,
vntDemo:
Pr opert y Get Demo ( I ndx As I n teger) As Variant
If Indx > UBound (vntDe mo ) Or I ndx < 1 The n
Demo "Error"
El s e
Demo ntD emo( I n dx )
End I f
End Pr operty
, O ~ . IsMissing 6 Xl
Func t i o n ReturnTwi c e (Op t i onal )
I f I s Mi s sing (A ) The n
0 Nu l l.
Re turnTwi ce =
El s e
,
Ret u r nTwic e = * 2
End I f
End Fun c t ion
--
43
Optional Variant Visual Basic 4.0,
. ParamArray,
, :
Di m As Va r i an t , As Variant
Dim i ntSurn As Intege r
Next
Int Sum =
End Sub
Sum
ParamArray. For Each ,.. Next
.
Ti1U l JI
( . 2.3)
main (
C
DOS main).
standard modle . , ,
, " " Command$
Visual Basic.
Visual Basic VD. EXE :
main , :
Sub Mai n ( )
file$ = Command$
End Sub
file$ . ,
main ( End), .
[. vt"'UA I BA", tC
--
....
Ap~
Visual Basic. :
Str$
Slr$ .
VaI:
% ~ 23
St$ - Str$(T %)
% ~ Val( St$ ) + 12 0 0
Inslr, InstrB
Instr
InstrB byte. :
Target$ = ~Au v~ a~ 1K N
Se a r ch 2$ " a "
= I n St r ( Ta r get $, Se a r chl$) 0 6
v = InStr(Ta r get$ , Search2$} 0 16
= InSt r ( Ta r g e t $, Search3$} 0
Len, Lenb
Len . LenB
byte. , , resul11
28 :
String l = "
resultl = l e n ( s t ring l )
Space, Slring
.
, . ,
, Space 20 , Slring
--
ASCII 45, 20 :
45
re su l t1 = Space (20 )
result2 = St ring( 20,45 )
Lcase, Ucase
.
Format
u Format u .
:
. .
# . .
- + $ () .
'
G,ner_1Number .
Currency 10 . .
--
MyDate = IJanua ry 27, 19931
0 46
E~ ~ long time .
My St r = Format (Time, "Long Time" )
E~ ~ long dat e .
MyStr Fo rmat(Dat e , "Long Date" )
\ x ~ f o rmat , ~ ~ o~ ~K
\ n St r $.
MySt r = Format (2 5 ) , . . , "2 5''.
MySt r Format( 5 45 9. 4, " , . 00" ) 1.0 1. "5 ,459 . 40".
MySt r Format( 3 3 4. 9, . 00 " ) E1 ~ "3 3 4. 9 0" .
MyStr Fo rmat (5 , "0.00% ") E~1. '500.00 %'.
" "
Visual Basic . .
, n Da t e 1.~ 24 /9 /9 7
, K ~ n Time ~1 2 : 10 : 4 4
DaleSerial, TmeSerial
DateSerial ,
--
47
. TmeSerial.
l ( 1)
Visual Basic ,
, :
m .
Sin .
. m .
e ( ) .
Log .
Sqr .
Randomize .
Rnd .
nvv
MsgBox, '
. ,
, .
:
prompt
title .
, prompt chr(1 3) & chr(1) (vbCrLf)
, :
buttons
, . defau~ ,
:
1 C.ncel'
2 b , Retr Ignore.
3 Yes, CanceI.
4 Yes ,
5 Retr C.ncel'
--
:
48
1 .
2 Cance1.
3 Abort.
4 Retry.
5 I,.
Yes.
7 .
,
l $ :
prompt
ttl e . defau ~ ,
. ,
3.6.
dim r c
rc = nut $( ~ aaa . & _
vbCrLf & v bCrL f & UMn ~ 10 a ." , _
" " , " . " , , )
13
Io:/;J rpooy:rte cme
.
Mro( t ree (.
. 3.6. l t $ .
tt p r r l>oEveJIt s
( ) ,
,
,
OoEvents. 32-b!
, Windows 95 "preemtive multitasking".
16-b! Window$ 3 .,
OoEvent$ , ""
.
standard
.
Dim , OpenForms
Fo r = 1 1 5 0 00 00
Ope nForms = DoEvents \ . 1. 1 .
--
Next
"9
.
Basic, 11 ...Then ... EIse, Do For,
Basic. , Visual Basic :
11 ... Then
:
Condition , True
False . , condition True, Visual
Basic Then. ,
. condition False
, ! ... Then ... Else:
Elself. . ,
4 command button controls
. event Click, :
El s el f I nde x 2 Then
Else
End I f
End Sub
, myDate:
Su b FixDa t e()
oim myDa t e
--
myDate - # 2 /13 / 95#
50
If my Da te < Now Then myDat e = Now
End Sub
Elself ,
SelecI Case. , , 1I
boolean. :
End If
Select Case
Visual Basic 1I ... Then ... Elself, Select Case,
. :
Case. ,
Case Else. , :
Case 1
Case 2
Case E1s e
End Se 1e ct
End Sub
. Visual Basic Do ... FO ... Next.
--
Goto, -
51
, Do ... .
. l Do :
00
[ s t a t e me nt s]
Lo o p
.
target$ '
slrinS. , GoTo:
Funct i on CountSt ring ( s tr i n $ , t arge t $ )
positi on % = 1
l a b:
fi nd% = I nStr (po sition, s t r i n, t arget )
If f ind% The n
po s it i on = InStr(position. st r i n, t arget) + 1
CSt ring% = CStri ng % + 1
GoTo l a b
End I f
CountSt r ing CSt r i ng %
End Func t ion
. ...
:
... While :
00 While condition
( s t a t eme nts ]
Loop
condtion (True),
m False () . :
--
CSt ring% = CString % + 1
52
Loop
CountStr ing = CString%
End Function
00 ... L,
:
[statements)
Loo p While condition
False Tre .
j9 _~ _ poppg 9
Unt i l condi t ion
[statements) [ s t a t e me nt s ]
Loop Loop Until condition
text, :
Found = False
For Each MyObject 1 MyCollection
--
If My Ob j e c t. Te x t = ~ H l lo " Then
53
Found "'" True
Exit For
End !
Next
M~oo (Mettods)
VT , (forms) controls,
controls (properties)
events.
control. , :
Object (name) .
object form , Cls:
[Fo rm. ] Cls
. , Form
. :
Cl s
. Hide ,
:
[ . ] Hi de
Show,
:
controls SelFocus :
--
object.SetFocus
54
control events, !
.
() (
Basic,
,
" " . Visual Basic Quick
Basic , ,
, , , con-
trol .
Basic , (sequential), (random)
(binary) . ,
, random disk,
.
. (records) .
25 24. ,
, , byte-by-byte.
, Visual Basic :
Open, :
pat!lname , made
Append, Binary, ',
Outpul Random. access
(Read), (Wri'e) (Read WrIte)_ filenumber
FreeFiIe. , Len
random '
. pa'hname ,
Append, Binary, Random mode.
, Print # ' .
--
55
MyBoo l = Fa lse : MyDate = t Februa ry 12 , 19 69 1 : MyNu l l Null
, ' :
Dim Fi l e Nurnber
FileNumber = Fr e eF i 1 e
Ope n ~T EST.DAT" For Out put As iF ileNurnber
Wri t e iFi1eNumber, ~Au 1. 1.
Cl ose t Fi1eNumbe r
! #
TESTFILE,
Wri!e # , ' ,
("Hello", 354):
Dim MyString, MyNumber
Open ~ TE S T F I LE For I nput As ' 1
00 While Not EOF (1 )
I nput #1 , MySt ring, My Number
Print MySt r i ng, MyNumber
Lo
Close # 1
Line ! # ,
Chr(13) Chr(1 3) + Chr(1) ,
, '
!e tbox control:
Dim Te xt Line
Open ~TESTF ILE " For I np ut As 1 1
\ 1.
0 0 Whi le No t EOF ( 1 )
Line Input 11 , TextLine
Te xt1 . Text = Text1 .Text + Chr$(13) + Ch r $ ( 10 ) + Te xt Line
Lo
Cl ose ' 1
, :
random ,
.
, :
Priv a t e Type Or g anize r
--
SurName As String * 30
56
Name As String * 2 0
Address As String * 40
Telephone As String * 10
Credit As Long
Charge As Long
End Type
. ,
indexlextboxes conlrols COXO
buttons .
wp;g, , . ./. . ~ !l
..,
I.
..,
11
,
llO
,--J 11 ,,"""
. 3.7. .
\ textboxes contro ls
Call TakeValues(Data Input)
RecLength = Len( Data lnput)
Fi leNum = FreeFile: DBFi le ~DBFi le. fi l H
'
,
LastRecord = LOF(Fi leNum ) \ Len(DataInput)
Recnum = LastRecord + 1
--
, K ~
57
- -- - -- - -- - ""-'-- - - - -- - - - - - - - - - - - - - - -
\ .
Seek #FileNum, Recnum
Put #FileNum, , Da t alnpu t
Close #Fil eNum
End Sub
SurName.
, ,
, SurName ,
, tetb oxes controls :
Private Sub Command2_Click()
Di m SurnameToLook As Str ing
Dim DBFi le As Stri ng
Dim Datalnput As Organizer
Dim RecLength As Lo ng
Dim Fi leNum As I nt e g e r
Call TakeValues(Datalnput)
RecLength = Len(Datalnput )
Fi l eNum = FreeFi le: DBFile = "DBFile. fil"
" ))
I f SurnameTo Look = "" Then Ex it Sub
\ l.l.Q l.
Fo r Recnum = La s t Re c ord 1 Step - 1
Seek #FileNum, Recnum
Get #FileNum, , Datalnput
I f Trim$ ( UCase$ (SurnameTo Look
UCa s e ( Trim$ (Da t a l nput . Su r Name Then
Te x t l (O ). Te x t Data lnput. SurName
Textl(l).Text Da t al nput. Name
Textl(2).Text Datalnput .Address
Te xt1(3) .Text Data lnput .Telephone
Text1(4) .Text Da t a lnput . Cr e d i t
Text 1 ( S) . Text Datalnput .Charge
End I f
Next Recnum
Close #F ileNum
--
58
End If
End Sub
j OrganIzer,
textboxes controls:
Private Sub TakeValues(Datalnput As Organizer )
Datalnput.S urName = Textl(Q).Text
Datalnput .Name = Textl(l) .Text
Datalnput.Address = Textl(2) .Text
Datalnput .Telephone = Text l(3).Text
Datalnput.Credit Val(Textl(4).Text)
Datalnput.Charge = Val(Textl (S) .Text)
End Sub
, , , , byte-by-byte.
, ,
. , Fl e Co py ,
CopyFile . ,
30000 bytes source$ dest$. j ,
Lof, source$, k, ,
30000 bytes i bytes
:
, source$
If Dir$(source$ ) = "U Then Exit Sub
, dest$ u KOl
\
Open source$ For Binary As #il
Open dest$ For Binary As #i2
v 30000 bytes
1 Lof(#il )
k ~ 1 \ j ~ 1 Mod 30000
30000:
For i = 1 k
bb$ ~ Space$(30000)
Get #il , , bb$: Put #i2 , , bb$
Next
, v Vlo Kl
I f j Then
bb$ = Space$(j): Get #il, , bb$
--
Put #i2, , bb$
59
End !
Cl o s e # i l , i2
End Sub
(DebuggLTIg)
Visual Basic .
, (Single Procedure Step) ,
' (Breakpoints),
.
. '
Debug , toolbar,
.
(modes) ,
design time, , ru time, ,
break, , .
Break toolbar CTRL + BREAK.
(caption bar) Visual Basic.
, debug:
d.bugging
Step l .
Step " , -
.
Run ""
design, Continue, Break
End
time. break mode
. breakpoint, " "
F8, design.
, , , ,
break mode.
--
60
M'i!jI\ .ll
I (~ner .. ) J
IInth$ (5} .. "!l.Y~: !lnth$ (6) .. ~J un " : IInt h $ ('7) .. "Ju. ~ : .!IntM " ...
IInth $ (9 } .. "Sep~: !l.nth$ (10) .. " OC:t~ : !lnth$ ( 1 1 ) .. "No ~: !lnth$ ( 12
. 3.9. F8 breakpoint l .
.
. , ' , ,
.
, Add Watch, '
break mode.
Quick Watch .
, "Shift + F9",
, Instant Watch, .
ax (p ~
' , .
. m . , '
,
. Visual Basic QuickBasic
, . Error,
, ,
, , .
, , .
Resume, ; :
Resume () ' .
--
61
, Err m m
, Error Error$ .
. l _open [ ,
, m m
Err :
Case 1
apen f$ Fo r Output As ~i
Case 2
Open f$ For Input As #i
Case 3
f$ For Ra ndom As #i
Case 4
f$ Fo r Binary As #i
Case 5
Open f $ Fo r Append As #i
Case Else
i=O
En d Se!ect
file-ope n = i
Exit Function
telos:
i = - Err: Exit Funct ion
End Function
' 1 32767.
m Visual easic, ; Err.
Err = n
, Error ,
:
Exit Su b
ErrorHandler:
Msg " l"
-- 62
MsgBox Msg , 1
Resume Ne x t
End Sub
Asse rts
Assert i Debug, i
oj i debug mode,
i . :
i ,
False, .
, i , j CustName
"George":
De b ug . As s ert Trim (Cu stName ) <> uGe orge"
[ - n
Monte Carlo
Monte Cario [ i [ oj
i i, ..
, i .
i OOKj:
[vCidxl
Monte Carlo, :
,.--- - ---,
I=~/N
, [0,1].
Rnd, i TUXaio .
TUXaio [Iowerbound, upperbound] :
Int( ( upperbound - lowe rbound + 1 ) * Rnd + lowe rbound)
, i 600 [ (
i j ) :
--
63
Dim i , ,
Fo r i = 1 600
~ Rnd (l )
= + Sqr{l - 2 )
Next
~ / 600
0,7867323968301 69,
, /4 , = 3,14""
InsertChar sChar ' sTarget iPos.
Sub I n s e r t Ch a r {sTarget As String, sChar As String, iPos As Integer)
If Len (sChar ) <> 1 Or Abs (iPos) >= Len(s Target) Then Exit Sub
Mid$ ( s Ta r g e t, Abs ( iP o s ) , 1) = sChar
End Sub
, ab byle
, ReDim.
Function I s Ar r a y Emp t y ( a b ( ) As Byte ) As Boolean
Dim v As Variant
Error Resume Next
v = ab(LBound(ab) )
IsArrayEmpty = (Err <> )
End Function
VIsual 8asic,
, False .
End Function
--
6<1
FmtStr Visual
Basic. iWidl h,
, fRighl ( False),
.
conlrols
controls
. Command butlons controls. :
Privat e Su b Command l-Cl i ck { Index As I ntege r )
GetCon trols Comrnandl ( )
End Sub
GelConlrols Variant.
Sub GetCont rols ( CArray As Variant )
o i m C As Con t r o l
For Each C n CAr r ay
MsgB ox C. lnde x
Next
End Sub
, .
Load .
--
65
bitwise
Visual Basic bitwise , macros HIBYfE,
LO , HIWORD LOWORD, C
Iong Integer. LO high-order low-order byte
, HIWORD LOWORD long Integer.
.
wparam ,
long Integer.
Fun ct i on ge thilobyte (wparam As I nte g e r . LOBYTE As Inte ge r ,
As I n teg e r )
\ 1 ~o LOBYTE wPa ram
LOBYTE :::: wParam An d &HFF&
, iVQl wParam:
= wPa ram \ &0 0 And &HFF&
g ethi l o b yte = 1
End Funct i on
End Sub
\ 1 lPararn
lPararn = &H7777FFFF
r et = geth iloword (lPa r ~ LOWORD, HIWORD)
End Sub
--
66
Cvi Mki$
Visual Basic Mki$ Cvi%
Basic. Mki$
:
Function Mk i $(i%)
temp l& = i %
If templ & < The n
templ & = t e rnp l& + 65536
End r f
b yte1 % = t emp 1& \ 25 6
byte 2% = templ & Mod 256
C1$ = Ch r $ ( b y t e 1%)
C2 $ = Ch r $ ( b yte2% )
Mki$ = C2 $ + C1$
End Func t i on
Gvi ,
Mki$:
Function Cvi%(i $)
b ytes1 $ = Left$ ( i$ , 1)
byt es2$ = Mid$ ( i $ , 2 , 1)
t empl& = As c(bytes 2$) * 2 56& + As c( byte sl $)
I f t empl & > 32 767 Then
temp l & = temp l& - 65 5 36
End If
Cvi% = templ&
End Funct i on
Extract
a$ .
b$
Extract G. , a$ = "dem01\dem02\dem03\dem04"
b$="\" , , G=3, "dem03".
Func t i on Extract$( a$ , b$ , C)
Dim i As Long, k As I nt eger, m As Long
temp $ = Trim$(a $): rf t e mp$ = ~N Or C < 1 Then Ex i t Func t i on
Do
i = InSt r(temp$, b$ )
I f i Then
k = k + 1
If k = C The n
m = InStr(t e mp$, b$ )
I f m Then
Extract$ Left$(temp$ , i - 1): Exit
El s e
--
Extract$ temp$ : Exit
67
End If
End I f
If i + 1 > Le n( t e mp $ ) Then E it 00
temp$ = Mid$ ( temp $, i + 1)
El s e
k = k + 1
I f k = C Then Etract$ ternp $
E i t 00
End If
Lo
End Function
Delimiter .
Rinstr
b$ aS.
' .
Fun c t i o n Rinstr(a$ , b$ )
Oi rn i As Long
For i = Le n (a$ ) 1 Step -1
C$ = Mi d S ( a$ , ., 1) + C$
If InS tr (C$ , b$ ) The n
r i n s tr = i: E i t Func t i o n
End If
Net
En d Func t i o n
j}/JUTIva Replace first$ a$
afte$ :
a$ - C$
End Sub
Strdel a$:
Sub Strdel (a $, 1)
For i = 1 Len (a$)
d $ = Mid$(a$ , ., 1)
--
68
If i <> 1 The n C$ C$ + d$
Next
a$ - C$
End Sub
Stripchar b$ a$.
aS:
Sub St ripchar(a$ , b$ , 1 As Integer)
1 -
For i = 1 Len(a$)
Fi nd% = : m$ = Mid$ (a$. ., 1)
Fo r j = 1 Len(b$)
d$ - Mid$ (b$ , j, 1)
! UCase$(m$) = UCase $(d$) Then Find% 1: Exit For
Ne xt
If Find% = Then
C$ = C$ + m$
1 = 1 + 1
End If
Next
a$ = C$
End Sub
Striprange a$
ASCII start end_. b a$:
Sub St r ip rang e (a $, s tart As Integer , end- As I nt e ger, b As I nteger )
b =
Fo r i = 1 Len ( a$ )
d$ = Mi d $( a $, i, 1)
I f As c( d$ ) < start Or As c( d $) > e nd- Then
C$=C$+d$
Else
b = b + 1
End I f
Next
a$ = C$
End Sub
Windows
. . AppRunning ,
. ,
. ,
Visual 8asic, ( ) ,
Prevlnstance, :
--
69
Sub AppRunning ()
Dim sMs g As St ring
I f App.PrevIns t a nce The n
SMsg = " " & App oEXEName & " x ~! "
Ms g Box s Msg , vbCr i t i c a l
End
End I f
End Sub
GetAPPPath , '
, "\" . Path .
:
label textbox
control. LongFileNameFix
,
. , , , label
40 , LongFileNameFix(File, 40).
:
TempS t r i ng = Incommi ng
LblLen = Max
I f Len(Temp St r i ng) <= LblLen Then
Long FileNameFix = Temp String
Exit Fu nc t i o n
End If
LblLen = LblLen - 6
Fo r i = Le n( TempSt r i ng ) - Lbl Len Le n ( TempString )
If Mi d $ ( Te rnp St r i ng , i, 1 ) = " \ " Th e n Ex it For
Next
LongFi l eName Fi x = Le ft $ ( Te mpS tr ing , 3 ) +
"0 00" + Right$ ( Temp St r i n g , Le n ( Temp St r i ng ) - (1 - 1
End Funct i o n
--
70
, (
recursive).
Funct i on Le nLong e stWo r d ( ByVa l s rc As St r ing ) As Integer
Di m i As Integer. j As Integ er
i = InStr (src, \\ \\ )
If i > The n
j = LenLongestWord(Mid$ ( src, i + 1
! j > i - 1 Then LenLon ge stWord j El s e LenLongestWord i - 1
Else
Le n LongestWord Len(src)
End If
End Func ti on
,
IsValidPath . , ,
vbDirectory vbNormal, :
Fu ncti on I sValidPath ( s t rPath As Str ing ) As Bo o lean
IsValidPath = Di r (st r Pat h. vbDirectory) <> \\>'
End Fun c t i o n
CreateLongDir ,
,
Dir$.
K~oo :
Call Cr e a t e Long Di r ( "d : ", "\Test \Te stl \ Lo ng Di r e ct ory Name\ "')
Visual Basic, SaveSetling GeISetling,
Registry Windows.
, .
--
71
PutFonPos~ion Left. , Width Height
. Tag :
Sub PutFormP os it i on (F As Fo rm )
Dim bu f As St ring
bu f = F. Le f t & "," & F.Top & "," & F.Width & "," & F.Height
SaveSetting . EXEName, "Fo rmPo s i t ion" , F. Tag, buf
End Sub
Unload .
GetFo nPos~ion Registry .
Load :
F.Move 1, t, w, h
End !
End Sub
1) ;
; m .
2) ; .
3) Publc Private; ;
.
4) " " ;
.
5) ;
.
--
72
6) main;
7) Visua/ Basic.
8) ; l
; ; Redim Preserve
Redim; Vissua/ Basic.
9) Visua/ Basic.
10) (structures); .
11) ; Form.
12)
Extrac/.
custom Defmiter
13) Exist
D$.
.1 . = 5 = 3, True/False
:
<
> =
=
*3<+4
2. ;
12, 3C, 2 , Name$, $B, .
3. 1 6.
For ...
4. 1 100.
.
5. (1 ) '
( 10) , .
l l .
6. :
TakeSectio n( istri ng$, t mpl $, tmp 2 $, Opt iona l En d s As Varia nt) As String
--
73
tmp1$ tmp2$.
Ends , tmp2$
.
7. .
. 9. ' nivaKG i i
. .
, command butlon , ,
( Print) .
--
7 -4
~!/(,
jd ---'~
MeJu
, command
buttons , Visual Basic
. menus .
/"",nuMIt
:::r"'
~ Menuitem L.te<'IUbaf _ l l
B3~~",
,,--- ~__ 1
~
Separalor t
,"00
MeJ)u EdLtor
Menu Editor design
menu controls
. , Menu d t r
--
Tools Menu Editor button toolbar.
75
~
,-
Cgxn- ! w
'''' j......,ilelleo
J:ieteoo:e>4!D:
r"""",
r-
P .E.rIbIed
~'I!lI'"ldov<L*,
..
"'-
" "Wer .
....S-1M..
- . .. ,. J
........ -...
-- &.Cdo:.
-
-, ..:J
, menu .
click menu control, Code Window
. ,
, click Visual Basic ,
, menu controI click.
Clck menu control :
Pr i v at e Sub Name-Click{ )
--
End Sub
76
n MeJII CoJItroI
, controls controls ,
, events. menu controls.
, ,
run time ,
menu items.
, design, '
. Index text box
, .
Click .
End Sub
Index .
menu cantrals menu
submenu.
SubmeJIU5
submenu '
menu menu items.
submenus.
r - - - - - -- - -- - ---,
'
- "
~ Bodd:t>b F F~F Nf FOR MICROSOFT 5
! [ " s_ . , . !!
IMPORTANT- READ
'- ,
CAR~ I#" I. ~;bi"
betwe en you (ei1her < o~ t!m,t:BIJo
individual
identified above. which includes computer 50 a <
oIln:~ elec1ronic documen 1ation I SO FTWA RE PRO
SOFTWAR E PROOUCT, i 10 be bound bythe
EULA, dO in5103ll use the SO FTWAR E PRODUC:
refu nd
. 4.3. submenus.
, Menu d r.
! c~,l m ~~
""" 1- J' """
)ro~: ~ ~: 1(""""")
~,"" ID:~ ~:!o'No<>e J
r Q>o<t.ed P' ~ P' ~ r ~
:!li]:!li] D:Jr!:EJ ~
=, "-',
..
_"'"
<IR.d
~..
" " " " H$Je
-~
J
. . w .d
. ......-&Gr.""
.",,,,,,,.-&fIb
' ;;:;;;:.-&1a.e_ ..:J
--
. 4.4. 4 submenus.
77
, check
menu ilem, Click conlrol:
Private Sub Menultem-Click ()
Menultem.Checked = Not Me nu ltem.Checked
End Sub
Menuname.Visib le = Fals e
, menu conlrols, , , 1:
Menuname(l ).Visib le = Fa lse
menu , ,
--
(keys) access shortcut. access ' menu
78
L menu item, .
caption command buttons,
(&) .
menu item.
s ho t cut '
function-key control-key, CTRL+F2 CTRL+X.
shotcut, Shotcut combo bo Editar.
>- rneJjU5
menu menu
bar, 4.6.
'81
i _ '*"4.. 1, . g
Ies! U1!OnS
"!:f.orrJ'M: end AutoSI
Q>ed<Box
tlumberSy$!em
Lt$16QX
MuIIpl e-Colum n l.$.1 ;
SoOIBm
Conlrpl&r~
. 4.6. - memu,
- menu PopupMenu :
, - menu, flags
menu. , , - menu
.
- menu 4.6.,
4.7., menu.
,
!- ..",.
,........
- ,-
~
'- ~
1-
Iot;Ud...:D ----
"'"'" 10_ 3
.,.... ,- ,- r,.....
~ .!I:iI .!I :::J ~-=.J
----
- ... -
"'""'~
.
---
--VUoDor s,....
~~
- ~ . 800
. ..8 ..
--
. 4.7. l - memu.
79
Click . :
text box
o ~ xl
text b ox control 0
n . .
1 n text bo x
a Light Blue
--
80
Sub mnuBlueltem-Cl ick ( I n d ex As I n t e g e r )
If Inde x = Then
txt Ed it.ForeColor RGB( O, 150 , 255)
End If
End Su b
~ t e xt box
Dark Blue.
menu b a r.
- Se l e c t Case I n dex
Case
index = , ~ N ew "
K ~K X~K l t e x t box
Kl l caption
Case 1
i ndex = 1, " . .. "
l .
Q l , l Q l Y1Q i
--
81
CMDi a log l . Filter = ~Al l File s ( *. * )1 *. * Text Fil e s
(* . txt) I*. txt /Ba t c h Fi l es ( *.bat )I *.bat R
CMD i a logl. Filterl nde x = 2
CMDial ogl. Action = 1
Fi lename = CMD i a logl . Fi l e name
Call OpenFi le(F ilename )
Ca s e 2
i ndex = 2. ~ S ave As...
, ~x text box
CMD i a l og l . Fi l te r = ~ All Fi les ( *. *) I*.* ITe xt Fi l e s
( *. t xt ) I*. t xt IBa t c h Fil e s ( *. ba t) I* .bat R
CMD i a l og l . Fi lte r l ndex = 2
CMD i a l og l . Act ion = 2
Filename = CMDialog l .Fil ename
Cal l Cl o s e File(F i l ename)
Case 3
i nde x = 3. ~ Cl o s e R
txtEdi t .Te xt = _
frmEdit o r . Capt i on = - Te xt Edit o r : Untit l ed W
mnuFil e l t ern(3 ). Enable d = Fal s e
Call Cl oseFile( File name)
Case Els e
End Se l ect
errhand ler :
Exit Sub
End Sub
t e xt box cont r o l .
Case 1
I nd ex = 1 24
t xt Edlt. Fon t .S lze = 24
mnuF ontS ize sltem(O).Che c ke d Fa l s e
mnuFontSiz e sl t em(1).Checked Tr ue
End Se l e ct
End Sub
, text box
CMDia l o g lSub mnuFo r e Color l tern-Cl ic k (Index As I n teger)
Select Case Inde x
Ca s eO ' KKK ~O
txtEdit . Fo r e Colo r RGB(255, , )
Case 1 '
txtEd i t . Fore Co l or = RGB(O, 2 5 5, )
Cas e 2
, x ~ K ~ K K ~ submen u
End Sel ect
End Sub
Dim ArrayNum As I nt e g e r
Glob al Filename As String
Cons t MB_YESNO = 4, ~CONQUE S T ION = 32 , D = 7 , MB-DEFBUTTON2 2 56
o~ K~ ~ t e x t box
.
~ x ~ o~ x .
K ~ n UpdateMenu ~ V ~ K
menu i tems menu .
F = Fr e e Fi l e
Open Fil enarne Fo r Inpu t As F
frmEdi tor !txtEdit .Text = Input$ (LOF (F ) ,F )
Clo se F
frmEditor !mnuFile lt em(3 ) .Ena bled = True
frmE ditor.Capt ion = "Text Edit o r : " + Filename
Upd at e Menu
Ex it Sub
End If
ErrHandler:
Clo s e F
Msg Box " , OK~ ~ . n , 48 ,
"Te x t Editor"
Exit Sub
End Su b
K ~ t e xt box
--
~ . VB Dir$
8 3
1 .
MsgBox 1 1
(Oerwrite ) .
Sub UpdateMenu ()
frmEdito r!mnuFileArray(O ).Vis ible True
ArrayNum = ArrayNum + 1
For i = Ar rayNum - 1
Next i
Loa d frmE dit o r !rnnuFileArray(Ar r ayNurn)
f rrnEd itor!mnuFil eArray(ArrayNum). Capt i on File name
frmEditor!mnuFileArray (Arr a yNurn ).Visible Tr ue
End Sub
1. v v v Vsual Basic;
2. v Submenus;
3. v v v; vrr.
4. v access;
--
85 - - - -- - - - - -- ----
,
ments) (D form) . Program
Manager File Manager Windows 3..
child, MDI, ,
. child
MD/Child True, D .
Child, , D
desktop Windows ( 5.1 .).
MOI
work$pace
Minimzed
childwindows
. 5.1 . child .
child, standard,
--
.
87 - - - -- - - - -- - -- - -
poj
D child F 1 , '
multiline textbo controI. D menu , New,
document. :
Privat e Sub New_Click ( )
Dim Ne wDo c As Ne w Fo rml
cn = forms .Count
Lo a d NewDo c
Ne wDoc.Caption ~Formn + Trim ( cn )
NewDoc. Show
End Sub
Count
caption , modal.
NewDoc Form1 (
New Dim, ) events ,
. , ,
' .
F _Resize :
Textl .Left =
text bo .
Form1, , :
Fo rml. Text l . =
' , :
Me. Text l . =
, ;
. module :
, MDIForm_'-oad :
Pr i va t e Sub MD IF or.m-Load ( )
ReD irn NewDoc ( O) As New Forml
Load NewDoc ( O)
NewDoc( O) . Caption = ~ Formo n
Ne wDoc ( ). Show
--
End Sub
88
:
child , .
. ,
,
Document. . Tet1 _Change tetbox:
, Form_Unload.
Tag tetbox , 1, .
Cancel True, :
Privat e Sub Fo rm-Unl oad (Cancel As Int eger)
Di m Msg As String
rf t ext l . Tag = "1 " Then
Msg = " " & Me .Caption & " ~ o~"
Arrange, Documents
, .
:
MD Iform.Arrange arrangement
arrangement .
vbCascade child .
vbTileHorizontal 1 D child .
--
89
, vbCascade,
vbTileHorizontal vbArrangelcons MDI child.
.. D No!ePad I!I~ EJ
f 'lfflt!ffi f
_ l l l:
. 5.4. vbArrangelcDns ch ld .
--
90
End If
Next
End Sub
Minimized :
Toolbar
toolbar standard ,
. [
bitmap ( control Align, bitmap
standard controls ) , ' buttons .
, custom toolbar control.
, buttons controls,
. , Glick buttons :
--
. 5.5. toolbar Mdi.Vbp.
91
l MDI
MDI,
5.6. MDI ,
PaInt, .
, . ,
. Mdi Child,
bitmap control ( ) . BorderStyle
Control . , bitmap control
.
Resize MDI :
, Activate :
Zorder 1, .
--
. 5.6. bitmap MDI.
92
. ro Mu/lip/e - Documenl intertace (DI);
2. D/ D/ chld r r "" ;
3. m MDI.
1. , MDIGhild
.
2. Mdi.Vbp . File
Open menu item, ASGII
textbax control. menu
items. ' ,
.
4 ' ASGII, ,
, .
--
93
Visual Basic
' ,
, . .
, . controis, line shape,
. cantrols ( image)
, (focus), hWnd,
.
, ,
( ), picture control , , printer object.
:
Circle , .
, (
) ,
Paint , Command1_Click command button,
. , , , object
AutoRedraw True. ( , Visual Basic
controi, ov
, .
,
Visuai Basic.
-
.-
95
x-axi$ ()
y-aKi$
.. CI>Ofd, rate S, sIelfl E x"nple 1![!]3
..
() . : ':.:':" . Fme
: ... 1
"
. 6.1. .
, (0,0). '
, .
, ScaleLeft, ScaIeTop, ScaleWidth ScaleHeight Scale,
defauh .
defauIt twip, 1/20 , , 1,440
.
twips (inch) 567 twips 1 (cm).
, ScaleMode,
:
VbPixel s (~3)
VbCharaeters(=4)
Pixel ( ) .
VbCentimeters(~ 7) (Centimeler).
, DrawWidth ( pixels) ( )
. 1 (default) 32,767.
, ScaleMode,
, Circle, :
Pri vat e Sub Form-Clic k ( )
, 1 1 ScaleMode .
ScaleMode = Sc ale Mod e + 1 ) Mod 7) + 1
--
, 1 1 , 2.
96
Circle (ScaleWidth / 2, ScaleHeight / 2 ) , 2
End Sub
l,}
, ' Crren
CurrenlY,
' .
:
Circle ( ).
L i .
Print .
Pset
RGB
. :
255 ( long
integer) .
:
RGB :
RGB(O, , )
RGO(O, , 255)
RGO(O, 255, )
RGB(255, , )
RGB(255, 255, )
RGB(255, 255, 255)
, OBColor, RGB
, 16 OickBasic.
15 :
Psel
. :
, , Step
Crre n CurrentY
.
--
, color RGB
97
Q8Color. , .
DrawWidth . , DoEvents
, .
End Sub
Line
. :
Step
CurrentX CurrentY. 1 , 1
, 2, 2 . color
. , ForeColor. 8
, F
,
FillColor.
.
.
Li n e ( 1 0 0 , 2 0 0) - ( 15 0 , 2 50 )
Line (1 0 0 , 2 0 0) - Step ( 5 0, 5 0)
, :
Line ( 5 0 0, 5 0 0 ) - (1 0 0 0, 10 0 0 ) . . BF
--
. 6.2. Line.
98 - - - - - -- - - -- - - --
:
Cur r ent X 15 0 0
Cur renty 500
Line -( 3 0 0 0 , 2000 )
Line -(15 0 0 , 2000 )
Line - (15 0 0 , 500 )
End Sub
!
picture control. :
[o bject . ] Point(x,y )
, . objec!,
-1.
.
Cl s ' K ~ 6 ~
He i g ht = 3 * 14 4 0 ' L .
Width = 5 1 4 4 0 ' .
Ba ckc olo r = QBColo r ( l ) , backg r oun d .
Fo rec olor = QBColor ( 4 ) f oreground ~6K K1o.
Li ne (, O) - ( Wi d t h / 3 , Height) , , BF \ 1 n 0 1 0.
Forecolor = QBCo! o r ( 1 5 ) , for eground .
Line (Wi dt h / 3 , ) - ( ( Width 3 ) * 2, Heig ht ) , , BF.
LeftColor = int . ) \ 1 0 ~ o .
MidCo lor = Point(Wi dth / 2 , Height / 2 ) \ 1 . 1
Ms g ~T o 1 1 ~
MsgBox Msg \ 1 nv
--
. 6.3. .
99
CircIe
, . :
Step ,
C rre n CurrentY. (,)
, radius , color
. start end (radians)
, . -2 2. d efau~
. aspect (ratio) . default
1 . ,
FillCoIor FillStyle.
.
\ . . . .
Circle , 1 0 0) , 50 , RGB( 2 5 5 , . ) \
Ci rcle ( 25 0 , 10 0 ) , 50 , RGB(2 5 5. , }, , , 1 / 3 \ l.
End Sub
.. FoIml I!I~EI
8
. 6.4. .
, Form_Click ,
:
\ 6
Circ1 e ( 15 0 0, 15 0 0 ) , 1 0 00 , - / 2, - / 3 l.
--
End Sub
100
"i FoIml 1!!IIi1E3
. 6.5. v FoIm_CIick.
PaIntPicture
(. , .WMF, .EMF, .ICO .GIF . . )
' Form, PictureBox, Printer. :
l1.
pIcture Picture PicrureBox control.
, 1, 1
width1, height1 2, 2 width2, height2. opcode
.
PaintPicture
bitmap , pIcture controls.
100 picture control:
Fo r i = 10
Fo r j = 10
Forml . PaintP icture pi c F. Picture, j * picF . Width, i * p icF. Height , _
picF .Width, - p i c F. He i g ht
Next j, i
default
. - .
DrawWidth
DrawWidth pixels Line, PSet
Circle. , ,
DrawWidth:
- - - - - -- - - - - - - - -
--
1
For i 1
12 Step 2
=
=+ 400
DrawWi dth = i
Line (2 0 0 0 , 10 0 + )-(5 0 0 0. 10 0 + )
Next
End Sub
.. ForIIl 1!!I~E3
. 6.6. Form_Click.
DrawStyle
DrawStyle Line
. 6 :
For i = 6
DrawSt yle = i
= ( 2 0 0 * i ) + 10 0 0
Line (2 00 0, 10 + ) -(50 0 0 , 10 + )
Next
End Sub
.. Foml I!II!JEJ
. 6.7. Form_Click,
FillGolor FillStyle
--
' , ,
1 02
( Circle Line),
FillStyle
. 7 .
(solid) FillColor, 1 (default)
.
FillStyle,
FillColor. 6.8.
Private Sub Fo rm-Click ()
Di m i .
For i = 7
= ( 80 0 * i )
Fi l lCo lor =RGB( 2 5 5, , )
Fi l l Style =i
Ci r c l e ( 1 0 0 0 + , 1500) , 35 0
Next
End Su b
. 6.8. FiIISIVle.
DrawMode
. 16
, 7 (Xor Pen) animation,
, ,
, .
, .
Fi l lCo!or = Fo reColor
Fi l l St y le = 2
Dr a wMo de = 7
For i = 1 5 0 0 0 Step 10
Ci r cle ( i, 1500) , 500
Circle (i , 1 5 0 0) , 5 00
DoEv e nt s
Next
--
End Sub
1 03
controls ,
Left. , form_CliCk, com-
mand button control .
= comma nd l . Le f t
s c a l e l e f t = s c a l e I e f t - 10 0
c ommand l .Left =
End Sub
scaleleft = s c a l e left + 10 0
' .
, ScaleWidth ScaleHeight
. , :
1/1,000 1/500
. command button cantrol,
.
= commandl . Wi ctt h
sca l ewidth = sca lewi dth - 10 0
command l . Widt h =
= commandl. He i g ht
s cal eh e ight = s c a l e he i g ht - 100
comman dl .He ight =
End Sub
default '
--
, . ScaleWidth
104 - - - - - - - - - - -- ---
ScaleHeight . , :
Sc a l e Height = - 100
.
Scale,
:
( , 1) ScaleLeft ScaleTop,
ScaleWidth ScaleHeight ' .
, default , Bar char1,
Line.
Pr i va te Sub Form-Pa i nt )
Dim , Ol dFont Si ze
, A ou 0
Wi d t h = 8640: Height = 57 60
\
Move 10 0 , 10 0
\
l Ou 10
Line ( , 1 ) - (2 , )
Cur r e nt y = Cu r r e nt y + 1.5
Print
Line ( Sc a l e Wi dth - 2 , I) -( Sca l eWi dth, )
\ X lO U bars
Line (10 , 0 )- ( 20, 45 ), RGB(O, , 255 ) , BF
Line (20 , 0 ) - (30 , 55 ) , RGB(255 , , , BF
Line 14 0 , 0 ) - (5 0 , 4 0) , RGB( O, , 255 ) , BF
Line (50 , 0 ) - (60 , 25), RGB(255 , , ), BF
Line (7 0 , 0 ) - (80 , 35) , RGB( O, , 255 ) , BF
Line (8 0 , 0) -(90 , 60) , RGB( 255 , , ), BF
Li ne (1 0 0 , 0)- (110 , 75 ) , RGB( O, , 2 55 ), BF
Line (11 0 , 0 ) - ( 120, 90 ), RGB( 25 5, , , BF
--
1 05
CurrentX = 18 : Currenty = 100
\ Y 1Q
, a Print
Font. Si z e = 14
Pr int ~ W i dg e t Qua r t e r l y Sales"
\ ava
Fo nt . Size = Ol dFo nt Si z e
CurrentX = 2 7 : Currenty = 93
\
Pr int ~ P lanned Vs Actual"
Li n e ( 29. 86) -(3 4. 88) . . . 2 5 5). BF
Li ne ( 43 , 86) -( 4 9, 8 8), RGB(2 5 5, , ), BF
End Sub
--
Widget Quarterfy Sales
PIotnodv,Ao.>uoI
.
6.9. B.r ch.rt
Fo nt.Siz e = 18
Fo nt.Bo ld = True
Print ~ Hell o Vi sua l Ba s i c "
End Sub
--
1 06 - - - -- - - - - - - - --
Font controls , ,
(Name, Size ..), .
picture boxes , FontTransparenl, ,
, ' ,
6.10. ,
.
. 6.10. FontTransparen
FontCount Screen
, Fonts . , Iist box
. '
, object Screen.
Private Sub For.rn-Click ()
Dim
For = Printer.FontCount - 1
Listl.Addltem Printer.Fonts ()
Next
End Sub
Font
, StdFont:
Dim MyFont As New StdFont
With MyFont
Name ''Arial''
Size 10
Bold True
End With
, :
--
[object. ]Print expressionl istJ [{ ; .}}
1 07
":" "." ; ,
,
, ( 14
) . , :
Basic l Ba si c 2
(0,0) ,
C en CurrentY,
, :
Cu r r e nt X ScaleWidth / 2
Currenty = ScaleHeight / 2
. ,
, TeXHe ight TextWidth.
:
. , ,
.
t ForeColor BackColor.
Pr ivat e Sub Form-Cl ick ( )
Cl s
ForeColo r = RGB(255 , , )
--
CurrentX = ScaleWidth / 2 - HalfWidth
1 08 - - - - - - - - - - - -- -- -
Cu r r e nty = Sca leHeight / 2 - HalfHeight
Print Msg
End Sub
. !rc!
!
Visual Basic
. 6.11 . .
1 t
. ,
Tab, :
Tab (column)
,
. 010 6.12.
Priv a t e Sub Fo rm-Cl i c k ()
Cls
Fo nt . Name "MS Sa n s se rif"
Fo nt . S i ze 10
Print
Print Tab( 2 ) ; ' "; Tab (22 ) ; " "
Print String$ ( 62 . .... _" )
Cas e "HLP"
Des c$ = " 1 Help"
Ca s e "DLL"
Desc$ = "DLL "
Ca s e " "
Desc$ = " ~ K"
--
1 09
Case El s e
Desc$ ~ U i U + e xt $
End Se l e c t
Pr i nt Tab ( 2); f i le$ ; Tab(22); Des c$
fil e $ ~ Di r $
Loop
Caption ~ U~ v :" + CurDi r$
End Sub
CLJP8DEXE t<:1l
. l I
SMAR.TORV.EXE
REGEDrrEXE
Rie\s .b mp
Squares ,bmp
Zig Zag ,bmp
CALC.EXE
NOTEPADEXE Kioo
PACAGER.EXE
P8RUSH.EXE io
VIRlTE,EXE io
\IN.COM A(oCOM
IOS.INI !
ASPl2HLP.SYS AioSYS
HIMEM.SYS SYS
Crs,bmp
Horeycomb ,bmp
DOSPRMPT.PlF ! PlF
N!NBUG.DAT
WINBUG 1o.0ll L
. 6.12. Tab .
EXTunWTyjt;
,
Printer. Print, PSet, Line Circle
Forit.Name, Font.size ..
; .
Object Printer . PrinlForm :
. NewPage :
Printe r .Newpage
, , EndDoc :
Print er. EndDoc
.
:
--
1 10
Dim HWidth, HHeight , , Msg
Er r or GoTo ErrorHandler
Msg = ~Au ~ K o ~
For = 1 2 \
P rinte r .NewPage \ ~
Ne xt
Print e r .EndDoc \ .
Exit Sub
ErrorHandler:
MsgBox "Yx ~ . "
Exit Sub
End Sub
Page .
, :
Fo r = 1 3
Print er .P r i nt Header;
Printer . Pr i nt Print e r . Pa ge \
= Pr inter.Current y + 10
For = 1 50
Printer. Print Str ing ( K. ~ " );
Print er.Pri nt "Vi s u a l Ba s i c ";
Ne xt
Printer.NewPa g e
Next
Printer. EndDo c
End Sub
Printer, default , ,
Copies, , DeviceName,
( . . LaserJet 11151), DriverName (driv-
er) , Duplex,
, PaperSize,
, Port, (.. L1 :) . .
--
, Visual Basic (collection) Printers, -
1 11
.
. ,
defaull.
Dim As Printe r
For Each 1 Pr int ers
If x.Orientation = vbPR QRPortrait Then
\ ~o pr i nt er default.
Set Printe r =
Exit Fo r
End I f
Next
- n
Fading
fading (
, ),
FadeForm . ,
True/False . ,
, Paint :
, l l .
, x ; O U .
frm.ScaleMode = 3
pixels = Screen.Height / Sc r e e n. Twi p s Pe r Pi xelY
= pixe l s / 64# + .5
frm.Draw Styl e = 5
frm.AutoRedraw = True
For j = pixels Step
= 24 0 - 245 * j \ p ixels
If < The n =
frm. Line ( - 2, j - 2) - ( Sc r een . Width + 2, j +
+ 3 ) , RGB( - Re d * , - Gr e e n
* , - B l ue * ) , BF
--
1 12 - - -- - - -- - - - - - - -
Next j
, X~K ~.
frm. ScaleMod e "" SaveScale
frm. DrawSt y l e "" SaveSty1e
frm. AutoRedraw "" SaveRedraw
End Sub
l
Rotate.Vbp b~map cantrol OVl '
. v , PSeI.
controls AutaRedraw True ScaleMode 3 - pixel.
Rotate . F :
Defl nt -
Cons t Pi "" 3. 14159265359
~K ~ ~ pitmap pic l
t heta K~ ~ pic2
Dim c 2y As I nt e ge r pi c 2.
, o~K
Di m " As Si ng 1e /
,
Di m r As Integer o~K
~ /
c 1x p i cl.Sca l eWidth 2
cly pic l . Sc a l e Heig ht 2
c 2x p ic2 .Sca l e Wi dt h 2
c 2y p i c 2. Sc aleHe ight 1 2
~K
~ pixe l pic2.
For 2 "" n
Fo r 2 "" n
1 o ~ K /
If 2 "" Then
a "" Pi / 2
--
1 13
Else
a ~ Atn( p 2y / 2 )
End If
r = Sqr (l& * 2 * 2 + 1& * 2 * 2 )
1 1.
1 = r * Cos (a + theta )
1 = r * Sin ( a + the t a )
V l. 4 pi xels .
cO& p ic1.Point (c1 x + . , c 1y + 1)
c1& pic 1.Point(c1x - , c1y - 1)
c2& pic 1.Point(c1x + 1 . c1y - 1 )
c3& p ic1.Po i nt (c1x - 1, c 1y + plx)
If cO& <> -1 Then pic2. PSet ( c 2x + 2, c2y + 2) . cO&
If c 1& <> - 1 Then pic2. PSet ( c 2x - 2 , c2y - 2) . c 1&
If c2& <> - 1 Then pic2. PSet (c2 x + 2, c2y - 2) , c2&
If c3& <> - 1 The n pic2.PSet (c2x - 2 . c2y + 2) , c3&
Next
, 1 Windows !. 1
t % = DoEve nt s()
Next
End Sub
Yl.a l. 1 30
Pi/6 rads
--
,,4
_ -
------
~
; . ~i::88-::
" 1
. 6.13. .
conIrols
Draw3d.vbp,
conIrols . MakeBox control, MakeLine
cantrol. Draw3d.Frm,
:
T~ ~ ~ao a
Fo rm-Paint 0 0 on
n: .
AutoRe d r a w n .
2! ct. + . Height
R& = QBColo r( 15)
$& = QBColor(8 )
FormX.Line ( !, ! - 20 ) - ( 2 ! , ! - 1 0) , 5&, BF
FormX. Line ( ! - 20, ! - 10 ) -( ! - 10, 2! ) , 5&, BF
FormX.Line ( ! , 2! + 10 ) -( 2 ! . 2 !+ 10 ) , R& , BF
Fo rmX. Li ne (2! + 10 . ! ) - ( 2 ! + 10, 2! + 20) , R& , BF
--
11 5
End Sub
1 1 i
c ontrol.
! . + . Hei ght + i !
2! Fo rmX. Width
2! !
R& = QBColo r ( 5 )
S& ~ QBColo r (8 )
Fo .nnX. Line ( ! , ! ) -( 2 !, 2 ! ) , . BF
FormX.Li ne (!, ! + 2 0)-( 2 !, 2! + 20 ) , R&, BF
End Sub
"
"'
. 6.14. .
Kv resize conlrols
Resize.Vbp u u , Re size Fon ,
conlrols , .
:
--
For Each ctl fr.rn.Controls
1 16 - -- - -- - - - - -- - - -
ctl. Move CDbl (Mid$ (ctl. Tag, 1, 5 * frm. ScaleWidth,
CDb l ( Mi d $( c t l . Tag, 6, 5 * frm. ScaleHeight ,
CDbl (Mid$ (ctl . Tag, 11 ,
5) * frm. Scal e Width , CDbl(Mid$(ctl. Tag, 16, 5 *
f rm. ScaleHeight
Ne xt ctl
End If
End Sub
Load , ! TJ e
Resize ! False:
Private Sub Form-Resize ( )
Call Resi z eForm (Me , False)
End Sub
Tag controls.
1.
. button control
PaInt. ; .
;
3. ; . ,
.
4. .
()
.
5. .
.
. ,
.
. , "" , .
--
11 7
6. progressbar control
( .
) . :
, , w, h nm
1 100 ( ,
) . %.
7. '
.
, , , l
.
-
-.
1 18
[ (rnOU5e eveJ)t5)
control s
.
MouseDown .
MouseUp .
MouseMove .
controls 10 , '
. ,
control
,
:
, , ( I)
.
--
1 19
, Imagecontrol (
), button { :
As Sing le . As Si ng l e )
I ma g e l .Mo v e - Imagel .Width / 2. - Imagel.He ight / 2
End Sub
. DrawWidlh
ForeColor , MouseMove
, button ,
MouseUp.
Dim PaintNaw As Integer
Private Sub Form......Load ()
DrawWi dt h 10 ~
Fo reCo l or = RGB(O. , 255 ) '
End Sub
As 5ing1e , As 5ing1e )
Pa i nt No w = True '
End Sub
As 5 ing 1 e , As 8 ing1 e )
PaintNaw = Fals e \~ n
End Sub
As 5 ing1e . As Single )
If PaintNow Then
PSet ( , ) , ~6
End If
End Sub
11 ~""
. 7.1. .
ButtoJ)
--
. ,
1 20
MauseDawn, , ,
MouseUp, button .
:
vbLeftButton( ~ 1) button o K o t .
vbRightButton(= 2) button .
vbMiddleButton(~ 4 ) button .
, :
Pr ivate Sub Forffi-MouseDown(Bu t t o n As Integ e r , Sh i f t As Intege r, As
Single , As Single )
If But t o n 1 Then MsgBox ~~ ~6 butt on"
! Button 2 Then MsgBox ~ l butt on "
If Button 4 Then MsgBox Ula button"
End Sub
Button, MouseMove,
buttan , , -
:
button .
3 n , .
7 buttons.
buttan, :
End Sub
, buttan.
And :
End I f
--
End Sub
1 21
" StJft
Shift Button.
SHIFT, CTRL buttons .
:
1 SHIFT.
2 CTRL.
3 SHIFT CTRL.
4 .
5 SHIFT .
6 n CTRL .
7 SHIFT, CTRL .
And , :
End !
Ed !
End Sub
--
control , ' , .
122
,
controls ( menus tlmers) drag-and-drop:
DragMode control.
Draglcon control.
DragDrop control (dropping) contro!.
DragOver control (dragging)
control.
Drag u (dragging).
. dragging, control
.
, dragging
Draglcon, design runtime .
:
End Sub
, Source control,
11 ... Then ... Else TypeOf.
DragOver, ( control) ,
' control, ( ) :
--
Private Su b Fo rmLDr a g Ov er (S o urce As Contro l, As Si n g le , As Single ,
1 23 - - - - - - - - -- - - - - - -
State As Integer)
End Sub
State control.
control, ,
:
c ont ro l .D ragMode
Drag, :
contro l . Dr ag 1
DragDrop, 2,
:
contro l .D r ag 2
Drag.
, command button .
MouseDown, MouseUp DragDrop.
DragX DragY, control,
MouseDown. Drag,
MouseUp:
DefInt -
DragY =
End Sub
command button l
. .
Drag.Vbp '
drag-and-drop. drive , dragging
Image control. , ,
, , .txt
--
NOTEPAD.EXE . .
1 24
.. Dra.g ond Drop I!lIiIEJ
18 ., J cal IIog.tt
t]: D:\
..
L] -wps _Ip
cardfile.ex e
cardfile.hl
. 7.2. Drag.Vbp.
drive list box, directory list box l list box controls,
. .
Drag .Frm:
Shell Yla ~o . Yla
(bitmap . . .), \Jll Image.
txt ., , ,
, FileName
temp ~ Ri ght $ ( f i l e l . filename , 3)
If Mid(file l.Path, Len(fi lel. Path = ~ \" Then
dropf ile filel .Path & f i l e l . f i l e n ame
Else
dropfile f i l e l . Pa t h & ~ \" & f ile l. f ile n ame
End I f
--
' control
1 25 - - - - - - -- - - - - - - -
im agel.Picture = LoadPicture ( "")
dragging 1
' . .
Sele ct Case Lc a s e $ ( t e mp )
Case "txt"
= She ll ("Notepad " + dropfile . 1)
Case "bmp" , "wmf" . "rle ", "ic o "
i ma g e l . Pi c t u r e = LoadPicture(dropfile )
Case "e xe"
= Sh e l l ( drop fi l e, 1)
Case "hlp"
= Shell ( " Wi n He l p " + dropfi l e , 1)
Case Else
msg "T ry one of t hese file t y p e s : "
msg vbCrLf + msg + vbCrLf + v b Cr Lf + " . tx t , .bmp, .exe, . hlp "
MsgBo x msg
End Select
End Sub
State DragOver 1 3 1 .
1 1 1 1
t a rget 1 1 , 1
1 10 1 1 2
1 a 1 0 .
, 1 0 Image control,
1 target , 1 10,
control n
design .
--
End Sub
1 26
J "
VisuaI Basic
, , cantraI , ,
. MousePointer :
, .
,
:
(Defautl). .
1 (Anow).
2 (cross-hair poin!er).
3 I-Beam .
4 .
11 (Hourglass).
12 ,
13 .
14 .
99 Mouselcon.
Screen, .
11 ( ) , 1
, :
Fo r = Sc aleWidth St e p 50
\ 1 1 1
End Sub
13 ,
, ; .
, DoEvents,
, custom control.
, Mouselcon ,
MousePointer 99. :
--
- - -- - - - - - - - -- - - 127 - - -- - - - -- - - -- - -
object.Mouselcon = p ict ure
auT u .CUR,
. (animated cursor).
DrAg d Drop
Visual Basic u u Drag & ,
, ' u controls
. Visual Baslc 5.0, u u
L Drag & Dro , u . u
u OLE, u C/C+ +.
Word ,
, Excel u u .
Source application
u Target .
, l;} UJjd
L Drag and u 9 ,
u u u.
OLEDropMode control
(largel).
OLEOrag L Drag and
.
OLECompleleDrag
Drag andDrop.
OLEDragDrop control
OLEDrapMode .
OLEDragOver con-
trol OLEDropMode .
- - - -- - - - - - - - - - -
--
128 - - - - - - -- - - - - - - -
L
,
Drag Source L
,
Drop Target
VbOleDragManual .
VbOleDropautomatic control / .
VbOleDropManual control ,i .
VbOleDropNone - .
- - - - - - - - - -- - -- -
--
129 - - - - - - - - - -- - - - -
target
' .
OLEl>rfjgOver
OLEDropMode, OLEOragOver
target, . :
Private Sub Forrn-OLEDragOver(Data As Da t aObj e c t , Ef f e ct As Long, Button As
Int e g e r , Sh ift As rnteger, As Single, As Single , State As I nteger)
,
GetFormal. , DataDbject
Effect :
VbDropEfteclMove yiVEl .
VbDropEfteclScroil
.
, Shift,
. State :
OLEl>rfjgl>rop
target,
OLEDragDrop. GetData,
. :
Effect OLEDropEffects.
, Shift, ,
OLEDragOver.
dragdrop.vbp textbox control , image control
o pto buttons controls ( 7.4.). Image Stretch
True, Multiline textbox control.
--
1 30
lIIri foIm1 I!!I[!]E'J
rNone
DRAG DD
MicrO$Ol!: Visu31 Ba,oc
noI >..rlOOtptI
Drag t.
,.
DragMode . Draglcon
'({'- DragDrop
DragOer , : (lIJTt.. ..
&~~c .. _
. 7.4. dragdrop.
u i ;
Option Explicit
Private m-effect As Long
Private Sub Form-OLEDragDrop(Data As DataObject, Effect As Long,
Button As Integer, Shift As Integer, As Single, As Single)
I f Da t a. Ge t Fo r ma t ( v b CFTe x t ) Then
Print "Text "
Textl.Text = Data.GetData(vbCFText)
ElseI f Data.GetFormat(vbCFBitmap) Th e n
Pr int "Bitmap"
Set Imagel.Picture = Data.GetData(vbCFBitmap )
ElseIf Data.GetFormat(vbCFMetafi le ) Th en
P rint "Metafi le"
Set Imagel.Pictu re = Data .GetData ( vbCFMetafi le)
Else If Data.GetFormat (vbCFRTF ) Then
Print "R ich Te x t Format"
End If
End Sub
m-effect = vbDropEffectNone
--
End Sub
1 31
, ,
WordPad . , Textbox Image con-
trol. Microsoft Windows Paint L Drag and Drop.
:
L
Orag and Drop, OLEDrag,
MouseDown source control. :
Priv ate Sub Fo r.m-MouseDo wn (B utton As Inte g e r , Sh ift As I n t e g e r,
As Sing le , As Singl e)
Forml .0LEDrag
End Sub
OLEStartDrug
OLEDrag source
control , OLEStartDrag, :
End Sub
,
Data, DataObject.
, AllowedEffecls
L Dragand .
OLEDropEffects. :
Pr iva te Sub Fo r rn-OLEStartDra g (Data As Da t a Obj e c t , Al lowedE ffects As Long )
All owe dEffect s = vbDr o pEf f ectCopy And v bDropEffectMove
End Sub
DataObject
Clear, files, GetDala, Gelformat SetData,
.
Clear DataObject /
Files u VBFilesFormat.
GetData nou u Clipboard U /
OataObject.
GetFormat DataObject.
SetData DataObject.
OLEStartDrag, o~oo
SetDala, . :
--
End Sub
1 32
vbCFBitmap,
vbCFDib, vbCFiles, vbCFMetafiles, vbCFEMetafiles, vbCFPalette, vbCFRtf, vbCFLink vbCFText,
.
VbCfRtl (.RTf).
VbCfText ( .) .
Pri vat e Sub Forrn-OLESt a rtDr a g (Da t a As Da t aObj ect , AllowedE f f ects As Long)
Al lowedE ffect s = vbDropEffectCopy
Da t a . SetData Te xtl .Te xt, v b CFTe xt
End Sub
OLESetDctc
target,
, .. .
, (Delayed rendering),
(rendering) ,
:
Pr i v a te Sub Form-OLE St a rtD rag (Data As Dat a Obj e ct , Al l owe dEffe cts As Lo ng )
Al lowedEffe ct s = vbDr o pEffectC opy And v bDropE ff ectMove
Data. Set Da ta. vhCFText And VbcfBitmap And v b c fMet afi l e And vbc f RTF
End Sub
, ,
. larget -
OLESetData, SetData,
--
.
1 33
Pr ivate Sub Form-OLESetDat a (Data As DataObj ect , DataFormat As Int ege r )
Select Case Dat aFo rmat
Case vbCFText
SetData (Re qu e s t e d da t a here ] , Da t a Fo rmat
Case vbCFRTF
SetData (Requested data h ere] , DataFormat
Case v b CFMeta f i l e
SetData (Requested data here ] , DataFormat
Case v bCFBitmap
Set Data (Requested data here] , DataForm at
End Select
End Sub
OLEGLvefeedfiuck
Drag and
L
target,
. , Effecl Defau ~Cursors.
Effecl vbDropEffecl
Defau~Cu rsors Windows
. False
Mousepointer.
Effect = vbDropEffectCopy
End Sub
OLEC.ornpletel)rug
OLECompleteDrag .
Effect, source
, ..
(vbDropEffecIMove) .
End !
End Sub
, a Explore r Windows
End !
End Sub
--
1 34
, Data.Files
DataObject.
Count .
110m .
CIoar .
Remove .
, OLEDropMode
1 - Manual. , , Windows Explorer,
, .
text boxes controls
Windows 95, '
box contral, menu (Cut, Capy ..) .
MauseDown teX box,
default , Menu1 :
cantrol Windows
MouseDown. PapUpMenu,
.
--
1 35
"Tag Tips"
Tag.Vbp
tag tips controls . ' ' label control
AutoSize True. tag controls
MouseMove :
PutTag :
MouseMove :
Private Sub Fo rm-MouseMov e(Button As Integer, Shi f t As Intege r , As
Sing l e , As Single )
Labell.Visible = Fa l s e
End Sub
Circle.Vbp
(,) , :
* + * <= r * r
, ,
(0,0), :
. :
--
1 36
mRadius (ScaleWidth / 2) ~ 30
End I f
,
Forml I!lOOf3
_vp sup .eKe
- - ufile.tmp ac csIal.eJle
- u phreg.da t alarm.ini
32k.cmeO.d ll
ac ce ssor_gp
accsaee
acroIead.in
aC fosch.ini
ag ility. ni
alarm .ini
ald lea rn.d ll ~~
ap iload _ini ..:.J
. 7.5. Droplist.
Droplist. Frm:
Deflnt -
--
1 37
Fil el .Dra g 1
End Sub
con\rols
Dragdrp controls
. command button controls
, (Vislble = ) . [ ,
.
. Paren\ con-
trols ( - ) .
.. Forml 1!!I~f3
! Butlon 1
Buto"
lon 2
Bulon 3
B ulOll ..
. 7.6. controls 2 .
Dragform.Frm:
De f l nt -
l KQl
Load, l 4 l controls
Commandl, KOl l ll .
, l
Move . , Sc reen.Width \ 2
--
1 38
F orm2 . Sh o w
Comrnand 1 (0 ). Top =
Command1( 0 ).Left = 1 0 0
Fo r i % = 1 4
Load Comrna nd1 (i %)
Comrna n dl (i %).Le f t = Comrna n d1( i % - 1 ) . Left
Comman d l ( i %).To p = Cornmand1(i % - 1 ) . +
Cornman d1( i % - l).He i g h t
Comrnand1 (i %) .Capti on ~Button " + Str$ ( i %)
Command1 ( i %) . Vi sible = - 1
drap-and -drop 1
Comma n d 1 ( i %).DragMod e = 1
Ne x t i %
Comma n d 1 (O ) . Ca p t ion = ~Butt on Ow
Comrna nd1 ( O) . Vi s i b l e = -1
Comma nd1 (O ) . Dr agMode = 1
End Sub
c ont r o l .
1 1. 1 .
1 Dr opfo rm.F rm :
1 1 1 10
1 1 comman d b utto n s 11
Vis i ble =
P r i v a t e Sub F orm-Lo a d ()
Move Sc r e e n . Wi dth \ 2 . , Sc r e e n . Wi dth \ 2
~
139
~
Command1( O) . Visible
For i % = 1 4
Load Cornmand 1 ( i% )
Commandl (i %) .Top = Command1{i% - l ). +
Commandl (i % - l) .Heig ht
Command l( i% ) .Visible =
Next i %
End Sub
, ~
1. Visua/Basic;
2. MouseMove.
3.
Drag & Dro;
Drag & D.
5. Drag & D.
6. ;
;
--
1 40 - - - - -- - -- - - - - --
2. ,
text bo control. '
, .
. control .
5. ' . ,
, .
--
1 41
( ..) ,
(keyboard). , controls
:
KeyDown .
KeyPress . ASCII.
KeyUp .
-
. ,: : : ~ ; : : : ' : -
18~ 1 ' " ' ' " ' . : Ii It 9 ... w ;:'
~
, t, ,
_
"" ' ' ' ' " ' ' ' : : "',
.-t..rfb . . ... - +
,~
:J - " t + ...
control (focus), ,
, controls (disabled).
controls KeyPreview True,
.
KeyPress ( ) :
--
1~3 - - - - - - - - - - - - - - -
KeyAscii ASCII
, CTRL
, Enter Backspace.
KeyAscii , :
KeyAscii default
controls, ,
text box:
Pr ivate Sub Text L-e yP re s s (Ke yAscii As Intege r )
Ch a r $ = Chr$ (KeyAs c i i)
KeyAs cii = As c( UCas e$( Char$))
End Sub
KeyDown KeyUp
( ) ( control) (focus).
:
Pr ivat e Sub F o rm-e y D own ( Ke y Code As Int e g er, Sh ift As Int ege r )
--
, .... - - - - -- - - - -- -- - - -
,
Case vbKeyFl: MsgBox . "
,
Case vbKeyF2: MsgBox F2 . "
Case vbKeyF3: MsgBox F3. "
,
Case vbKeyF4: MsgBox . F4. "
End Select
End Sub
, F2,
SHIFT, CT R text bo cantral.
Private Sub et-eDwn (KeyCode As Integer, Shift As Integer)
Dim ShiftDown, AltDown, CtrlDown, Txt
, Shift
ShiftDown = (Shift And vbShiftMask) >
End !
End Sub
--
1 45
- (
tet boxes controls ( )
, CAPS LOCK, KeyPreview
True KeyPress :
End I f
End Sub
l teX boxes
tetboxes controls
Enter. , controls Insert.
, tet boxes Enter
Insert. , InsertMode. tet boxes
controls, Index .
KeyDown KeyPress:
DefInt -
Dim I n s e r t Mo de As Intege r
- - -_ - - - - -- - - - -
--
146 - - - - - - - - - - - -- -
,-------------------...dft
r~
, . ~ =iI't
, SelLength ' text box ( combo box) ~l::~
(selected), SelText - .....
.
AutoRedraw True
AutoSize True
BorderStyle -
DrawMode 6-lnvert
,
DrawMode 6,
. Picbutn.Frm, ,
4 bitmap KeyDown, , MouseDown MouseUp,
DblClick. L .
~ ~ ENTER SPACE Vl Q
V l El K6v a
l ENTER SPACE 1
Click 1
button.
--
I f KeyCode = 1 3 Or KeyCode = vbKeySpa ce Then
1 47
P i c t u r e l . Line ( , O) - ( Pictu r e l . Width , Pi c ture l . He ight) , , BF
PictureLCl i c k
End !
End Sub
, ', , , , ,
:
. & .
. Edit
, : ; -
. Tab, Enter. ,
lnsert.
3. captIon
(ASCII). Shift CI1 .
4. .
. , "
. Backspace.
m
;
5. ,
.
. , .
. Backspace, .
--
, 048
-
coJItrofs...
controls, text box command
button control, events . Visual Basic
, , '
controls. cantrols (custom controls ) OCX.
Visual Basic, text box command
button control, controls.
controls .
coTItrols
controls Visual Basic.
fn.lTJJe
Framecontrol controls,
.
frame controls
. , frame
.
, controls
Framecontrol. CTRL con-
trols .
Caption. Run time - ,
' , :
--
events , Click DblClick.
1 49 - - - - - - - - - -- - - - -
iIII Forml I!I[ilEJ
F'l!le1
:. ao
, caption Framecontrol,
Static:
Pr ivate Sub Commandl-C1i c k ()
Static 8 0 0 1 As Integer
If 8 0 0 1 Then
Frame l . Capti on = "True"
Els e
Fr ame .Cap t ion = "Fa lse"
End I f
End Sub
Lobef
Label control
, textbox control. '
Caption, control Frame.
control.
- - - - - - - - - - - - - - -
-
.-
150 - - - - - -- - - - -- - - -
Alignment 3 :
- Left Justify ( )
1 - Right Justify ( )
2 - Center ( )
AutoSize rue . False control
, (caption) '
Label control:
Pr i vate Sub Form-Load ()
Dim Authorl . Quotel As String
Opttonbutton
button button, (
(group) ' .
Alignment button
( 9.3.). , Caption ,
, Value, design .
Tnue False, button ,
, Click.
. 9.3. 1 butlons .
. 9.4., group
9 buttons. ,
control ,
. , (Index) , 8.
- events. DblClick button
. :
--
End Sub
1 51
r -
.... I"st~.
OPTlONS EJ
n 30ption
11
. 9.4. 9 buttons, .
button "Ok" ,
:
End Sub
CheckBox
control button, .
button controls .
P' ~~~
r:.Check2
. 9.5. checkbol controls. l, '
CheckBox (default ) .
1 CheckBox .
2 CheckBox ( Grayed).
--
1 52
, , Click (
Run lime .
HstBo x
LislBox control ComboBox
m
conlrol, .
..
NewOrleMls ~
,
SI'IFrllci$CO
COC"9Q
S eltle :...
oorl o ::.J
. 9.6. , box .
Irol' Columns lisl box (scrolls) .
liSI box ( . 9.6), ,
Iisl box / ,
(. 9.7.).
F;:'kIbof.Idb
_khs.1db
n<ti h t . mdb
eIolIL'xl
pe rIo rm.txt
tfj1:r;;y; i_,ainbow.dib
~.:rnal. txt
ernaIxt ~Kng. anboW.b
!mainfrm .lrm packing .lst re.w me.txt
mamfrm.frm pasteJ.dib re adme.ixi
. 9.7 list box .
m Item, Listlndex
. ~em . read- wite Run - time
-1 lisl box ilem.
item, List.
, :
Li stl. List( O)
MuItiSelect item
(Multiple - Selecbon lisl box). :
--
1 53 - - - - - - - - - -- - - - -
(Default).
1 . click Spacebar items list box.
2 Shift + click Shift + items. C~ + cl i c k
.
Visual Oominus4.0 1
Yisual Dominus 4.02
. ,
f s u al Dominus4.0 4.
V s u al Dominus4.0 5
. ,
Sorted True, .
,
list box control.
Addltem ~em list box Run - time .
l:
--
1 54 - -- - - - - - - -------
CornboBox
Combo box control text box Iist box,
control. item text box
list box.
ListCount, List, Listlndex, Sorted, ItemData Newlndex,
Style combo box. ,
:
1 Simple Combo.
tet box list box, list box .
2 Dropdown List.
list box, .
IR~l
not No~
Chdrdonn~y _ - combobox (Slyle )
FumeBlanc
G ewi.zIr.!l mne
ZrJandel
J Chardnn.:'' J
Pin N or DropdoWfl kst ( S!yle 2)
,
Fme BI-!lnc
Gel'lirZra miner
Znfardel
, , Screen.
, . ActiveControl
controI events. ,
,
text box controI caption labeI controI .
P r i vate Sub Forrn-Click ()
If TypeOf Sc reen. Ac t i veCo ntro l I s TextBo xThen
La b el l .Caption Screen . ActiveCont rol . Text
El s e
La be ll. Capt i on "B ut ton: " + Screen. Activ eCon t rol. Ca p t i o n
End I f
End Sub
-
.-
155
ActiveForm events.
, captIon :
Private Sub CommandL-C lick ( )
Screen.ActiveForm.Capt i on = ~New Tit le"
End Sub
FontCount (fonts) ,
Fonts . list box
fonts :
Sub F o~Click ()
For = Screen.FontCount - 1
List l.Addl tem Screen.Fonts ( )
Next
End Sub
Fonts
~8 old N~.
..s Serif J
rIIalic
" J
S ize
-;
rUnde li"e
p ~I~!!~~
Demo
lr:J
. 9.10. .
Combo.Frm:
Deflnt -
, O X ~K cornbo b o x e s
Pr i v at e Sub Fo r ffi-Loa d ()
Dim i As Intege r
For i = 1 Screen.FontCount - 1
c omho l .Addltem S c r e e n . Fo n t s (i )
Next
combol . Listlndex =
--
1 56
comho2.Addltem "8.25"
comho2 .Addltem "9.75"
combo2 .Addltem " 12"
combo2 .Addltem " 13.5"
comho2 .Addltem "18"
combo2 .Addltem "20"
combo2.Addltem "24"
combo2 .List lndex =
check 1. Value = 1
End Sub
~ ~ ~ 6 n label contro l
Private Su b Checkl_Click ( )
l ab e l l 0. Font. Bold = che ckl.Value
End Sub
ScroH Bc r5
(Scroll Bars) controls HScrol18ar VScroII8ar
COX. ,
, .
vj multiline tet boxes list boxes controls,
--
, , .
1 57
.. FOfml I!!lOOI3
...
... '[j"
.. .. . .
. ..
Min m .
defaull .
Max .
defaulf 32767.
Value
min max.
Scroll .
scroll bar
' label control:
o~ Form-Load Scro l l Ba r
KQl ouvtXE1Q Di s pla y Da t e ~
Di splayDate
End Su b
e vent Ch a n g e ~ .
Di s p l a y Da t e .
--
Priv a t e Su b HScro l ll_ Change ()
1 58
DisplayDate
End Sub
~ VB Now Kal
n Scroll Bar cont ro l ,
. caption label
.
Forml I!lIiIEJ
:-. Sub
?= ~ va ~ e Sub hsbRed-Sc ro l l ()
DoColo r
:: Sub
~~ , event Change co nt ro l s
OL~iva Sc r ol l control.
--
::::: S:lb
1 59
Private Sub hsbGree~Cha nge ()
h s bGr e eILS c roll
End Sub
Pr i v a t e Sub DoColo r ()
t xtColo r . Ba c kColo r RGB( hsbRed. Value, hsbGreen. Value,
hsbBlue . Val ue)
End Sub
,
text box control . Move
controIs.
Priv a t e Sub Form-Lo a d ()
HSc rolll .Ma x 100 \ 1 1
End Sub
O.,ecIorylis I b OJ: -
Drtve H5t
drive Iist box controI Iist box (drop-down)
drive . , , drives
' .
--
. 9.14. drive Iislbox drives .
1 60
drive Drive, :
Dr i v e l .D rive = ~ C : \n
Change de .
Dtrectory Hst
directory list box control d rec t es () d e .
directory
sJex - 2
~c:\
!..J hc
O -dde
Doch
D,_ LsIrx:l -
D""",,,
D-
D ..... !J
. 9.15. directory listbox directories.
control ListCaunt, Listlndex List controls lisbox
combobox. 9.15., (
) Listlndex -1 .
,
-2 .
ListCount .
,
9.15., 7 (hc, ... ,winapi):
Privat e Sub Di r l-Cha ng e ()
Di m c n As Intege r
Cl s
For c n = d i r l . Li s t Count - 1
Pr i nt d ir l . Li st (cn )
Next
End Sub
' cl Change,
. Path,
. ' De cl, Ghange:
--
1 61
Private Sub Dr ivel-Change ()
d i r l . Pat h = dri ve l.D rive
End Sub
control ,
ChDir.
ChDir Di r l . Path
Hfe Hst
file list box control ' Path,
, design
.
Pattern
(extensIon), .FRM . BAS.
Fi le l . Pattern = "* . FRM; *. BAS"
' ,
SetAtlr.
' directory list box control, Change,
' Path file list box:
Privat e Sub Dir l_Change ()
f i l e l . Path = dir l .Path
--
End Sub
1 62
ListCount, Listlndex List.
' file list box control:
For i = Filel ist .Li stCount - 1
Print Fi le l i st. Lis t ( i )
Ne xt
Hrner
timer " " control, Run time
.
Timer.
lnteral , milliseconds (
) Timer. 65535.
( controlS) able , control.
lanm. b
alanm.
118:42:56 JI
AlJflll SeIIir : r AlwIII !
. 9.18. .
buttons timer, m
caption Iabel
text box , L.
:
, A o o ~ o 1 timer
Pr i v at e Sub Form-Load ()
timerl. Enabled = Fal s e
End Sub
- -- - - - - -- - - - -
--
16 3 - - - - -- - -- - -- -
t i me r , ~ o ( I ndex 1)
Im1l0e
Visual Basic controIs
,
GIF, JPEG, Bitmap, Icon MetafiIe.
ImagecontroI, controls, Picture,
design ,
LoadPicture, :
, Image controI , :
HJ'IItj , ;
--
. 9.19. .
1 64
Stretch,
True False
, control.
Image.vbp , icon
, click ' , timer.
check box,
Image.Frm:
Option Explici t
Dim I mg W
v i mage control
KQl v .
vQ v
KOl t i me r.
I ma g e l . Left =
I mg W = Imagel.Width
Timerl . Interval = 300
Ti me r l . Enabl e d False
, 6Xl i ma ge control
\ tirner
I f Not MovelconThen
Imagel .Move Imagel. Left + ImgW, Imagel .Top, ImgW * 2
Else
Imagel .Move Imagel. Left + ImgW, Imagel.Top, ImgW
End I f
Timerl.Enabled = False
--
1 65
End !
Move l con Not Move lcon
End Sub
image control
button toolbox.
image control
( down). image
Padlock ' LockOpen LockClosed, Load
:
Ptc:tureBox
control Picture ; image control,
, Line, Circle, PoInt, Print . . , .
, Circle '
pIcture box:
Pi c ture l .Auto Redraw = True
Pictu r e 1. Ci r cle (1200 . 10 0 0 ) r 750
AutoRedraw , pIcture
box .
, control , . ,
, image pIcture box control,
.
Picture,
" " pIcture box, . ,
Picture, '
ture box:
Di m obj Pi c As Pi c tu r e
Set ob j Pic = LoadP i ct ure (UButt e rfly.bmp" )
Se t Pict u r e1 .Picture = o bj Pi c
--
1 66 - - - - -- - - - - - - - - -
St11.e
Shape ,
, , . . , Circle, Line . .
Shape,
, Shape.Vbp, controls
Shape control .
. controls, time .
l Sha pe 11iI]
(' S he IO
8
('"Shape 11
r.:;; hape .~
r s h.e 13
r Stupe 14
r 5hae.5
, , button (index) .
, , Load control,
, , :
Fo r = 1 5
Load Optionl ( )
Ne x t
5 button, 1 . control
Load, Unload:
UnLo a d Opt ion l ( 3 )
,
' option button , . . 1 _Click.
Shape.Frm.
Option Ex pl ici t
n~o 5 op tion button
Optionl 1 16 1
. c a pt ion
1 Visible .
, 16
Fi l l Style Fi l l Co l o r , shape
--
1 67
Private Sub Form....Load ()
oim
End Sub
1 c on tro ls 1
Shape cont ro l
LJIe
, l ne control
, . 1, 1 ,
control, BorderWidth .
Line.vbp , line bmer
contral. ( click ) , line.
Line.Frm:
1 timer 1 1 n 1
\ .
Pr i v a t e Su b Fo rm-Lo a d ()
Timerl . I nterval = 1 0 0
Line1 . X1 100
Line1 . 1 10 0
Li ne 1. 2 500
Line1. 2 300
End Sub
--
1 68
Private Sub Timerl_T imer ()
St at ic Odd
If Odd Then
Linel . 2 Linel. 2 + 250
Linel .Y2 Linel . 2 + 600
Else
Linel . Linel.Xl + 250
Linel.Yl Linel.Yl + 600
End If
Odd "" Not Odd
ScaleHeight
, ScaleWidIh ( ) .
Dfj t fj -
conIrol, (MSAccess ) ,
. L control.
CU5torn ctrl5
Visuai Basic ( ) .
--
, Registry
1 69 - - - - -- - - - - - - - - - -
REGSVR ( REGSVR32), :
custOJJJ slJ1: GS C
custom controIs,
ViusaI Basic.
CommonDiaIog
CommonDiaIog controI, ,
, 5 .
:
,
.
Save n ,
caption .
Print
.
Color , .
Font , ; .
control , Act o n,
,
.
setting .
2 Save
3 Color
4 Fonl
5 Printer
6 WINHELP.EXE
--
1 70
DiaIogTitle, caption
titIe bar .
read, .
11.. .llHIl
i1
_!D1X. .,1
. - . . ~- .
.,... ....
..............
,
- . ... . - . .
- - - -
. ,
,"' "
_
.
0 . 0 .
, Dialogs.Vbp,
' CommonDialog control moduIe, Dialog s.Bas,
5 , control.
declaration module:
Deflnt -
Type FontProp
Fo ntName As String
FontSiz e As Single
Fo ntBold As Integ er
F o tl t a li c As !nteger
FontUnderLine As I ntege r
FontStrikeThru As I nt e g er
ForeCo lor As I nt e g e r
End Type
FontProp , module.
FiIeSelect Open, Action 1.
DefaultExt (etension) , . . .. FiIIer
Type . :
*., tet.
, ": " (ASCII 124) .
,
tet picture, bitmaps icons.
Text ( *. t x t ) 1*.txtIPictures (*.bmp; * . ico) I*.bmp; * . ico
171
-
.-
FileSelect, , , path$,
( *.), titie$,
. :
v a IJEJ
Filej)le: [olde : 0<
111; c:\ vb4
add,ettb. E;j c :\
U ol.bp
bbIio. 1db
biblo. mdb
.,:,) hc
bright. dib D include
dataag .ece ZJ odbc fl.e ad onIy
dosecp. zp CJ repot
11 aia dal
. 9.22. la Open.
FileSave .
ShowSave, Flags cdIOFNCreatePrompt
--
cdlOFNOverwritePrompt. -
1 72
.
,
(ov erwrte) . 10
.
Else
d i alog s . CMD i alog l . Filter ~ * . W + path$ + Chr$ ( 124 )
End I f
dialogs. CMDial ogl.Flags = cdl OFNCreatePr ompt Or cdlOFNOverwritePrompt
di alogs.CMD i alogl.ShowSave
ChDr i ve dire$
f i l e s ave = di alog s . CMDi a log l . File name
Ex it Func t ion
e ndl :
f i les ave = : ChDrive dire$ : Exit Func ti on
End Func t i on
--
e nd3 :
1 73 - - -- - - - - - - - - -- -
Ge tP r int e rlnfo = - 1: Exit Function
End Funct ion
:
ret = Ge t P r i n te r l n f o ( 1, 3, 5)
PrInt 1JE3
Pnl III: Default (lexmak QK
1 : )
nl range===~~==rr,
o~ :ietup...
r S~Il!!Ction
: fage;
. 9.23. Printer.
.i r r r r r;;i r r
. r r r r .D liiI &:I
.r:; rliiI . .i . 1iii
. r-
I!!!J .
t:u. ~"", colo .:
~~~~ fi~:~ B~
;;;r r.;; r;;i ffii
liliH II
\)~!~ ."."", ,,,,lnno > ColO1S!!lid : ~ BIye: [Q
odd Dmom CI<ii.
. 9.24. Color.
--
1 74
GetFontlnfo Font, ShowFonI.
FontProp
FontName. , !
. Gance[ button,
-1, .
GetFo nt l n fo r =
Exit Funct i o n
e nd5:
GetFontln f o - 1: Exit Func t ion
End Funct ion
Fonl 613 1
Fort .!e:
IR_ 0<
~
.=J
s_ .=J
$q:ipt
--
. 9.25. Font.
1 75 - - - - - - - - -- -- -- -
, ShowHelp WinHelp.Exe.
:
MSChart
MSChart control .
, , design
. MSChart control
.
. , ChartType
. MSChart control
DataGrid , ,
control .
100 100
-1
6ll +-- - - - - 6ll
40 - -' - 40
20 20
RI R2
'- r
R3 R. R5
. 9.26 . S C h a conlrol, .
DataGrid
, ColumnCount RowCount
. ColumnLabelCount RowLabelCount
labels , Column Row
DataGrid. The ColumnLabellndex RowLabellndex
labels. , ColumnLabel RowLabel
label .
, bar chart,
labels:
--
Dim columnCount As Integer
1 76 - - - - -- - - - -- - - - -
Dim Dat aGrid As DataG r id
With MSChart1.DataGrid
Da taGri d .
r owLa be l Co u n t = 2
columnLabelCount 2
rowCount = 6
columnCount = 6
' KOl 1abels
. SetS ize r owLabe l Co u n t, columnLabelCount,
rowCou nt , columnCou nt
'
RandomDataFill
' labels .
column = 1
ColumnLabe l (column, labellndex ) "Product 1"
column = 4
.ColumnLabel(column, labellndex) "Product 2"
row = 1
' labels
'
Fo r i = 1 UBound 3
For j = 1 3
(i , j ) = i * j
Next
Next
'
l abel s .
( 1, 2) "Wheat"
--
( 1, 3) = "Corn"
1 77
' labels .
( 2 , 1) "Januar y"
( 3, 1) = "Februa ry"
' .
MSChart1
' v a r i a nt .
= MSChart1
' ~
MSComm
MSGomm communication control
/ . m
, ; downloading uploading,
termina1.
,..--- - - - - - - - --,
rue
Flse
cornNone
,02.
. cornltMode ext
600
/JI'd FIse
BoiferSle 512
/JI'ityRelace ?
..""",
CornmCtrl.CornmPort 1
CommCtrl.Po rtOpen True
--
CommCt r l . Set t i ng s "192 0 0, , 8 , 1"
1 78
, , ll
.
,
' modem:
A~ 1 K6 10 1 0 .
MSComm l .CommPort = 1
, 96 00 baud, parity, 8 data, a nd 1 st op b i t .
MS Comm l .S e t tings = " 9 6 0 0, , ,l
, c o nt r o l 6 1 10 10
, .
MSComml . I nputLen =
\ .
MSComml . PortOp e n = True
\ . ( at t e ntion command ) mode~
, 1 V10 . 1
\ '''" .
00
DoEvents
Loop Unt i l MSComm l . InBuf fe rCount >= 2
Instring = MSComml. Input
, .
End Su b
--
17 9
Case vhMSCommEvReceive
Term inal Txt = CommCt rl. I nput
Curso rPos = Len(Termina lWi nd ow.Text)
Termina lWindow.SelStart " = Curso rPo s
' ~~ x 1 ~ BackSpace
End Sele ct
End Sub
--
( ) terminal.
1 80
SSTab
SSTab Diatog control tab control OptIons Microsoft Word
Excel. tab controIs. , tab,
Tabs tabs, Style
tabs, Word () property sheets
Windows 95 (1).
ConfIgure Anima
User lD
.. ~_ ..
PaUWOfd _
~
11'N ame '!'
.- --
...
Serv ers
Newr.
j
Inl ernet MJ
E-mail 1__
H e3de r. ;;:
11'
~ f;.dnCfJI !
Microsoft MaiI
(e-mail) Microsoft ( )
, e-mail Internet,
Fax . .
,
Mail Serers , MIcrosoft Mail, MicOsoft Exchange,
Novell's Group Wise, Lots cc:Mail . ,
controls,
MAPlsession MAPImessage. MAPlsession control
Microsoft Mail sere r. ,
. Signon
Signoff . :
MapiS ess.SignOn
! Er r <> Then
Ms gBo x ~H Logon 11 : ~ + Error$
Else
Map i Me s s . Se s s i onI D MapiSess. SessionID
--
End !
1 81
MAPlmessage
Mail serer. control :
Compose .
Copy ' .
Delete .
fetch .
Forward .
l .
Send .
MsgGount
Caption :
Screen.MousePointer = 11
MapiMess.Fetch
Caption = ulnbox - u + CStr(MapiMess.MsgCount) + U "
Screen. MousePointer =
FetchUnreadOnly True,
FelchSorled, .
,
listbox control (
MsgOrigOisplayName), ( MsgSubject)
( MsgDateReceived) . MsgRead
Msglndex:
Dim read As Boolean, As Integer
Listl. Clear
For i = mailctl.MsgCount - 1
mailct l .Msglndex = i : read = True: Mess$=""
If Not mailctl.MsgRead Then read = False: = + 1
a$ = Format$ (mailctl. MsgO r igD isplayName, "!" + String$ ( 1 0, "@")
If Not read Th e n
Mess$ "*" + " " + a$
Else
Mess$ a$
End I f
--
Ne xt i
1 82
Caption = ~ Y 6 xo ~ + CSt r ( X) + ~ 16
, 1 , 1 1 0 1
MapiSess . SignO f f
If Err <> Then
Ms g Box ~H Logo f f 1 1 : ~ + Er ror$
End If
StatusBar
StatusBarcontrol '
, StatusBar
Panel, Panels.
, panel
. Add
Panel, :
StatusBarl.Pane ls.Add
9.29 Style
Panel StatusBar.
, . Alignment,
Panel, Text, Panel, Key,
.. Panel.
"", fl.!I!J
!ei<l:
r.y Ii-- - -
_ 10 .....
~",,' 10.T'"
~eveI: 11 ' lf'lSeI ~
"""~. I~I
0< =>< 1 -
--
18 3
With Stat u s Ba r l .Pa ne l s
Item( l ). Sty l e : sbrDate
It em(l) .Ke y : -Date pane l-
I tem ( l ) . Au toS i ze : sbrConte n t s
Item(l) .MinWidth : 2 0 0 0
Item( 2) .Style : sbrTime
Item(2) .Key = "Time panel"
I t e m( 3) .Aut o S i ze : s b rContents
I tem(3 ). Te xt : "Miscellaneous Data"
Item(3 ).Key : " Pa n e l 3"
End With
End Sub
ProgressBar
Progress8ar control ,
.
@l
. 9.30. Prog ressBar contro .
Max,
control Value .
Slider
Slider control ,
, , .
II, ... ~
. 9.31 . SIider control.
Max. ,
SelectRange. .
Imagelist
Im ageL st control controls,
, listlmage.
--
1 84
Wi1J!1' 'ei,iit.i. 41. iHII:l
. 9.32. .
,
9.32, control, Add
Listlmages, ,
:
ImageList control:
Dim imgX As Lis tIrnage
, Extractlcon
bltmap ImageList controI. ,
M o use lco .
--
1 85
With Forml
. Mous elcon = p icX
. Mo u s e Po i n t e r = vbCustom
End With
End Sub
L stV iew
ListView control 4 ; .
, ,
. ' Listltem. View
ListView control, Large (standard) Icons,
Small lcons, List Report.
, Listltem ColumnHeader.
, '
ImageList control. Icons Smalllcons. ,
() SubItems. SortOrder
, Sorted
. ColumnHeader .
List.b , ListView ImageList controls.
ListView control View
combo box control.
11. _ l '
Ilcon J
, ColumnHeaders
Se t clmx Li s tVie wl . Col umnHeaders.
Add( , ''Author'' , Li s t Viewl. Wid th / 3)
Set c l mx ListViewl.Co lumnHeaders. _
Add( , " Title " , Listviewl. width / 3)
Se t c l mx List Viewl.Co lumnHeaders . _
Add( , "Publisher" , ListViewl . Wi d t h / 3)
view 11 6 Report.
Lis tViewl .View = lvwReport
, o OU ' 1 10
--
ImageList c ontro l .
1 86 - - - - - - - - - - -- - - - -
Dim imgX As Listlma g e
Se t i mgX = ImageListl.L istlmages. Add
(, , Lo adP i ctu r e ( " i c on s \ Wr i t i ng \ No t e 0 6. ." ) )
Se t im g X = I ma g eLis t 2 .Listlmag es . Add _
(, , LoadPictu r e ("bitmap s \assorted \ w.bmp"
With Combol
Addltem ''Ic o n ''
\ ~ Lis tltem ~K - .
, Author
Set itmX ListViewl . Li s t l t ems. _
Ad d ( , " " , 1)
Ti tl e
itmX. Sub l t e ms (l ) = " o ~ 1 6 1 Wi ndows"
, Pu bl isher
i t mX.Subl t e ms ( 2) = "Anubi s "
, 1
End Sub
RichTextBox
RichTextBox control textbox control . '
6 4 textbox.
RTF format, MSWord.
--
control ,
1 87
, ' , , ..
LoadFile SaveFile
RichTextBox control, :
oolbar
Toolbar control button.
. buttons
Add
~..ll fJ I
. 9.35. Too lbar control .
--
o ol b r . vb p, -
1 88 - - - - - -- - - - -- - --
RichTextBox control toolbar
WordPad.
'1
'''''' 1[iO -1"1l"i"E] !R..
cJs;loriZ'e 1oc1Ja 1 ReloeTooI>r
Gai a ::i
'{y g G qi q
6
,on
T @rm in o IIermino !
. li n@ l ,' "
- ' jo,: , ,y1r.
~
Hy erte)<l OuvWTO
Mlq umq oq ,,[ I! $ G a Io
, - .- ., _. ~
. 9.36. .
Dim bt nX As Button
--
\ butt ons
1 89
\ Add .
ComboBox control l l l
. but ton.
With Combol
.Width Toolbar l . Buttons("combol" ) . Width
. = To olba rl .Buttons("combol").Top
. Le f t = Toolbarl.Buttons ("combol") .Left
Addltem ''B lac k''
Addltem ''Blue''
Ad d l t e m "Red"
List Index =
End With
With Toolbarl
.Wrappab1e = True
. Al l owCu s t omi z e = Fa1se
-
.-
19 0
En d With
with CommonDialogl
. Defau ltExt = ~ . rtf"
. Fi l t e r = "RTF fi le ( *. RTF) I *. RTF "
End With
With Commandl
. Left = Toolbar 1.Buttons(2 ).Left
. = Toolbarl.Top + To olb a rl .He i g h t + 100
Width = 15 0 0
Height = 300
. Ca p t i o n = " Cu s t omi ze Toolba r"
End With
With Cornmand2
. Left = Cornmand1.Left + Cornmandl.width + 50
. = Cornmand 1.Top
Width = 1500
Height = 300
.Caption = "Restore Too lbar"
En d With
, margin ll RichTextBox
, lQl control.
r ich t ext b ox l. Ri g h t Ma rgin = r ichtextbo xl.width
End Sub
--
To o l b a r l . Bu t t on s ( " r i g h t " ). Va l u e = tbrUnpressed
19 1
Toolbarl .Buttons( ~center" ) . Value tbrUnpressed
En d Select
Sel1talic ~~ , - 1, Null. ~
Mi xedState ~ ~ x~ ~ True.
Select Case richtextboxl.Sel1talic
Case \ Not italic.
Toolbar1.Buttons(~ i talic").Value tbrUnpressed
Case - 1 \ 1talic.
Toolbar1.Buttons(~italic"
) .Value tbrPressed
Case Else \ Mixed State.
Toolbarl.Buttons( ~italic" ).MixedState True
End Select
End Sub
o~o toolbar .
Case Is = ul eft"
richtextbox1. SelA1ignment rtfLeft
Case I s = ucenter"
richtextbox1 . Se lAlignment rtfCenter
Case Is = Uright"
--
richtextbox l. Se lAlignment r tfRight
1 92
Case I s = "bold"
If Button.MixedState True Then
But ton.MixedState Fa lse
End If
richtextbo xl . SelBold Abs(richtextboxl.SelBold) - 1
Case I s = "italic"
If Button.MixedState True Then
Button.MixedState False
End If
richtextboxl . SelItalic Abs (richtextboxl.Sel Italic) - 1
End Select
End Sub
Se l Colo r vbBlack
Case 1
SelCo lor vbBlue
Case 2
.SelColor vbRed
End Select
End With
richtextboxl.S etFocus
End Sub
TreeView
TreeView control n ,
File Manager. item - Node ( )
+ -, items,
--
(expanded) (collapsed) .
1 93
8 b oot
! '._. ! F' sISibling
:'0 Nc
i_ "' !! lasSiblirg
. b Parent
8 b U sQrIed
:- -[!) lsa
iII ot:) GeQ/f
gob SQfted
~Beth
:--- !! Drew
8 b S QfIedD escen&1ts
8 - f2: Ann
; '. !! Dave
[ ... [!) Sid
8 - b Pam
j- ffi) BiII
, !! GIenn
TreeView control,
:
! Node root .
Next Node .
Previous Node .
, bitmaps ,
TreeView control ' ImageList control. Style
control, ..
, '
TreeView control , Add. ,
, control.
Dim nodX As Node
Set nodX TreeView1.Nodes .Add( " "R", "Root" )
Set nodX T reeViewl.Nodes.Add ( ~R" , tvwChild, "Cl" , "Child 1 ")
Set nodX TreeViewl. Nodes.Add(~R", tvwChild, "C2","Child 2")
Set nodX T reeViewl.Nodes.Add (~R" , t vwCh i ld, "C3" , "Child 3" )
Set nodX TreeViewl.Nodes.Add(~R", tvwChild, "C4", "Child 4")
nodX.EnsureVisible
TreeViewl.Sty le = tvwTree l i nesText ' Style 4.
TreeViewl .BorderStyl e = vbFixedS ing le
End Sub
--
1 94
For i = 1 TreeVi ew l .Nodes. Count
strNodes = s trNodes & TreeView l .Nodes(i) . Ind e x & U &_
UKey: U & Treev iewl . No des ( i) . Key & U " & _
TabStrip
TabStrip controi SSTab Dialog control
,
, .
......
Animation
Animation control (silentAudioVideo lnterleaved)
(frames), . "
" folders, Windows 95. .AVI
\Graphics\AVI CD-ROM Visual Basic.
CURRENT.DOC
FIom 'JOBS'1o 'M yDOC1ATI!!I1!~'
. .l.I . ~ . ~ - II..9ri#UI
Animation control
. .AVI ,
Multimedia (MCI) control.
Dpen control, .AVI, Play
, , , Stop . , video
Close. .
, Animation control anmAVI,
CommandButton controls cmdPlay cmdStop CommonDialog control
dlgDpen:
Privat e Sub cmdPla y_ Click( )
l l ComrnonD ia l og c o nt r ol VlQ l
--
\ . av i VlQ l .
- - - - - - -- - - - - -- 195 - - - - - - -- - - - - - -
d l g Open. Filte r = ~A I ( *. avi) j *.avi n
d lgOpe n . ShowOpen
a nmAv i . Ope n d lgOpen.F ileN ame
a nmAVI . Pla y
End Sub
video:
Private S ub cmdS top_Click ( )
arunAVI . Stop
En d Sub
Play
(repeat, start stop) ,
, frame m.
repeat, .AVI .
1 , frame (
frame ) :
arunAVI. P l a y 1 0, 5, 15
Muftimedia
Multimedia control Media Controllntertace (MCI), ,
sequencers, CO-ROM drives, audio players, videodisc pIayers, videotape recorders players. control
, m MCI
compact disc player.
,
, Next, Play, Pause, Back, Step, Stop, Record Eject.
Multimedia control.
cdaudio CD player .
daI player
sequencer .mid D sequencer.
C Vd e ota pe recorder player.
video . ai video.
videodisc Videodisc player.
waveaudio .wav WavefOl . n J p .
Command control
MCI Win32 , Play, MCI,
CL.
,
--
Command control m C.
196 - - - -- - - -- - - -- - - -
MCI
Stap CS MCI.
Back MCI STEP tracks.
Step MCI STEP tracks.
Prev MCI SEEK track Seek.
Seek MCI SEEK track.
Record CRCRD MCI.
EjecI MCI SET CD-RDM.
Save MCI SAVE .
, Multimedia control
:
n 1 6n Not i fy Tr u e , Done
n - MCI.
MMControll .Not ify = False
\ 1 6 n Wait n
0 n MCI .
MMControll. Wa it = Tru e
\ n Sh a r e a b le 0 MCI
, .
, ,
, :
Microsoft FlexGrid
control Visual Basic 5.0 FlexGrid
. Grid control, ,
, ,
( ) . , bound control,
MS Access ( ) .
FlexGrid, , ,
--
.
1 97
, (cell) Fl eG rid control
. Row Col , '
Text.
' , WordWrap True,
.
ColWidth RowHeght ,
. controI Cols
Rows.
FixedCols FixedRow,
(default 1 ) FleG ri d control.
(scrolling) control .
CellAlignment '
, ColAlignment , FixedAlignment
.
FleGrid
control
, CellFontName, CellFontSize, CellFontBold, CellFontltalic, CellFontStrikeThrough,
CellFontUnderline CelJFontWidth, CellBackColor CellForeCoJor
. CellBackColor
. ' BackColorFi ed . , ,
BackColorBkg BackCoIorSel .
.. Fo m1 I!!lIiIEJ
Produt!
1. Wahoos
1. W ahoos
3. Foobars
4. Applets
I ~ An nIPI"l._<:'> I'If?/1
' . Grid.Vbp
ReG ri d control Load
:
, 06 . . 1. .
, . . .
, FlexGrid c ontrol.
MSF l exGridl.BackColorBkg = vbGr een
MSFlexGridl.BackColorFixed = vbCy an
MSFle xGr i d l. Bac kColo r Se l = vbBlue
- - - - - - - - - -- - - - -
--
1 9 8 - -- - - - - - - - -- - - -
\ O ~ 6 V1Q headers ( 1 K a ) .
\ ~ .
MSFlex Gr idl.Row
o x~ .
\ help 0 .
.
' mj :
--
1 99 - - - - - - - - - - - - - - -
:
FlexGrid control ,
.
Sorl,
MergeCells. , ,
MergeCells
MergeRowO MergeColO True .
, MergeCells.
IlexMergeNever (DefaU t) .
tlexMergeFree 1 .
flexMergeRestr ictRows 2 .
tlexMergeResfrictColumns 3 .
flexMergeRest rictBoth 4 .
, .
, ,
' .
Merge.Vbp FlexGrid control
. , , FormalSlring,
, ,
.
( : ). '
! <, , > ,
' , .
TextArray, :
obj e ct.Text Array (cellinde x ) [= s t r i ng ]
--
cellindex -
2 00 - -- - -- - - - - - - - - -
Cols .
cellindex :
MouseRow MouseCol,
. , ColPosition
twips control
.
,
. (dragging) :
\ Fl exGri d control
Pr i v a t e Sub Form-Load{)
Dim As I nt eger
Fgl. Cols = .4
Fg l .Rows = 20
Fgl . Me r geCe l l s = 2
Fg l .F i x edCo l s =
For = 1 Fg l . RowS - 1
, .
, . inn.
Fg l . MergeCol(O ) True
Fgl . Me r g e Co l (l) True
Fgl .MergeCol(2) True
, T ~ .
DoSort
End Sub
, X~ o o ~ ~ TextArray ~~.
--
Fgl . Co l Sel = Fgl. Co l s - 1
2 01
Fg1. Sort 1
End Sub
\ o ~ y ~ FlexGr id .
Func tion Ra nd omString( kind As I nte ge r)
Dim s As St ring
Se lec t Ca se k i nd
Ca se \ Reg i on.
Select Cas e (Rnd * 1000 ) Mo d 5
Case : 5 - ~ 1 . "
Case 1: s = ~2 . ~~"
Case 2: s ~3 . "
Ca s e 3: s = "4. ;"
Cas e El se: s = "5. "
End Select
Cas e 1 \ Pr o d uc t .
Sele c t Case ( Rnd * 10 0 0) Mod 5
Ca s e : s = "1. Domi n u s "
Ca s e 1: s = " 2. Ta ngr am"
Ca s e 2: s = ~ 3 . VB 5 . "
Case Else: s = ~ 4 . TgReport"
End Se l ect
Cas e 2 \ Employee.
Select Ca se (Rnd * 1 000 ) Mod 4
Case : s " "
Case 1: s = ~ N Ko"
Case 2: s = ~"
Case El se: s = ""
End Select
End Sele ct
Rand omString = 5
End Function
l ~ Tag ~~6 yl Q K ~ ~ 6
l ~o ~ l.
Fg1.Tag = \\"
If Fgl.MouseRow <> Then Ex it Sub
Fgl. Ta g = St r ( Fgl. MouseCo l )
Mo u seP oin t e r = vbS i zeWE
End Sub
\ o ~ oo~ ~ . l
As Single )
Mo u sePoin te r = vbDe fault
I f Fg l . Tag ~ " Th e n Exit Sub
--
Fg l. Redraw = Fal s e
2 02
Fgl . ColPosition( Val( Fgl. Tag Fg l .Mo useCol
Do So r t
Fg l .Redraw = True
End Sub
"'"
l,Avo le~o J-t
C!'o
4, 1 gRe/1 N,;Q
2. am (;n
I(.;,o ~o"
1. O<Wine t:::.~
1. .: -~
fb>Ji\Q<;
4, 1 e , t:::~o"
2.1"4f\9laII1 ~~a-",
item ,
index .
, tab (vbTab) .
Removeltem Clear
FlexGrid control. :
Dim i
MS Fl e x Grid l .Col s = 2 .
For i = 1 100
MSFlexGrid1.AddI t em ~E ntry ~ & v bTab & i .
Next
Fo r i = 1 50
MSFlexGridl .RemoveItem i . .
Next
MSFlexGridl .C lear K ~ c ont r ol.
ColSel RowSel
.
.
Spread.vbp , FlexGrid textbox
control spreadsheet .
, CellHeight, CellWidth,
CellLeft CellTop, twips.
- - - - - -- - -- -- - - -
-
.-
203 - -- - - - - - - - - - - --
M.,j
,,
1
5
'33' noo ,;..j
,,
7
~~
12
__~~~-t~=~---=~::=-
~_ _ ---+------ +---- I-- _~_~ ~ .
"" -~+-
"
16
, .
Fg2.ColWidth (O ) = Fg2.ColWidth(O) 2
Fg2.Co lAl ignment(O) = 1
Ne x t
For i = Fg2 .FixedCol s Fg2.Cols - 1
Fg2 . TextAr ray(Fgi(O , i ) ) = Chr$(Asc(''A" ) ~ 1 + i )
Next
txtEdit
End Sub
\ l l space ( )
Private Sub Fg2-DblClick ( )
MSFlexGridEdit Fg2 , t xtEdit, 32
End Sub
\ . textbox control.
Private Sub Fg2-GotFocus ( )
If txtEdit . Visible = False Then Ex it Sub
Fg2 = txtEdit
t xtEdit .Visible = False
End Sub
, . t e xtb o x c o nt r ol.
Private Sub Fg2-eress(escii
--
As I n t e g e r )
2 04
MSFlexGridEdit Fg2 , txtEdit, KeyAscii
En d Sub
\ X ~ oo~1 TextArray ~~
Funct i on Fgi(r As Integer, c As I nt e g e r) As Integer
Fgi = c + Fg2.Cols * r
End Fu nct ion
, 1 textbox control 1
Sub MSFlexGridEdit (MSFlexGrid As Control, Edt As Control, KeyAscii As I n t e g e r)
\ .
Selec t Case KeyAscii
\ ~ text.
Case 32
Ed t.Te xt = MSFl exGrld
Edt . Se l St art = 10 0 0
r 1Q 1 V 1 K text.
Case El s e
Edt = Chr(KeyAs cii)
Edt.SelStart = 1
End Select
\ t e xtbox control .
Ed t.Move MSFlex Gr i d.Cel lLe f t + 120 , MSFlexGr i d . CellTop + 120 ,
MSFle x Gr id. Ce l l Widt h , MSF l exGr i d . Cel l He i g h t
Ed t . Vi sible = Tr u e
\ 1 .
Ed t. Set Fo c u s
End Sub
, 1 beep Ente r .
Privat e Sub t xtEdit-eyPres s(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii =
End Sub
\ 1 o~ ESC ..
Su b Edit Ke y Code ( MSFlexGr i d As Contro l , Ed t As Contro l , Key Co d e As Intege r ,
Sh ift As Int e g e r )
Select Case KeyC o de
Ca s e 27 ' ESC: text K~ 10 MSFlexGr id
Edt. Visible = False
--
MSFlexGrid. Se t Fo cus
2 05
Case 13 ' ENTER av l ~o ~o MSFlexGrid.
MSFl exGrid. SetFocus
Cas e 38 ' .
MSF l e xGrid. SetFocus
DoEvents
If MSFlexGrid.Row > MS FlexGrid. FixedRows Then
MSFlexGrid.Row = MSFlexGrid.Row - 1
End If
Case 4 ' ,
MSFlexGrid. SetFocus
DoEvents
If MSFlexGrid.Row < MSFlexGrid.Rows - 1 Then
MSF1e xGr id.Row = MSFlexGrid.Row + 1
End If
End Se le c t
End Sub
(scrolling) bitmap
Scrollp.vbp ,
, (scrolling) bitmap
; .
Scrollp.Frm:
--
206
event Resize Ka~ 6~ ~6~.
10 ~ 1 s cro l l ba r s
picture control.
1 1 scrollbars
End Sub
11 Pict ure.Left 1 .
--
2 07
_ Q
11 ~xl
. 9.46. list box controls.
Def l nt -
1 list box e s
1 1 1 1 tlmer
Pr l va t e Sub Fo rm-Load ( )
For i = 1 26
lis tl.Addlt em ~Visual Ba s i c 4.0 ~ + Chr $ (i + 64 )
Next i
Fo r i = 1 26
list 2. Add l t e m ~ Vi sual Ba s i c 4. 0 ~ + Ch r$ (i + 64 )
Next i
Ti merl. I nt e r va l = 1
Time r l . En a ble d = Tr ue
End Sub
event timer.
list box.
item Listl
TopIndeX-Listl = list l .TopIndex
x ~ a~
I f TopIndeX-List l <> PrevTL-List l Then
item lis t bo x
1 1 0
~ ( scro l l i ng)
K~ ~ l i s t bo x
lis t 2.TopI ndex = TopI ndeX-Listl
PrevTI-Li stl = Top IndeX-Listl
End If
\ ~o ~ o item 1 list bo xe s
If listl. ListIndex <> list 2. Lis t Inde x The n
--
list2.ListIndex list l . ListIndex
2 0_
End If
End Sub
, '
P riva t e Su b Comrnandl-Click ( )
End
En d Su b
Iistbox control checkbox
listbox Visual Basic
checkbox. '
ListView control, Chklst.Vbp.
ListView ImageList control. ImageList
check Listview control. General tab
ImageList control '16 16'.
:
' KnO~
'1istview c o n tro l
For i = 1 10
Addltem " Listltem " & i
Next i
o ~ ~o
'1istvie w c ont r o l u n chec ked
Sub Addltem (itm As St ring )
Di m i t mX As Li s tlt e m
Dim i As Integer
' i c on unchecked
i t mx. Sma lll con =
itmx.Text ; i t m
End Su b
- - - - - - -- - - - -- --
--
209 - -- -- - -- - - - -- - -
'
En d If
End With
End Sub
11
L!iHem 1
&g,.;mil+
~C l is\lIem3
: lstl Iem 4
Cic l islHem5
t lisl Iem 6
l isllIem 7
to Li~U lem )
lisl l em 9
L.isIIIem10
Match.Vbp DirWalk, , " "
controls FileListBox File1 DirListBbox 1 ,
, ' .
D , .DLL
C:\Windows ' listbox control:
ReDim sArray (O ) As String
Screen.MousePointer = 11
Call DirWalk ("* . DLL; *. OCX", " : \windows" , sArray)
Screen.MousePointer = 1
For i = UBound (sArray )
List1.Addltem sArray(i)
Next
wildcards
, (;). :
--
2 10
Sub DirWa lk(ByVal sPatte rn As Str i ng , ByVa l Cur r Di r As String,
s Found( ) As St r i ng )
Di m i As Intege r, sCurrPath As String
Dim sFile As St r i ng, i i As I nt e ge r
Dim iFiles As Integer, iLen As Integer
If Right $( CurrDir, 1 ) <> " \" Then
Dir1.Path Cu r r Di r & " \"
Els e
Di r1.Path = CurrDir
End I f
Fo r i = Dir1.ListCount
If Di r 1.Li s t (i ) <> " " Then
DoEvents
Cal l Di rWalk(sPattern, Dir1.List(i) , sF ound(
Els e
I f Right$(Dir1.Path, 1 ) = " \ Then
s CurrPath Left (Dir1.Path, Len( Dir1.Pa th) - 1)
Else
sCur r Path = Dir1.Path
End I f
File l .Path = s CurrPath
Fi lel .Patter = s Pa t t e r n
File 1. Li st ( i i )
Next ii
End If
iLen = L eD ir.ath )
Whil e Mid (Dirl . Pa t h, i Le n, 1 ) <> " \"
i Le n = iLen - 1
Loop
Di r l . Pa t h = Mid( Dir1.Pa th, 1, iLen )
End If
Next i
End Sub
--
2 11
1. Iistbox controI .
, , cap-
tion .
2. controIs .
, , , controls
ListView control . ListVew control
control .
contro.
3. FiIeSeIect$,
CommonDialog con-
(DpenShow ) . ,
file system controIs. ' , text box
, IabeI command buttons controIs ( CanceI).
4. . timercontroI,
Line controI .
5. Spread.Vbp, '
button .
MSChalicontrol button,
,
. bar chali.
6.
Windows Explorer. '
controIs. TreeView control ListView conto.
TreeView contro! drives . ' ,
controI , ListView con-
trol icon (
controIs). , Shell.
- - - - - - - - - - -- - - - 2 12
--
~1/
:a..,.....
~
Visual Basic
. . . Clipboard,
. ,
, . . " "
, Windows , DDE OLE,
" " .
.
CIbfl"d
Visual Basic
, Clipboard. ,
, , Clipboard.
SetText GetText,
. SetText Clipboard, , .
:
Clipboard.SetText da ta [ , fo rmat ]
GetText ,
Clipboard , :
, Clear Clipboard .
controls, text boxes combo boxes controls,
, . ,
Clipboard, cut-and-
paste. , time ,
--
:
- - - - - - - - - -- - - - 213 - - -- - - - - - -- - - -
SelText .
Clipboard,
Copy, Cut Paste.
,
text box (Iocus) , ActiveControl
Screen. , control:
Screen.Act iveCont ro l
.
control text box.
Sub Cop y_Click ( )
Clipboard.Clear
Clipboard.SetText Screen.ActiveControl.SelText
End Sub
Sub Cut_Click ( )
Cl i pb o a r d. Clear
Cl ipboa rd. SetText Sc reen.Act iveControl. Se l Te x t
Screen.Ac t i veControl . SelTex t=""
End Sub
Clipboard , ,
, . ' GetData,
SetData GetFormat, ,
, . SetData Clipboard
. :
--
214 --------------~
Clipboard form.t
vbCFBi1m.p 2 Bnm.p ( . ). def.u~
, Clipboard.
Cl i pboa r d. Set Da ta Lo a dPi c t ure ("PAPER. " )
GetData Clipboard. ,
10 Picture Image control:
Irnagel .Picture = Cl i pboard Get Da t a ( )
, GetFanmat
Clipboard. :
Clipboard.GetFormat ( f ormat)
format ; .
Clipbo.r d form.t
vbC FLink &HBFOO ; DDE.
vbC FText 1
vbCFBilm.p 2 Bllm.p (. )
Sub Form-Clic k ()
Dim ClpFnt , Msg
Case 2, 4, 6
Msg = ~ Clipbo a rd ~ x ~ bitmap. n
--
2 15 - - - - - - - - - - - - - - - -
Case 3. 5. 7
Msg = ~ T O Cl i pbo ar d ~ x~ K~ bitmap. W
Case Else
Msg = ~To Clipbo ar d ~x ~ .
End Select
MsgBox Msg
End Sub
(D D )
Windows. Clipboard
" " " " , ,
. DD , , ,
(background).
.
spreadsheet
Microsoft Ecel.
DDE
, DDE.
destInatIon, source.
Visual Basic 1.0 client sere r.
- destination ( destination) DD ,
.
- source .
19 , ,
- source ( source)
, . , ,
. , ,
, , ,
,
. tems '
.
DDE
DD source ,
. ,
Microsoft.
- - -- - - -- -- -- --
--
216 - -- - - - - - - -- ---
, tapIc .
(document) topIc, Excel, ,
.xLS . XLC Word .OOC . . topic
"System",
.
Items System :
Ilem
5ysltems items Systemtopic, .
opi c s topics / / .
51atus .
Formats Clipboard .
item.
, Excel item (. . RIC1), Word
(bookmark) . control Visual Basic destInatIon , 10 item
Ln kltem , source ,
text boxes, labels pictures i1ems.
(Iink) .
, source destInatIon,
.
Automatic link
source (items) destInatIon, ( hot link
1. ) .
ManuaI Ink
source destInatIon , 10 ( cold link
1.0 ) .
l1y link
source destination ,
destgn
Visual Basic
design time. ,
, . ,
. destination ,
:
(source) .
@! source, Item Edit Menu (
) Copy.
@) VB, control (text , label pIcture)
.
--
Edit Menu Visual Basic, Paste Lnk.
- - - - - -- - - - - - - - - 217
' , control
. automaticlink time .
source ,
design . LinkMode 1-Source.
applicat ionltop ic
source topic
" " ( ASCI1124). , spreadsheet Ec el :
EXCEL IC:\EXCEL\SHEETl .XLS
R2C3
, item ,
, LinkMode . 4 , 0-
None, , 1-Automatic, 2-Manual 3 -f.
, Visual Basic .
1-Automatic, (items)
, control Change.
Link_ltem , AutomatIc Excel .
LinkMode vbLinkNone, . control,
, t box label. Excel ,
.
Ro w = Ro w + 1
I f Row = 1 Then
Cont rol. LinkMode = vbLinkNone
Cont ro l.LinkTopic = ~ Ex celISheetl"
--
End Sub
- - - - - - - - -- - - -- - 2 1 8 - - -- - - - - - - - - - - -
LinkMode 2-Manual, , control
. ,
, LinkRequest.
, control
LinkRequest, spreadsheet Excel:
Priate Sub Lin k-I tem ( Con t r o! As Cont r ol )
If Contro l . LinkMode = vbLinkNo ne Then
Cont ro l . Li n kTopic = "Exce l ISheet l"
Control .L inkltem = "RI C1" ' It e m
Cont rol.L i nkMode = vbLinkManu a l
Cont rol. LinkReques t , c ont r o!
Els e
! Contro ! .Linkltem "RICl" The n
Contro l .Linkltem "R2 c l "
Cont rol. LinkRe qu est c o nt r o !
Else
Contro! .Linkltem = "RIC l"
Cont r o l . Lin kRe q ue s t , c ont r o l
End I f
End I f
End Sub
, !
, ,
Shell.
S ub St a r tapp ( Control As Co n tro l, App Name $ , To p i c $ , Mode % )
Const DDE-NO-APP = 283
S tartUp:
I f Er r = D D -- Then
i = Shell(AppNarne)
Re surne
El s e
Ms gBox Erro r $
End
End If
En d Sub
[ LinkMode 3- , 2-
Manual,
--
LinkNotify. ,
, DD , source desti-
nation. LinkPoke, destination
source, . :
Textl . Li nkMode =
W
Te xtl .Li nkTopic = - Exce l l Sheet l
W
Textl .Link l tem = -R2C3
Text l . Li nkMode = 2
Text l. Text = ~New alue w
Textl .LinkPoke
Textl. LinkMode =
DDE,
linkExecute. , . ,
, worksheet Excei.
Te xt l . Li nkExe c ut e ~[FI LE.C LO S E ( ) ] "
.
DD Excel, worksheet
:
nl0y Exce l
cmd C V ' & Q &"SHEETl" & Q & 'j]"
cmd = Cmd & '[SELECT t' & Q & ' Rl Cl : R5C2 " & Q & 'j ]"
Cmd = cmd & '[NEWt2 , ) ] [ARRANGE. ALL t) J "
End I f
lQ LinkPo ke ,
--
Fo r = 1 5
2 20 - - - - - - - - - - - -- - - -
Row =:
Text l .Linkltem =: ~Rn & Row & ~C l n
Te xtl.Text = Chr(64 + )
Te xtl.LinkPo ke
Te xtl .Link l tem =: ~ R " & Ro w & C2 "
Textl .Text = Row
Te xtl. LinkPo ke
Next
, destination, source .
, . LinkTopic
topic,
application (
project, Visual Basic).
Items controls (text boxes, lables bitmaps). ,
, source , LinkMode
1-Source.
DDE, LinkNotify.
, :
Li n k r , DDE.
LinkExecute s o U ce , destination
.
ArJAY
,
Visual Basic Copy Paste Link Edit menu.
.
Paste Link, destination
Clipboard .
, GetText Clipboard
( ) , vbCFLink(&HBFOO).
, :
Link$ = Cl ipboard.GetText(vbCFLink)
--
Link$ :
- - - - - - - - - -- - - - - - 221
applicationltopic !item
I f Clipboard.GetFormat(vbCFLink) Then
\ M~ DD
Ed If
,
' menu Paste Link mnuEPaste.
, ,
control , :
M~K D ~ items
Sc r e en.ActiveControl.LinkMode = vbLinkNone
Screen.ActiveContro l. LinkTopic = Link
Scre en.ActiveContro l . Li n k l t e m
Screen.ActiveControl.LinkMode = vbLinkAutomatic
End 1f
End Sub
Clipboard
. ,
Click
mnuEdit menubar. Clipboard
mnuEPaste.
--
End Sub
222
Copy ,
source , Clipboard,
:
application ,
App.EXEName, topic LinkTopic , , item,
Tag control .
mnuECopy :
Clipboard.Clear
If TypeOf Screen.ActiveControl 18 PictureBox Then
AppTopName = App . EXEName & "" & LinkTopic
AppTopName = App TopName & " !" & Sc reen.ActiveContro l .Tag
Cl i pb o a r d . SetText AppTopName, vbCFLink
Cl ipboard. SetText Screen. ActiveCont rol .Pictu re
E!self Ty p eO f Screen.ActiveContro l 18 Te xtBox Then
AppTopName = App.EXEName & " " & Li nkTopi c
AppT opNarne = AppTopName & " ! " & S c reen. Ac t i v e Co nt r Ql . Ta g
Clipboa rd. SetTe xt AppTopName, vbCFLink
Clipboard.Se tText Sc reen.ActiveCont rol.Text
Else
Clipboard.SetText 8creen.Act iveContro l
End If
End Sub
CreateGroup group.
DeleleGroup group.
ShowGroup i group.
Reload group.
Addllem item .
Deletellem item.
Replacellem item.
ExitProgman Program Manager.
--
2 23
group item:
[ C r e a t e Gr o up ( ~ Wi ndo w s Appl icat ions")]
[ S h owG r o up ( ~ MY GRO UP .GRP", 1)]
[Add l t e m(wi na pp . e x e , wi n App ,winapp.ex e ,2 ) ]
Program Manager,
'l catn " "Topic" , PRDGMAN. ,
Program Manager, groups items,
CF_. item group,
carriage return
. group ( ) ,
group , items .
' items.
Contrlpm.Vbp
Program Manager " " groups items. ,
groups .
!tk:e Ir Qe1ete
~~:,z
.4PfGPlA
J
~:::,,~I?
V'$u41 0 <1$18 .. (1 6-b!]
l4uli,medi<t 0011
MFC S anpJes ( ~
Microsolt
MicrosoIt l C....
QuIc"Pak ProIessio nal 4.0
, l c 4.0
MulIimeda V ie we r 2_0 ::
E"plo, e MultImedia 5 e,i e:
PacilI c ech
Aolloay 6 uId
Int eInet ,gr<mmng
Defl nt -
--
2 24
t e xt l . Li nkExecute ~[Addlt em (NOTE PAD .EXE setup.t xt . Re a d me ) ] n
\ ~ list box x~
~ K i t e ms ~ x ~ .
Private Su b Command2-Click()
\ n1 l i s t box 1
groups x~ .
~ li s t bo x group s
Ca l l f l11 1 lstbox
End Sub
CR (1 3) . u x ~ Li s t b o x contro l .
Pr i v a t e Sub fi l l li s t box()
225
--
Text$ = textl.Text
length = Len (Text$)
ReDim x$(length)
listl. Clear
For i = 1 length
dumY$ = Mid$ (Text$, i, 1)
If dumY$ = vbCr Then
i = i + 1
a = a + 1
End If
x$(a) = x$(a) + dumY$
Next i
Fo r i = 1 a
x$(i) ~ Mid$(x$li), 2, Len(x$(i - 1)
l i s t l . Add l t e m x$ (i) -
Next i
listl .Listlndex =
End Sub
textl control , 1 DD 1
Program Manager
Private SubForrn-Load()
textl .Visible = False
End Sub
Jj e!p
~ objett{s)
--
spreadsheet ! , -
2 26 ------------~~--
, ..
=
FoImT
D
,
,
.- "" 1
~
,,,
CIu.<m ."
~
1
1 Pk/tl>!'l' k
"" ~
HJ
!
.,,,,,,,,, ,., Ci:;lt.'I
- .,m-
" ~
,,
2 1
Ektm"....,,
" 600 2 1
. 10.3. Excel.
Insert Obje ct 13
B ,lma I mge
Cr cle Oocumenl
r Ceate from EIe:
I nde ~ C"rd
Inlernel Oo.meI ( L
MeofuCip
Miuosoll Excel (l ~ IlyM Ic:on
M CoroH Excel c',,,
.:h
;::;
,, ' _ _..:cJ
:;.
. 10.4. .
--
. , L control
2 27
, '
. DispIayType control
, SizeMode l
.
". , . # l l $ "
joul otE :.:J
-1'"--,1
-.-.
....,
,
.",
,."""""'"
-"
...""'.....
AutoAdivte
,~
:: """"""'"
.."...
, -
r~~~~ - Fed Snje
.=J
t<fi eloj
D<lt4Sc:u, e
sp!yTypoo
Drl,1! CQ(I ....,
,,.""""
0- content
~-
....., "W
'" .:J
"""
'Class
'~sets tIwtdtss lWI'Ie ." efbedded
,
control, menu ( - ) ,
OLE. Insert Objecl.... Insen Object, Delete
Embedded Objecl Objecl.
Paste Special... (Paste Special dialog)
Clipboard . , Clipboard
Copy
, .
( ) time
. , control, ,
Load :
OLE l . Ac t ion =
End Sub
, Paintbrush:
Pr ivate Sub c omma ndl_ Cl i c k ()
OLEl . Cl a s s = "PBr u s h "
OLEl . Sour ce Doc = "c: \ wi ndows\ar c he s . bmp"
Source l tem ~ Pa i nt b r u s h ~l
\ v - ~x l 2 y2 n
.-
22 8
-
OLE1.Sourceltem = ~o 121 159"
OLE1.0LETypeAllowed =
OLE1.0LETypeAllowed =
OLE1. Action = 1
End Sub
Action time
, .
embedded.
Class, OleTypeAllawed ( 1 ) Sourceltem.
1 l ked. 01eTypeAllowed ( 2 )
SourceDoc, Sourceltem, .
6
L contro).
7 L . Verb,
L .
AutoAclivaIe 2 (Doub!e-Click), L control .
9 .
embedded .
10 . -
.
11
FileNumber. linked,
, .
embedded , control .
12 : SaveToFile.
FileNumber
14 Insert Object.
.
15 Paste Special. -
Clipboard.
17 verbs Verbs -
. , u verbs "edit" "play."
ObjecIVerbs ObjeclVerbsCounI , Verb :::: 1
, Verb :::: 2 .
18 .
--
2 29
OIe.Vbp, , .
,
Copy, Cut, Paste Paste SpeciaI,
verbs . OIe. Frm mod-
uIes. ' , OIe2mod1.Bas .
. V C/ipboard .
2. n ;
3.
;
4. n 11em ;
5. ;
6. LinkMode.
7. LinkRequesl LinkPoke;
8. n L ;
9. L conlro/.
destination source
Automatic lnk. textbox controI.
saurce , contraI destinatIan.
--------------~
--
230 - -- - - - - -- - - - - - -
DfJtfJ Cortror
. . , BtrIeve, dBase, FoxPro, Paradox OOBC,
. data control, ,
, . , .
Data Crl ,
(DataAccess Objects).
Data Control controls (bound controIs) , text box
. controls
. data control,
,
.
0llt (Tables), (Rows)
(Columns) Excel Lotus 1-2-3.
, (records) (fields)
, ' . 11 .1 .
4 ( ) 6 ( ) .
IE ~~~~~~_~-==;~~--.;;;] t~~!~t
,
--
. 11.1 . .
- - - - -- - - - -- - - - - 231
, , . .
, , .
,
.
,
. ,
.
(primary key)
.
,
.
, ( , ,
) . SQL (Structured Ouery Language)
' . ; (queries)
.
11 .1. SOL
" " " " " " :
"SELECT , FROM
() .
Data C.oJJtrol
data control
Visual Basic, BIBLlO.MDB.
!
. 11.2. data control toolbox .
contro! toolbox, , F. ,
. , '
DalaBaseName '' data control. ,
.
,
RecordSource, (
11 .3.).
t boxes ,
. control, check boxes, pictures
boxes, image controls, labels, DBList, DBCombo DBGrid MSFlexGrid,
(bound contro!s). bound controls data control,
, DataSource, .
data contro!s, '
--
. bound control () . -
- -- - - -- - -- - - - - - 232 - - - - -- - -- - -- - --
DataField,
.
1f t.;. 4- #'.tb
IDat~I " :J
- I~I
..oJ
"""""" ...."".,..
=: .
""",,k~
""
_)
--'0
=:-0
F'"
. C>efd:
0 - No t
'0-.. .
ecordsetType
F~se-
Oynlls!'t
.
RM#To.eft AoA!'S
.,
""",,",
ooIT.pText "."""
'"'
Al Tt~
:!
C-
RecwdSOtJce
}<e.ms(sets the ~ ta:le, SQL
. 11.3. (Table).
. 11.4. .
, - data control,
, ~, .
text boxes button data control, Visual Basic
. m
, . .
df t. -
data control,
design run time .
Gonnect
,
Microsoft Access.
- - -- - - - - - - -- -
--
233 - - -- - - - - -- ---
DaIabaseName
,
.
ser er ,
.
Exclusive
True,
, .
, , Refresh,
.
Recordset OpIiOnS
, data control ' ,
Recordset, Recordsel.
, :
.
OpIiOnS
.
dbDenyWnle 1 " u u .
dbDenyRead 2 " u u .
dbReadOnly 3 u .
, ,
"tiUes":
Dat a l .Da t aba s e Name = ~BIBLI O.MDB W
ReadOnIy
,
, ReadOnly True.
Rec:ordSource
data C I' , query
--
Microsoft Access , , SOL query.
- -- - - - - - - -- - - - - - 234
, , SQL
:
Data l. Refre sh
; Recordset
' .
RE!c:ordsE!t
' , data
control, Recordset,
SQL query.
Recordset data contro.
.
data control ,
. ' command button
Recordset Addnew, :
da ta l.Re co rdset.AddNew
.
:
. .
. index ( U) .
. .
. (Iacked).
, Delete.
.
. button
:
--
, , :
2 35 - -- - - - - - - - -----
[formname. ] datactrl. recordset.MoveFirst
[formname. ]datactrl. recordset.MoveLast
[ f ormname. ]datactr l.recordset.MoveNext
[ f ormname. ]datactr l . recordset.MovePrevious
, , ,
bound controls .
, , BOF EOF,
:
( recordset)
, .
, Publishers ' "
. Refresh data control
.
Data l.Refre sh
,
' , BoakMark ,
Variant StrIng. ,
, ' :
Field
Recordset FieId,
. Field
Recordset Fields. ,
Value ' .
.
. , .
--
" ":
- - - -- - - - - - - - -- - 236
F$ = Dat al. Rec o rdset. Fi e l d s (O).Value '
, :
.
, , "Invalid Use NULL". ,
, "Name" , :
Assign .
Variant " .
Caunt,
Recordset. list box
:
Fo r i = to Da t a l . Re co r d s e t . Fi e lds. Cou nt - 1
Li s t l .Addl tem Dat al .Recor ds e t .F ie l ds ( i )
Next
,
bound controls:
Dat a l . Dat aba seName nBIBLIO. MDB"
Datal . Reco rdSou rce = nTi t l e s "
Dat a l .Refresh
, n ~oo .
Oata l .AddNe w
, ~ o ~x
--
=
2 37
, ~ ~ l ~l .
Datal .Update
, recordset .
Dat a l. Recordset. Close
' ( ) .
:
, l
Datal.Up da t e
\ recordset
Dat a l .Re cor d s e t. Clo s e
~ l Vla :
M~oo
.
FindFirst, FindLast, FindNexl FindPrevious, :
criteria .
, NoMalch, :
False
.
, 6
--
2 38
Datal .Reco r d set .Fi ndFi rst Cr i t eria
B1K~
~ ~~K ~
,
Edit, :
, ' .
,
:
, K1~o
, En ~
v dutu coJJtror
data control, DrapDrop, DragOver, MouseDown, MouseDown
MouseUp, , .
data control. :
DataErr Response
' , Open,
DatabaseName control:
- - -- - - - - - - - - -
--
239 - - - -- - - - - - - - -
Pri vate Sub Data l-Er r or ( Da t a Erro r As I nt e g e r . Response As Inte g e r )
Select Case Da t a Er ro r
Cas e 3 0 2 4 ' n
CMD i alog l .Action l ' 1 1 0 16 Ope n
End Se l e c t
End Sub
Reposition
. :
data control
.
. ,
list box :
Declaratio n s
1 1 r ecordset.
Data l.Refresh
While Not Datal .Recordset.EOF
pn
Data l . Re f r e s h
l~ n field text box .
--
2 40
~ xo list box.
For = Listl.ListCount - 1
Exit For
End If
Next
End Sub
Valida\e
, Upda\e (
Upda\eRecord ) , , Dele\e, Unload
Close . :
Ac\ion ,
.
vbOalaAclionCancel .
vbDataActionMoveFirst 1 MoveFirst.
vbDataActionMovePrevious 2 MovePrevious.
vb O alaAclio nM ove N eX 3 M ove N eX.
vbDataActionMoveLast 4 MoveLast.
vbOalaAclIonAddNew 5 AddNew.
vbOalaAclIonUpdate 6 Updale ( UpdaleRecord).
vbDataActionDelete 7 Oelele.
vbOalaAclIonFInd 8 Find.
vbOataAclIonBookmark 9 Bookmark.
vbDataActionClose 10 Close.
vbDataActionUnload 11 .
Ac\ion,
, . Save
bound conlrols ( True/False) . True,
Edi\ UpdateRecord.
bound controls, bound controls.
DataChanged bound controls , True,
.
, _I
, Text1 control:
Private Sub Datal_Validate (Action As Integer . Save As Integer)
, ~ x o l l
--
I f Textl.DataChanged Th e n
- - - - - - - - - - - - - - - - 2 .. 1
Ms gBox ~ 10 ~."
nn .
End Sub
UpdateControls
bound controls. :
bound controls
, '
,
KeyPreview True:
Private Sub Forffi-eyOown ( Key Code As 1nteger, Shift As Integer)
Const KEY-ESCAPE = &HIB
UpdateRecord
bound controls .
:
datactrl .UpdateRecord
bound
controls Validate,
. Edit,
Update, .
TrGIJJ sGIctLOJJS
Transaction ' recordset,
. ,
transaction, . transactIon,
.
:
, transaction
,
,
-
.-
242
.
. transaction
, ,
transacfton .
, . Visual Basic
transactIons. BeginTrans, transactIon, GommitTrans,
transaction , , RollBack,
transaction. Transactions,
Transactions recordset True .
Bound ,l5
bound controIs, ' data control
.
controls (Label, TextBox, CheckBox, ComboBox), controls (Image, PictureBox),
(advanced)controls (DBList, DBCombo) , , Bound Grid (DBGrid) MSFlexGrid.
controls data control DataField DataSource. con-
trols DBList DBCombo " " ,
Addltem, ListBox ComboBox
controls. . :
RourceSource
Datacontrol bound
control. run time .
ListField
bound control .
, BoundGolumn .
BoundGoJumn
bound control ,
control. ,
BoundTex1
BoundText
BoundColumn.
MatchEntry
bound control.
RourceSource design
. . m
DBList OBCombo ;
data control. ,
RecordSource datacontrol Refresh.
ListField bound control,
runtime. , .
- - - - - -- - - - -- - - -
-
.-
243
ListField,
.
. RecordSource datacon-
trol. , SOL,
, :
Data l .Reco rdS ou rce = ~ S e lect [PUDID]& String ( 5, 32 ) & {Name] W &
~As I DNarne. PB~D , Name. Address From Publis he r s "
Datal.Re fresh
DBList l .ListF ield = ~ IDName
,
,..
~ -....cn:& ~_~
y_PtiNd ISBN FtIO
~o~_
~l s
.; ~tL~{:~i:f- -~~::!:
-}~;~
~ ~_!o ~ S_QL <I~d_: . j-= ~tt=g:i- _s, .;.."
~2,-.
H tc/H.e ", GUd: VBSO . 1~--~96i242i~ _~7,~
~=~:g:.~ ~~~~i- _ ~7
"~
~~ ~~~'5-5 "53--:'::
~11"Z..~.~ -~::
~~t47I sj~~
}~+-~t- _.t.9";.
Maed~"
An
M sa .. ...
Ad>,orcedY..... B'O: ' .
oo.:I;n to .-.
~
i!i9"o.aiI6082~
jgg;~W.1f5;j_~ --.:~~
9'31Tj:2IJ~ _ - ""
+..
1 ~..!2Oi~ '}~~,~}--- _~L-
An~ to<U:oNse
~~
1"['"'-- "-."...
.... ~~'!.?-:.'!~ .-:r..
lLlI o. , iI!!J
--
. , data control
2 .... - - - - - -- - - - -- - -- -
Refresh DBGrid control, :
. DBGrid control,
design
Properlies. , , Columns property
sheet ( 11.6). '
.
" ..
, :
, 0
Pr i v ate Su b Fo rffi-Load( )
--
Datal.Databa s eName = App. Pa t h + " \ o r ganize r.mdb"
- - -- - - - - - - - - - - 2 <15 - - - - - - - - - - - - - -
Datal.Reco rdsetType 1
End Sub
\ a
Di m Q As String
Dim src As String
Di m c riteria As String
Dim CurrentRcd As Variant
Q ~ Ch r $ ( 3 4 )
CurrectRcd = Da t a l. Recordset. Bookmark
src = InputBox$ (" . " , "Find ")
--
Private Sub Command5_C lick()
2 46
Er ro r GoTo e r ro rHandl e r
e r r o r Ha nd ler:
MsgBox Error
Exit Sub
End Sub
, ~o
''''''''
JII:wooi "'l 1
O".m~
; 6 ~ ' p ~
....., ...
6~ .. _ qit i"",
47 !18 ~
_7, 23
-.. .. ,....
/-'"
...
1...- -~ -~
T~
14663'19
","""",
..,
"'"
Ipo:edn@Ico.I g
--.:::J ~ B
~ ~ --=:!J
m; .1
IHI4/D;/II;/I1
. 11.7. Orgaaizer.Vbp.
--
2 47
1. ; ;
2. Tr data contro/;
3. Tr data cantro/ '
;
4. data controI.
5. bound contro/s; .
6. Recordset; .
7. Recordset ;
.
2. . '
controls , D
time .
- - - - -- - - - - -- -
--
- - 24 8 - - - - - -- -- -- - -- -
, (Database)
" ,
, Excel.
,
; .
, .
. ,
.
, , .. , ,
. . . ,
.
, ,
,
:
.
@! .
@) .
,
C lm nl ,
,
, , , . . .
Rw s/ ( recod) , ..,
(fields) (, , ) -
. , -
.
Re l a n sh / / . ~LK
- , ,
.
--
2 ... 9 - - - - - - - - -- - - - - - -
Database/ , .
/ , , '
, .
Index/ ,
.
,
, .
, , .
, , , , . .
.
,
.
,
. , ,
.
: , , , Fax, , , , , , . .
,
.
. ,
. ,
, ' , .
Fax
--
. , ;
2 50 - -- - - - -- -- - - ---
Access .
, .. , , .
, .
, ,
, , .
.
(keys).
(primary key),
.
primary key
, .
simple key ( ,
- composite key - ( ,
(atternate keys), , .
, primary key ,
.
, bytes
.
, ' ,
primary key, Autonumber.
, ,
.
OrdersTable
Custom ers Table Qrder!D
?ustomerlD CustomerlD
fm;.ign ~ij: ;,
CompanyName OrderOaIe
ConIactNam RequiredO ate
ConlactTi!le EmployeelD
Address Ship e:lD ate
city
RegiOn
Posta!Cooe
( lJJdexes )
,
( ) . ,
,
--
, Indexed :
-~-------------- 251
Yes (Duplicates )
Yes ( Duplicates)
,
(table
sca) ,
, .
,
. ' ,
,
.
:
,
.
(Gompact), .
DAO
Exterl1ill Dutubil5e5
ISAM (Indexed Se q uetial Access Method) ,
, Btrieve, dBASE 111, dBASE IV, Microsoft FoxPro 2.0 2.5, Paradox 3 .
4.0. Visual Basic (text
files) (worksheets) Microsoft Excel Lotus 1-2-3.
ODBC Dutubil5e5
--
c liet-server, ODBG stadard , Microsoft saL
2 52 - - - - -- - - - - - - -- -
Server. ODBCDirect mode D ODBC
, Jet. , Remote Data Objects (RDO)
Remote Data control (RDC), EnterprIse Visual Basic,
ODBC.
D ,
. ,
DBEngine .
, ,
. Workspaces (
),
Workspace. Workspace Database.
Database TableDef ..
,
, ' (index) . , TableDef
Database MyDatabase, MyDatabase.TableDefs(O),
MyDatabase.TableDefs(1) . .
DBEnglne
l{ Workspace
Dat..base
L TableDef 1 QueryDef 1 RecordseI 1 Con!ainer J l RelaIi:lr
~ fie ld f ield 1 Fie!d 1 OocnenI 1 Fie!d
Index Parameter
Field
I)re,
lfGroup Legend
and collection
CJ Obje cl on'Y
User
""
--
2 53 - - - - - - - - - - - - - -
( ""
, . (dot).
l)
Jet (
D , ( , , indexes
(relations).
Database , TableDef Field .
:
Dim -
. , VK DBEngine default Workspace :
Database.
TableDef .
Field .
Index index .
:
tI CreateTableDef Database,
TableDef , :
~~~~~~~~~~~~~-
--
25 .. ~~~ ~ ~~~~~~~~~-
Set AuTd = My DB. CreateT able De f (~Auth or s " )
Set PubT d = My DB. C re ateTableDef(~P ub li shers W)
CreateReld TableDef,
Reld ; ( , . .) :
@ Append :
rl r ~ i YJdex '
indexes .
:
indexes , Createlndex
TableDef, :
Auldx.Primary = Tr ue
Auldx .Unique = True
@ index, CreateField
Index:
Set NewFld = Auldx. CreateFie ld ("Au-I D")
CreateField Index
TableDef Index. Type
and Size Index.
(refGItioYJ5)
(RefereYJtiGlf IYJtegritg)
TabIeDefs (keys) primary and foreign,
, ,
primary/foreign. , ,
, . ,
--
, foreign (valid)
f9 U - primary/foreign ,
CreateField Relation :
Dim TempField As Field
Set TempField = Au-Tit.CreateField ("Au-ID")
TempField.ForeignName = "Au-I D"
@) Append Field
Relalion Database.
Au-Tit.Fields .Append TempField
MyDb.Relations.Append Au-Tit
x~ vnv
D
, .
TableDef Field Index . ,
, index .
SQL,
U .
, :
,
TableDef TableDefs, :
Dim db As Database
Dim NewTd As TableDef ' n ~oo TableDef ~Ko.
Dim NewFld As Field \ n~ovo F ie l d li.
-
.-
25 6 - - - - -- - - - - - - - - - -
Se t NewFl d = NewTd.Creat e Fi e ld ( ~N ew Fie l d Name n , dblnteger)
flivaxa
, Delete TableDefs.
, indexes,
, ' .
Authors:
Db .Tab leDe f s .Delete ~Authorsn
f ' flivaxa
' ,
field Fields.
Address Phone Authors.
Dim Db As Databas e
Dim Td As Tab leDe f
Dim Fld As Field
j f
, ' TableDef.
, Index Relation objects.
Delete TableDef. indexed
Index . Relatian.
Se t Td Db . T ab l eDe f s ( ~Auth or s n)
~~~~~~~~~~~~~~-
--
257 -~~~~~~~~~~~~~-
Se t Ne wl dx = Td . Cr e a t e l nd e x ( UAdd r e s a-I nde x " )
Newldx.Unique = Fa lse
Set NewFld = Newl dx. Cr e a t eField (UAdd r e s s " )
IJJdex
index
. "Address_lndex" index
Indexes Authors:
Db .Table Defs (UAuthors " ) . Inde x e s.D e ! et e uAdd ress_I ndex"
Index Relation.
DAO
.
DAO.
De
DBEngine, ,
Workspace, .
DBEngine :
D BEngine
Wrk ace-
ErrOIS
. 12.3. DBEngine.
DefauItUser / DefaultPassword
User name Password " " MS
Access. Jet ,
User Password
Workspace.
IniPath
ISAM.DLL MS Access.
LoginTimeout
Jet
--
login ODBC.
- - - - - - - -- - - - - - - 258 - - - -- -- - -- - - -- -
Version
read-only m DBEngine .
m Jet, DBEngine
:
CompactDatabase
, RepaIrDatabase, .
CreateWorkspace
Workspace,
.
Workspace, Workspaces.
:
IdIe
. transactIon, ,
, CommitTrans m .
RegisterDatabase
ODBCdriver Registry Windows.
RepairDatabase
m MS Access.
--
25 9 - - - - - -- - - - - - - -- -
. Workspoc:e
Workspace
Oatabase.
, Workspace Oatabase, Users Groups.
OBE rg-<e
W'orkspaces
Workspace
, Workspace Workspace,
.
Workspace :
Name
Name Workspace.
Count
Count m Workspaces Workspace.
, Workspace.
Username Password
Workspace, password
.
Workspace .
--
2 60 - - - - - - - - - -- - - - -
As Re cordset
Prompt = ~ t it le Acc ount Exe cutive ?"
Set MyWo rkspa ce = Workspaces( O) , default Workspace .
, database.
Set MyDatabase = MyWorks pa ce .Op en Databas e (~ MYDB .MDB" )
, .
Set MyTable = MyDat aba s e . OpenRe c ordse t("Employ e e s ", dbOpenTable )
MyWo rk s pac e .BeginTrans , K~o p t ran s act ion.
MyTable.MoveFi r st
Until MyTable . EOF
Else
MyWo rkspace.Rollback ~ n
End If
MyTab le.Clo s e ' table .
MyDataba s e.Close
End Func tion
Close
Close Workspace Warkspace.
default Workspace, .
CreateDatabase
, ,
MS Access. :
databasename , locale
, (;
dbLangGreek ) , , , options
--
2 61
dbEncrypl ( encrypled ) .
database .
OpenOatabase
database. :
Se t da taba s e = wo r ks pa ce . OpenDa t a ba s e{ db name [, e x c l us i ve_
[, read-only [, source ] ] ] )
dbname , exclusive
, read-only
, , , source
OOBC .
Dut ubuse
database. :
Wok;p.'ICe
Dtab.uet
-
O Mab bIcO eI'$ A~"""
""""""
Q .-.le/ $
""""'"
. 12.5. m mv Database.
Oatabase :
CoIIatingOrder
read-only ,
locale CreaIeDaIabase,
. dbSortGreek (
Microsoft.Jet workspaces).
ConnecI
read-only options OpenDatabase.
--
2 62 - - - - - -- - - - - - -----:
Count
Database ] Database.
Name
read-only
QueryTimeout
Database
, query ODBG.
RecordsAffected
read-only (records)
Execute ..
Transactions
read-only TRUE FALSE, Database
transaction.
Updatable
read-only FALSE TRUE, Database
Version
read-only D
.
Database.
OpenRecordset
Recordset ] Recordsets.
" , Recordset
query () . :
ij variable, , Recordset.
, OpenRecordset.
--
2 63
, MYDB.MDB VKo
recordseI, .
--
26 4
Cre ateProperty
CreateProperty Database.
, Property (b ui ~-i n)
Database (user-defined).
Set v a r i a b l e = ob j ect .Crea t e Prope rty ([name [, t ype [, val ue [ , fDDL]JJ)
CreateQueryDef
CreateQueryDef
QueryDef,
. :
name
QueryDef, sqltext SQL
, QueryDef. , name '" .
Query, .
, QueryDef Pubs SQL
Recordset, Dynaset, query.
\ 1. 0 Quer y De f .
Set MyQue r y = MyDB. C r e at eQ u e r D e f ( ' Pubs H , "SELECT * FROM Publi shers ; " )
\ Re co r d s e t qu ery.
Set MySet = MyDB. OpenRe co r d set("All Pub s H , dbOpenDynaset )
CrealeRefalion
CreateRelation Relation,
--
queries. :
- -- - - - -- - - - - - - 265 - - - - - -- - - - - ---
Se t vari abl e = databas e . CreateRela tio n([name[, table [, _
fo r e i gntabl e [, attri b ute s ] ] ] ])
dbRelationUnique one-to-one .
dbRelationlnherited attached ,
.
Relation, parent
, CreateField, child
ForeignName. ,
Customers ValidStates CustState StateCode .
Dim My Re lati o n As Re latio n
Dim My Dat abase As Database
Dim My Fie ld As Field
CreateTableDef
CreateTableDef Database. :
Set variabl e = databa s e.CreateTableDef ([name[ , a t t r i butes [, _
source , c onnect]]]])
variable
TableDef. name
, attributes
. , source
, connect
Microsoft Access.
Ttl Detail
, Comments.
--
266 - - - - - - - - - - - - - - -
Set MyDatab ase = Workspaces (O ). OpenDatabase ("B1BL10.MDB")
, ~oy V ~K ~ O TableDef.
Set MyTableDef = MyDatabase.Creat eTableDef("Title Detail " )
, MyTableDef.
Set MyFie ld = MyTableDef.CreateFie ld ( "Comments" ,dbDat e)
MyTableDef.Fields.Append MyField
MyDatabase .Tab leDefs .Append MyTableDef
Execute
OueryDef SOL Database. '
:
dbDenyWrIte -
, Execute.
dblnconsistent .
dbConsIstent .
dbFailonError , ,
.
dbSeeChanges -
SOL OueyD ef.
dbRunAsync ( ) . -
ODBCDirect QueyDef .
, SOL,
Titles.
Dim SQL as String
SQL = "DELETE FROM Titles WHERE ISBN 1S NULL"
. Database.Execute SQL. dbFai lOnError
b l e D ef
ableDef
Field Index.
D<tabase
! OOIeDefs L
. 12.6. TableDef.
- -- - - - - - - - - - --
--
267 - - - - - -- - - - - - - -
TableDef , DateCreated LastUpdated,
, RecordCount,
. .
.
CreateField
(tield),
TableDet. :
Set variable = o bject .C r e a t e F i e l d ( [ name [ , typ e [, si z e ] ] ] )
dbTe t ,
sIze, Visual Basic ,
; . , ,
Phone, MyTable.
Dim MyDat aba se As Databa se
Dim MyTabl e De f As Tabl e Def
Dim My Field As Fie l d
- -- - -- -- - - - - - - - 268 - --
-- - - - - - - - -----
variable Index, name
. , Index.
Dim Myl nde x As Index
Dirn MyField As Field
Dim MyTab l e De f As Tabl e Def
Dim MyDat aba se As Da t aba s e
C reaIeProertv
TableDef.
.
OenRecordSet
recordset. OpenRecordSet
TableDef Database, ,
TableDef
source. ,
RefreshLink
linkedtable,
.
feId
Field ()
.
I~ QueyDeI. R~eL
~eMtor bIeOeI
F,e lds
Feld
. 12.7. VIK o Field.
Field.
AIlowZeroLength
(" ),
- - - - - - - - - - - - - -
--
269 - -- - - - - - -- - - --
At!ributes
.
.
dbFixedField . default .
dbVariableField U . default .
DateUpdateable
.
Defaul!Value
, .
FareinName
VKo Field foreign table, primary table.
Name
Field.
DrdinalPosi!ion
Field .
Required
Required # NULL#.
Size
bytes ,
( , dbText
255 ).
SourceField
attached.
SourceTable
attached .
Type
.
.
-
.-
27 0 ---~------------
, , Fax Phone,
Employees dbText, 20 .
Di rn MyDat abase As Databas e
Dim My Field As F ie l~ MyTabl eD ef As TableDe f
, 1 6 .
, CreateField,
:
255
, Memo, 1.2 Ge. ,
dbLongBinary, OLE.
, Visual Basic ,
.
AppendChunk .
FieldSize .
GetChunk .
AppendChunk :
f i eldo b jec t. Append Chu nk s o u rce
source fieldobject.
Memo Long Binary
AppendChunk data control, .
:
\K~ Comments .
Da t a l. Re cord Se t . Fields ( "Commen ts H )
--
FNum = FreeFile
- -- - - - - - - - - -- - - - 271
Open FNarne For Binary As #FNurn ' .
End I f
Cornment s.
Data1 .RecordSet. Fields( ~CommentsW) .AppendChunk ( CurChunk)
Loo p
Oata1 .RecordSet . Update 2 .
Clo s e FNun 2 .
End Sub
FieldSize :
GetChunk:
stringar = f ieldobject.GetChunk ( offset , numbytes )
offset numbytes
bytes .
GetBigFile ,
Memo Long Binary.
Su b Ge tBigFi 1e ( FName As String )
oirn NumChunks As Lo n g , To t al Si ze As Lo n g
o im RemChunk As I n t e g e r , CurSize As I nteger
Oim As Int eger, FNum As Int e g e r, CurChunk As String
ChunkS ize = 2 0 0 0 \ .
, . Cornments.
TotalSize Oatal.Reco rdSet.Fie1ds (~C ommentsH ).F ie1dSi ze()
, b yte s 2 .
RemChunk = TotalSize Mod Ch unkSize
CurS i z e = Ch u nkS ize
FNum = Fre eFi1e
Op e n FNarne For Bi nary As f FNum \ . .
F or = N unChunks
I f = NumChunks Th e n CurSize = RemChunk
CurChunk = Datal .Rec ord Set.F ie1ds( ~Comments) .
Get Chunk(I* ChunkSize, Cu rSize)
--
Pu t #F Nun" CurChunk ' .
2 72
Ne xt
C!ose FNum
End Sub
A~ ~o / Index
Inde
.
.
Inde .
Foreign
Ind e m ' foreign .
IngoreNulls
Required Ind e #NULL#.
FALSE, Required, ,
TRUE.
Name
I nde .
Primary
in d e "
mary key" , . Microsoft Access
"primary key", .
Ind e Primary In de.
Inde "primary key" TRUE/FALSE , ,
# NULL# lnde.
Required
, i nde ,
#NULL.
Unique
:
lnd e. , TableDef
Field Primary I nde, Field.
, TableDef Field.
primary i nde,
Field:
Dim MyDatabase As Database
Dim My Tab! e De f As TableDef
Di m MyFie ld As F ie ld, Mylndex As I ndex
Dim As I nteger
\ n~oyo .
--
2 73 - - - - - - - - -- - ----
Set MyDatabase = Worksp ac es ( O) .OpenDat ab ase(~MyDB .MDB")
MyField. Require d = Tr ue
MyTableDe f . Fie l d s . Ap pend MyF ield
Set MyFie l d = MyTable Def. CreateField( ~Fi eld2 w , db Long)
\ 1 1 1 Nul l 1 .
MyF i e ld Requ ire d = True
MyTable De f . Fie l d s.Append MyField
My Databa s e . TableDefs.Append MyTable Def
, n1 0 p r imary i nde x ~
Set Mylnd e x = My T ab l eD e f .C re a t e lndex (~ My l nde x* )
Myl ndex . Pr imary = True
Myl nd ex .Unique = True
Se t MyFi el d = My TableDe f .C re a t e Fi e l d (~ F ie l d l)
Mylnd ex. Fields. App end MyField
v(v QueryDef
SQL
, QueryDef.
QueryDe! RecordSource data control. QueryDe!
Field Parameter. query
(action query).
D._ . ..<
QueJrDels
. 12.8. QueryDef.
--
; QueryDef.
2 74
DateCreated LastUpdaled
/
DateCreated Que yD ef ,
LastUpdated / .
Name
Q u eyDef.
RecordsAffected
action
quey Q ueyDef.
ReturnsRecords
/ QueyDef, / ,
action quey .
SDL
/ / SQL Que yD ef.
, q uey Orders.
Dim MyDB As Databas e , MyQuery As Que r yDe f . MySnapshot As Rec ordset
Se t MyDB = Workspaces( O). OpenDatabas e( -MYDB.MDB W }
n ~ oo q uery.
Set MyQu e ry = MyDB.CreateQueryDef (nLarge F reight" )
MyQuery.SQL = ~S E LE CT * FROM Orders WHERE (F re ight ] > 10;"
\ n ~ oyo s n a p s h o t .
Set MySnap sho t = MyD B .Op e nRe co r ds et (~Large F r e i ght " , dbOpenSnapshot )
Type
Qu eyDef . ,
, action q uey . .
, / Append /
Qu eyD ef, / Close, / q uey,
/ Oelete, Qu eyDef , / Execute,
action quey, / OpenRecordSet / CreateProperty.
i'r.rr.rneter
Parameter
Qu eyD ef. ; / Count,
Parameter, / Name, /, / Type, /
( dbTet , dbDate, dbMemo ..).
, qu ey , ,
, Record set Qu ey D ef.
- -- - -- - - -- -- - - - -
--
275
Set MyDB = Work spaces(O) .Databases(O)
, v QueryDef.
Set MyQuery = MyDB.QueryDefs(UParamQuery ")
, .
MyRecordse t.Close
! Recordset
Recordset
, ;
data control.
Recordset query.
12.9, Fields.
Recordset (dbOpenTable, dbOpenOynaset
dbOpenSnapShot), .
Dalabdre
Recobet:
;)
l:'Wd:eJ.F~ ]:1
. 12.9. QueryDef.
AbsoslutePosiIion
Recordset.
BookMark
, AbsolutePosition.
, recordset (n)
. RecordCount,
, MoveLast
RecordCount.
Function MoveToRecord ( as Long, Rs as Recordset) As Integer
RS.MoveLast
If Rs.RecordCount > Then
Rs .AbsolutePosition =
MoveToRecord = Tr ue
Else
MoveToRecord Fa lse
End ! !
End Function
--
2 76 - - - -- - - -- -- - - --
BOF EOF
BOF, TRUE,
Recordset, EOF Record set.
, Recordset , ']
MoveNeX, MaveLast MovePrevious, .
LOOp
MyTabl e . MoveLas t
0 0 Unti l MyTable.BOF
My Tab l e . Mov e Pre v ious to pre vio us r e c o r d.
Lo
Bookmark
'] , Recordset. ,
,
Bookmark. '] string variant.
, Recordset
Bookmarks string, .
BookMarkable recordset
--
Bookmarks.
2 77
DaleCreated, LastUpdaled LastModilied
DateCreated Recordset,
LastUpdated , , , LastMadilied
Baakmark .
Index
Index, Seek
, .
LockEdits
MicrosaIt Access,
Edit. Visual Basic .
2 . default
Edit "pessimistic". .
, Update,
.
,
''ot m st c'' , .
LackEdits . :
NoMatch
Find Seek
.
RecordCound
Recordset.
50rl
Sort Recordset, ORDER
SQL . default ,
. ,
Record set data control Ship Country.
Datal.Reco rdset . Sort " [Ship countryJ"
--
Data l .Re cordset .Sort " [Sh ip Count ry] Desc " i
------------~-- 2 78 - - - -- - - - - - -- - --
Transactions
Transactions recordset eeginTrans,
CommitTrans RollBack.
Type
Recordset,
dbOpenTable, dbOpenOynaset dbOpenSnapShot.
Recordset Dynaset SnapShot.
AddNew, Ed t, Update, Oelete, Find, ..,
. Dynaset
. ,
Index. ,
. Dynaset,
Dynaset. Recordset Snapshot
; ,
AddNew, Update . . ""
, Snapshot .
Recordset.
AddNew
Recordset,
SnapShot. , Customers.
, Update . ,
LastModified .
CancelUpdate
Recordset Edit AddNew.
CIone
Recordset, .
--
, Recordset,
2 79 - - - - -- - -- - - - - - - -
, , listbox controls.
.
0 0 Unt i l Rs l . EOF
List l .Addl t e m Rsl!Author
Rs l .MoveNe xt
Lo op
00 Unti l Rs 2. EOF
Lis t2 .Addl t em Rs 2!T i t le
Rs 2 . Mov e Ne x t
Loop
CIose
Recordset,
Recordset. .
Dim My Da t a b a s e As Dat abas e . MyRecordset As Re c o rdset
Set MyDatabase Workspaces{O) . Ope nDa t a ba s e (" MYDB. MDB W }
=
W
Set MyRe c ords e t = MyDatabase.OpenRecordse t ( "Customers )
CopyQueryDef
,
Recordset. Record set table.
Delele
Recordset
Snapshot. , ,
, .
End I f
Edit
.
--
, Update .
2 80
, ,
Title.
Dim Cr it e r i a As String, NewT i t l e As String
Move
IOWs .
:
--
Cas e "BACK": Di s t anc e = Abs (Dis t ance ) * - 1
28 1
Ca s e Els e: Ms gBo ~ I n c orr ec t call i ng a rgurne nt"
End Se lect
If UCase(Re lat i veB ookMark} = ~ H E RE w Then
MyRe c ordset .Move Dis t ance
Els e
MyRe cordset. Move Distanc e , RelativeBookMark
End I f
If MyRec ordset.EOF Or MyRecordse t . BOF Then Beep
End Sub
Loop
MyTabl e .Close
MyDB.C los e
OpenRecordSet
OpenRecordSet,
. VKo Recordset
Iable, dynaset snapshot.
Seek
V Ko Recordset table
VKo Index. v :
tab l e . Se ek co mpa r i s on, ke yl , key2 .. .
--
2 82
MyTable . Index = "Pr i ma r y Key " , index .
My Tab le.Seek "= ", 3
If MyTable .NoMatch Then.. .
Update
Update Recordset
AddNew Edil.
SQL
AS, ,
:
,
brackets.
SELECT (Yea r Published] . Tit le FROM Tit les
,
WHERE.
SELECT publishers. * FROM Pub 1is he r s
WHERE ( Pub l i s he r s . Pub I D > 100 );
,
. :
--
2 83 - - -- -- - - - - -- - - -
,
, :
,
.
,
.
\} (Aggregfte fUI1Ct0I15)
SQL ,
, , ..
.
COUNT () ov
. , ,
Titles.
SELECT COUNT (Au-ID ) FROM Ti t l es
SUM , AVG,
, .
GROUP ,
, ' . ,
City.
SELECT City, COUNT (Name ) FROM Publi sher s GROUP City
n
.
, xoov .
FROM, WHERE.
.
It
, '
, dBase, Paradox .. , .
--
~C :\DBASE\ DATA\S AL E S " ~ dBASE I V;"
- -- - - -- - - - - - - -- 284 - - -- - - - - - - - - ---
WHERE CUSTOMERS.Customer ID Like ~ A*"
n !JPDATE
SELECT , UPDATE
WHERE, . ,
SET, ,
Freight Orders, WHERE.
D Orders
SET Fr e i g ht = Fr e i g ht * 1. 03
WHERE [Ship Country] = 'UK'
DHETE
UPDATE, DELETE ,
WHERE.
. nj
MS Access,
"Type Mismatch". ,
(#).
, RecordSource
data control :
Dat a 1. Da t a Ba s e = uC: \ACCESS \NWIND.MDB"
Dat a 1. Re c o r d So u r c e = uSELECT * FROM Employees
WHERE [Bi r t h Date] > #12 /31 /60#"
.nj n
,
:
parametertext datatype .
, Enter state .
PARAMETERS [Enter s t a te ] , Text
SELECT DISTINCTROW Titles . Tit le , Tit l es . [Ye a r Published] ,
Authors.Author, Publishers .Name AS Pub lisher ,
[Ci t y ] & U," & [State ] AS Location
FROM ( Publ i s he r s RIGHT JOIN Tit les Publ ishers .PubID Titles.PubID)
LEFT JOIN Authors Titles .AU-JD =Aut ho r s. Au-I D
WHERE Publ ishers.State=[ Enter state ])
ORDER Tit les.T it le
OWNERACCE SS ;
--
2 85 - - - - - -- - - - - - - - - -
- "
Iistbnx cnntrnI
Iistbox combobox control
. , FieldControl
cmb controI, tabI , , fiId,
control. RT
Database .
1 0 V 1 K o Recordset
que ry Vl0
tabl. Recordset
V10Olx f i ld 0
, cmb 6
fild.
I f Snpm.RecordCount Then
Snpm. MoveFi r st
Do Until Snpm.EOF
v l = Tr im$( CStr (Ass ign( Snpm( O))))
! vl <> " " Th en cmb. Addltem vl
End If
Snpm. Close
Scree n. Mous ePointer 1
End Sub
~ x . 1 #NULL# ~ ov
. .
--
2 86 - - -- - - - - - - - - ---
Info.Vbp, , ,
Iistboxes controls
, queries , Indexes . .
, ~ K ~
Dim db As Da tabase
Ko~ .
Fo r j = db. Tab l eDe f s.Coun t - 1
Set Td = db.Tabl eDe f s ( j )
( Td.At t r ibut e s And db SystemObje ct) Then
Li s tl. Addltem Td. Name
End
Next
Li s t l. Li s tCount > The n Lis tl. Listlndex
\ ~ ~ ~
For j = db . Prope r t i e s .Count - 1
Set Prop = db . Prope r t i e s ( j )
Lis t5. Addl tem Prop.Name + ~ = ~ + CSt r (Prop.Value)
Next
\ que r i e s
For j = db .QueryDefs .Count - 1
List 3. Add l tem db . Que r yDefs (j ). Name
Next j
, Relations
For j = db . Relat ions . Count - 1
Li s t 4. Add l t em db . Rel at i ons (j ). Name
Next
--
2 87
End Sub
1 1 10 1is tbox
i 1 inde x 1 1
\ 1 .
Fo r
= Td. I ndexe s . Count - 1
List6.AddItem Td. Indexes(I) . Name
Next
End Sub
".U"''P;e~
Q;tQl'l1e~
0'0010
CustQI'I1erlD
E mJo,ees E m ~el D
Order Oetail~ Orde!DeIe
RequredDele
S/pedJeIe
ShpVa
A elelorIs
CmtomelD CetegoriesProducts
CWQmesr(\:,rs Cu~t~sO rdes
E mlQY"'el D E mpfojeesO rders
mlo~e~(ders OrdelsOrder Detals
OrdeIDete PJuctsOrder O e!~s
PlimeyKey Shippe' sO rdes
Shped)eIe SIJ P pie sProducl.~
, _
. 12.10. .
'
'
, , (
) . Oatabase , -
--
2 88
, l D RTDB,
TableSource TableTarget. ;
dbOpenSnapshot)
Se t Snpml = RTDB.OpenRecordset(Tabl eTarget. dbOpenTable)
! Snpm.RecordCount Then
Whil e Snpm.EOF = Fa l se
Snp rnl . AddNe w
Fo r k = Snpm.Fields.Count - 1
Snpml( k) = Snpm( k )
Next
Snpml . Updat e
Snpm.MoveNe xt
Wend
End If
Snpm. Close: Snpml .Cl os e
End Sub
Ouery
, C reateOu er Def
"", Quer, . ,
, ,
Field1 Table1 1.1. Quer
, .
10 Ouery
Quer To p .Vb p , Select,
1 ( ) Q uer.
:
, Ao ~ Da t abase , K~ nl 0 ~l Querydef
Se t MyDB = Workspa ces ( O). OpenDat aba s e (~BIBL IO. MDB" )
- - - - - -- - - - - - -
--
289 - - - - - - - - - - - --
Set MyQue ry = MyDB.CreateQ u eryDef{QueryDefName$ , Sql$)
, objects ~l QueryDefName$
MyDB. Que ryDefs. Delete Qu e ryDe f Name $
MyQue ry. Close
MySet.Close
MyDB.Close
End Sub
Query
TableQueryExists.Vbp ExistsTableQuery,
Query
True, . :
Di m D As Database
Function ExistsTableQuery(TName As St r i n g ) As Boolean
Dim Test As String
Const NameNot lnCo llect ion = 3265
Error Resume Ne xt
, Ex~ Name TableDefs .
Name 1 QueryDefs .
, . .
--
End Sub
29 0
1. tetbax
Listbax c . Laad
BibIiG.Mdb (
VisuaI Basic).
SOL tetbax c l Enter,
Recardset SOL Listbax !
3. . , ,
TreeView C Oueries ' SOL .
4. 1 .
MSFIexGrid Listbax c l' c
. , .
5. Custamers.Mdb,
Kadikos. Epanima, Onama, Tilefna EmaiI Index .
5 tetbaxes cantraIs , MSFIexGrid
c buttans New. Update Load
MSFIexGrid c
.
MSFlexGrid cl. MSFIexGrid c ,
cantraIs.
- - - - - - -- -- - - -- -
--
29 1
r; r;r; (object)
' .
,
controI .
, ,
, . Visual Basic,
, .
, ,
, .. , , , ,
, , , , .
, . ,
() , (1997), ( Rena u ~) ,
(5) . ,
.
.. ,
, , .
, Tetbo x, label ..
Visual Basic, .
, , textbox
:
Te xt l .Top = 4 00
- - -- - - - -- - -
--
- - - - 293 - - - -- - - - - - -----
.
, :
, :
,
With...End With, :
Wi th Label
. Height = 2000
. Widt h = 2000
. Capti on = " Th is i s MyLabel"
En d Wi t h
LabeI ( control).
. , "
" ' , Refresh, " "
Picture ( controI) :
Picturel . Refres h
,
Object Browser, F2 View .
l
')1 Applic a1io nStar1Con~ () AscW
~ AsyncProperty ,~ 1
,fi'1J Async Type co nstanI ~ ..() 8
13.1., ,
, ' ,
2 9"
--
.
, :
Controls ( "Te xt l n )
Controls!Text l
, :
Controls(3)
,
class modules () .
, , .
class modules tarms,
. class module .
Sub Functions , Public,
, Public, declaration modle ,
, .
i,. .. .,,'
,':'-: ".
CJ.s I CIMsMocUe
co ;;ou;<!
""'"
Priolote
.
P.bkNot<retble
:) - Sh;IeUsI!
6' ~
:,;,;:;, _. - -
y"ttwt.~~)'CUUI_
. 13.2. .
--
. -
- - -- - - - - - - - - - -- 2 95 - -- - -- - - - - - -- - -
Project Properties Project, - m ,
. , Standard ,
. ActiveX ActiveX
DLL, m, 13.2.
Name , InsIancing
, .
.
1 - Private defaulf () . /
. (component).
2 - PublicNofCreatable / " component
( ) -
. GreateObject New.
3 - SingleUse / ", ooou , c ompnent
. AetioX D.
4 GlobalSingleuse Singleuse,
. ActiveX DLL.
5 MultiUse . component
Vy n .
6 - GlobalMultiUse MultiUse.
.
component
( ), New
CreateObject, :
Dim v a r iable As Ne w Cl a s s l
Public declaration class modUe , :
, :
Cla s s l . Name
Class1 .
Private
--
(property procedures). m -
- -- - - - - - -- - - - - - 296
read -only , standard modules
. , , module
. , Balance :
Priv at e dbBal anc e As Double
Class1.Balance ,
Property Get, Balance Property Let.
, Proe rty 8et .
~o
, Public
, :
End Sub
Class l .C reate
["
--
2 97 - -- - - - -- - - - -- - -
Initialize :
End Sub
Class1, New.
Terninate, :
End Sub
Class. :
( ; ) ,
. Events.Vbp
. Widget.
, LongTask. PercentOone,
Event .
RaiseEvent . m ,
, rue,
LangTask. :
Opt i o n Expl ic it
, O~6
Pu b l i c Ev ent Pe rce n t Done t ByVal Percent As 5 ing 1 e . By Re f Cancel As Bo o l e a n )
\ '
sngSt a rt = Time r
sngThreshold = Mini mumlnterva l
00 Whi l e Ti mer < ( s ng St a r t + Duration )
I f Time r > (s ngSt a r t + s ngThr e s ho ld) Then
PercentD one
Rai seEvent PercentDone ( _
sngThreshold / Durat ion, blnCanc el )
1 1
End If
Lo op
--
End Sub
2 98 - - - - - - -- - - - - -- -
. ,
WithEvents New,
Dim. code editor
mWidget, PercentDone,
, .
Widget,
New, , commandbultons, label
gressbar control ( 13.3.). progressbar
control label. .
PercentDone:
Option Ex p l i cit
, Wi dget
Pr i vate WithEv e nt s mWidge t As Widget
Private mbl nCa ncel As Boolean
End Sub
K ~K v ~ i l 6
.
P riat e Sub mWid g et-Pe rcentDone (ByVa l Pe rcent As Si ng l e, Cancel As Bool e an)
lblPerc entDone. Ca pt ion = CI nt( l OO * Perce nt ) & ~ %"
Do Ev e nt s
If mbl nCa n c e l Then Cancel True
En d Sub
--
2 99 - - -- - - - - - - - - - - - -
iiii Form1 l00
C"n:;el
46%
. 13.3. .
. ,
ReDim,
. ,
,
ReDim
4
, . :
Add - .
Count - .
II_m - a .
D_I_I_ - .
Add :
ilem , key [
, before after
.
, Add, Inst
( Class1 ) MyCiasses:
Private Sub For.m-Lo ad ()
Dim MyC la s s e s As New Col l ect io n ' ~oo ~ .
--
TheN ame = InputBo x(M sg, "Name the Co l lect ion Items")
30 0
I nst . I nstanceName = Th eName ' l l l
, l , l
, .
NarneList = NameList & MyOb ject. Ins tance Name & vbC r
Next MyOb jec t
, Kal lQ . i .
, l l l
Item ,
, ..:
key Add.
Set Obj = colOb j. l tem s (~Demo" )
(ob)ect ne r .rc n )
. .
business,
, Employee, .
, business decla-
ratIon :
Employee
. name salary.
, business, AddEmployee,
Employee :
Pub lic Function AddEmpl oyee(ByVal name As String, ByVal salary As Lo ng)
As Employ e e
--
Dim e mpNew As New Employ e e
3 01
St at i c intEmpNum As I nt e g er
intEmpNum = intEmpNum + 1
With empNew
. = ' & Fornat$ (intEmpNum, ")
. name = name
. s a l a ry = salar y
End With
co l Employe es . Add empNew , empNew .
Se t AddEmploy e e = e mpNew
End Function
, business,
:
AddEmployee, .
(polymorphism) VK O o
. Vlsual Basic 5.0, vo Implements, '
, .
. ,
. Animal ' :
End Sub
End Sub
, . abstract class
.
monkey declaration :
Implements animal
--
3 02 - - - - - -- - - - - -- - - -
H.1tf!!i* , !,!$ _'r:1I
[ iml J I (. J
Opt io n E>lp li e i t
Move
Il'I1p~~_e rre: n.~ ~_.~ i rnal
-
_~lI '>
End S ub
-
2 : ~ ~
, flea ( ), i
Animal, :
rmplement s a n i mal
Priv at e Sub animaL-B ite(ByVal What As Object)
MsgBox ~O ~ & Ty peName (What )
En d Sub
monkey flea.
anim, 5et, i (reference) flea,
Bite flea, [ monkey, i
Bite.
Dim f l As fle a
Dim mk As monkey
Dim anim As animal
Set anim = mk
Call anim.B ite(fl ) 'a Bike monkey.
, anim i i i
animal. Bite early bound i
anim, i i (compile time)
i anim Bite.
i , i .
:
--
3 03 - - - - - - - - - - - - - -
Public Sub GetFd Va l Critter As Object, ByVa l Fo od As Object)
Dim dblDistance As Double
.t":ttt~ !l
,~ <.. - "
~I ;"I ~ I ~ t l ll"
I ~~:
~ ~~
dassL
2.
.......,..
froperties I ~ E~ s ~
,.....
.
--
_"IS
. 13.5. .
AutOJJJl1ttoTI Servers
Visual 8asic
L AutomaUon.
Visual 8asic L AutomatIon se rer.
L Automation serers: in-process out-ot-process.
(DLL) (code segment),
(data segment) . o t-of- p rocess
in-process se re rs .
L Automation serer ,
Project Properties Project (Project Type) ActiveX
ActIveX DLL. ot-of-process in-process serers .
--
ate , .
- - - - -- - - - - -- - - - 304
Projed Iiet
Corte:d:JP:
'
r ~~ per Qt>jed
r. n.Md i'""""""3 t:tYeads
...
. 13.6. l Automation Serer .
x l Sheet. Vi s i b l e = Tr ue
She e t . Rang e ~ " ) .Vaue = ~ T e st"
;filil9
. ~~~-
"=
Dc \\oIIN.OOWS\5Y5TEM \/NCL32.1X<1I
""""" ........
"'-'"
--
. 13.7. Reierences.
3 05 - - -- - - - - - - - - - -
, Microsoft Excel object library, , Project ,
References,
objecf lbraes ( 13.7.).
, Browse Olb Tlb.
(object lbra es) Visual Basic .
References,
Object, , .
. , , Visual
Basic . , .
, , , X15en32.01b
References, :
Dim As Ex ce l .App l i c a t i o n
Dim mySh e e t As Work s he e t
Se t = Crea t eOb jec t(~Ex ce l. Appl i c at i o n W)
Wit h
ui Excel. , ,
.
, For Each... Nexl,
worksheets Excel:
Dim As Ex ce l.Application
- - - - - - - - -- - - - - - -
--
306
Next mySheet
End With
xl.Quit
Set xl = Nothing
nwyj 'IIord
Micrasaft Word,
VBA, Word 95 Basic, WordBasic.
(document) Word OLE
Automation , ' ,
, , . .
FileNewDefaull, defaun tem-
plate NormaI.Dot). FileNew, ,
(
template. Word ( Excel)
, CreateObject. AppShow
. :
Dim wd As Object
wd.F i l eNewDefaul t
H
wd. File New "c : \ me r i\ he l p. dot
wd.AppShow
FiIeOpen .
, error handler ,
.
Er ro r GoTo Wo rdError
Dim wd As Ob ject
wd.AppShow
Exit Sub
Wo rdEr r o r:
Ms gBox Er r.Number & " " & Err . De scription
'
Insert. ,
, FileSaveAs.
Dim wd As Obj ect
Dim My Te xt As String
Wi t h wd
. FileNewDefau lt
--
30 7
AppShow
MyText " Word" & vbC rLf
MyTe xt = MyText + " "
'
Insert MyTex t
'
Sta r tOfLine
'
.SelectCurSentence
MyText = " v "
I nsert MyText
'
I nsertP ara
Le f t Pa r a
I n s e r t ""
Bo ld
.
Fi l e Sav e As Name:="NewDocument"
End With
Word ; ,
, '
Toolbars. CounIToolbars , ToolbarName$
Toolbar, ToolbarSlale .
Dim wd As Object
Dim Too lbarArray() As Var iant
Dim Name As String, i As Integer
For i = 1 .CountToolbars
MsgBo x ToolbarArray(O , i), 1 6, ToolbarArray(l , i)
Ne xt
End With
Word, CurValues.
)
. , , i ToolsWordCount
, .
--
:
3 08
Error Go To WordError
Dim wd As Obj e c t , DialogObj As Obj e ct
Set wd = CreateObject("word.basic")
With wd
. File Op e n "c : \ Do c s\ he l p . d o c "
. AppShow
Set Di a l o g Ob j = .CurValues . Too lsWordCo unt
MsgBo x " : " & DialogObj .Pages & vbC r Lf
+ " . : " + Di al ogOb j . Pa r a g r ap h s + vhCrLf
+ " : " + Dia l o gObj . Lines + vbC rL f _
+ "~ : " + Dia l ogObj . Words + vbCrLf
+ ".: " + Di a l o g Ob j . Ch a r a ct e r s
End with
Exit Sub
WordError:
MsgBox Er r .Number & " " & Err.Descript i on
ToolsWordCount WordBasic :
ToolsWordCount [. Co untFo otnot e s = number ] [ , . Pa g e s = t e xt] [, . Wo r d s
text] [, . Cha r a c t e r s = text ] [ , .Paragraphs = text ] [, .Lines = text]
tab Genera/ OptiGns Tools Ward.
.
Set wd = CreateObject("word.basic")
with wd
. Fi leNewDefau lt
End Select
End Wi th
Word, :
wd. AppClose
Set wd = Not h i ng
, macros,
ToolsMacro. Visual Basic macros
, Word [ . ,
' macro. [ macro:
--
3 09
Dim wd As Objec t
W'ith wd
. Fi leOpen ~c : \ do c s\Ga i a . Do c "
. AppActiv ate ~Micros o ft W'o r d "
. ToolsMacro Name :="MyMacro ", Run: =True
End W'ith
- ni
SIack
Stack (stack)
LIFO. Push ,
, . Count
, , , Item
. , :
MsgBox Stck.Cou nt
MsgBox Stc k. ltem ( l) & " " & Stck.ltem( 2) & " " & Stck. ltem(3 )
MsgBox Stck.Pop
Ms g Bo x Stck. Pop
Ms g Bo x Stck.Pop
x ~ K~K :
De fLng -
Pri v a t e nStack As New Col l e c t ion
--
3 10
Remove ( . Count)
End If
End With
End Function
With wd
F i l e Ne wDe f a u lt
. I n s e r t txtSpell ing.Text
Error Re sume Next
To o lsSpell i ng
EditSelectAl l
.CharLeft Count:=l . Select:=l
txtSpe l ling. Text = [ Se l e c tio n $] ( )
. FileClose Sa ve: =2 ' o K ~
End With
End Sub
InOJrnet Explorer !:
Internet Explorer ,
Automation Server, . ',
Explorer Visual BasIc, Shell,
References Tools SHOOGVW. OLL.
Internet Explorer .
,
buttons
OecIaration .
Priv a te As Ne w I nt erne t Exp l orer
--
311
.. Control Dem: I!!lIiJ 13
G~At:
EndDemo
. 13.8. .
. Visible
Explorer:
Option Expli c i t
Privat e As New Internet Exp lorer
Unload Me
End Select
IE.Quit
Set Nothing
End Sub
; Intemet Explorer
control.
SHDOCVW.DLL, ,
WebBrowser control, browsing Visual Basic.
, Browse, GoBack, GoForward,
GoHome, GoSearch, NavIgate, , Refresh Stop, , OnBeginNavigaIe,
OnCommandStateChange, OnOownloadBegin, OnOownloadComplete, OnNavigate, OnNewWindow,
--
3 12
OnProgress, , OS tatusTextCha ge .
Screen.MausePointer = 11
La b el l . Ca p t i o n = "Creating Excel Object"
Labe ll.Refresh
workbooks . Add
workbooks . Add
Set mySheet = . wo r kb o o k s ( 2 ) . Wo r k s h e e t s ( 3 )
Visible = Tr u e
End With
mySheet.Select
La be l l . Capt ion "Opening the database"
Lahell . Refresh
--
31 3
Labe11.Caption = ~Record : & Str ( i + 1 ) & ~ of" & Str (rCount )
Labell.Refresh
For j = Sn. Fields. Count - 1
\ o~ fie ld s p reads heet
If Sn( j) .Type < 11 Then
, cel ls (i + 2 , j + 1). Value Sn (j )
Else
. c ells( i + 2 , j + 1) . Va I ue ~ Memo o r Bi nary Da t a "
End I f
Next j
Sn.MoveNext
i = i + 1
Loop
\ e xc e l obje ct - ao K ~ Exc e l a
Label l .Caption = ~Quitting Excel "
LabeIl .Refresh
xl. AppI i c a t i on. Quit
EI s e
, .
End If
Label l . Caption = ~ C l e an i ng
LabeIl.Refresh
Set Nothing AoK ~ object variable.
Set Sn = Nothing AOKV~ snapshot ob j ect.
Se t db = Nothing A oKV~ da tabase object .
Scre en.Mou s eP ointer =
Label1 . Ca ption = "Ready"
Labell. Re fresh
End Sub
MDI
, MDI,
.1 , . . ,
13.9. CMRU
dnte.
Registry
p~ .
b! 4
--
. 13.9. Mdinote.
3 14
.
' separator mnuSeparator ExiI
mnuFileMRU, Index Visible False.
Load :
, ,
UnLoad, Registry.
m-ob j MRU. Cl o s e MRU mnuFileMRU
End Sub
. CMRU,
:
Opt i on Explicit
Co n st MAX-LEN = 32
Privat e mLiArrayNum As I nt e g e r
Private mLiMaxAr r ay As Integer
Pr i v at e m-sFil e Array() As String
, . ~ K
\ a
, Re gi st r y .
Public Sub OpenMRU(mnuAr ray As Var iant )
Di m vaMRU As Variant , i As I nt e ge r
Dim s F il eName As St r i ng
--
3 15
If Len(sFi leName) Then
If rnLiArrayNum Then
Loa d mnuArraY(ffi-iArrayNum)
End If
ffi-sFileArray(rnLiArrayNum) = sF ileName
mnuArraY(ffi-iArrayNum) . Cap tio n = FormatName(sFileName)
mnuArray( rnLiArrayNum).Vis ible = True
If ffi-iArrayNum < m-iMa xAr r a y Then
ffi-iArrayNum = rnLiArra yNum + 1
Else
Exit For
End If
End If
Next
End I f
If rnLiArrayNum Then
Load mnuArraY(ffi-iArrayNum )
mnuArray(rnLiArrayNum) .Caption
mnuArray(rnLiArrayNum ) . Visible True
End I f
End Sub
, Registry .
Public Sub CloseMRU(mnuFileArray As Variant)
Dim i As I nt e g e r
For i = rnLiArrayNum - 1
SaveSe t t ing APPLNAME, "MRU", " File " & i + 1, ffi-s FileArray( i)
Ne xt
End Sub
, vn
\ .
Pub lic Sub UpdateMRU( rsF ileName As String, mnuF ileArray As Variant)
Dim i As I nt e g e r , J As Integer
I f Len (rsFi1 e Na me ) = The n Ex i t Sub
Fo r i = rnLiArrayNum - 1
If LCase(ffi-sFileArray(i)) = LCa s e ( r s Fi1e Name ) Th e n
For J = i 1 Step - 1
illLSF i1eArray( J) = ill-sF ile Ar r a y (J - 1 )
rnnuFi l e Ar r a y (J ). Cap t ion = mnuFileArray(J - 1) .Ca ption
Next
illLSF i l eArray ( O) = rsF i leName
mnuFi leArray( O).Capt i on = Forma t Name ( r s Fi l e Name)
Ex i t Sub
End If
Ne xt
If ffi-iArrayNum < ffi-i Ma xAr r ay Then
For i = ffi-iArr ayNum 1 Step - 1
ffi-sF i l e Ar r a y ( i ) = ffi-sFi leArray( i - 1 )
mnuFi l e Arra y ( i ).Ca ption = mnuFileArray( i - 1 ). Cap t i on
--
3 16
Next
rn-sF ileArra y( O) = r s F i l e Name
mnuFile Ar ray( O) . Ca ption = Fo rma t Name ( r s FileName )
mnu Fi l e Array( O).Visible = True
rn-iArra y Num = rn-iArrayNum + 1
Lo a d mnuFi leAr r a y(rn-iAr rayNum)
mnu Fi l eA r ray (rn-iAr r a yNum ).Caption
mnuFileAr r a y( rn-iAr ray Num). Vi s i b le Tr u e
Else
For i = rn-iArrayNum ~ 1 1 St ep - 1
mnuFileArray(i) .Caption = mnuFile Ar r a y (i - 1 ) .Ca p t io n
rn-sF ileAr ray (i ) = rn-sFil eArray (i - 1)
Next
m-s FileArray (O ) = r sFileName
mnu FileArray( O) .Caption = Forma t Name ( r s F i l e Na me )
End I f
En d Sub
\ E ~ ~
\ ri lndex.
Pu bli c Function GetFil eNam e ( r i l ndex As Intege r ) As String
Ge t FileName = ffi-2F i leArray (ri lndex)
En d Fun cti on
\ o oo ~
\ ~ KnO~ O .
Priv ate Function FormatName (rsFi l e Name) As String
Dirn sTemp As St rin g , iStart As Int e g er, i Found As l n t e g e r
\ ~ o X ~K ~ ~
Pri v a t e Su b Class_I nitializ e( )
m-iArr a y Num =
L...iMaxArray = 5
Reoim ffi-SFil eArra y( O 4 )
End Sub
--
3 17
1. vr; r vr; -
rrK vr.
2. Visua/ asc;
3. vr /mp/ements.
4. Severs; ;
1. TgFile, .
( 30)
. - Ei sl, Open, FreeFile
, .
2. , TgSlring,
. .
3. TgComDialog,
ShowColor, ShowOpen, ShowSave, ShowPrinler, Show Fonl ShowHelp CommonDialog clI'
: , CommonDialog
Inilialize .
4. Zoo.Vbp, ,
Animal "" .
- - -- - - - - -- - - -- -
--
31.
- --------
'
~/ 'lII "H-~ ~'
.111
, !f-
ActtveX ctr's
n Ac;tveX cotrl
--
control ,
3 19 - -- - - - - - - - - - - - -
control spinner control.
. New Project File,
.
b s,.. :::::<:J
~
"""""XD
lIi ~
.-(-
"
Wi>>rd
ou
~
'I!J I pt "'" \'8 fuerons.
~ co ...
~
- ~- ~
~
A<I~. ""
. 14. 1. .
ACtiV3X control .
,
UserConIrol1,
control. control
xt box txtSpinnerValue (vertical scroll-
bar), vsSpinner. controls UserControl1.
~':~'";"'P'"'.'~
. I__ ~
. 14.2. ActiveXcontrol, controls .
. ';,;;g,.'.l.\!l.Iii8!fti'4 _ !!'
l~sSpinn.,,- :J jCh. nge :J
P ,, ~ .. t ~ ,~
U" "rC Dntr o l Initia li z .. ( )
- ..:
, , ,~
" " .. ,~
v"Sp inn .. ... C hang .. ( ~
GW"I!.iJG-"tiPJ,
f '''.j@
,, ,~
!.
,.j-ill ~
--
. 14.3. Code Window Change.
3 20
, UserControl1. ( 14.4.)
Toolbox control ( )
UsetControl1.
control'
I ~ ;'~
abi " -.J
r- IIJ
~ .!HJ ;
Q1!Ji,I"'I',III.Oell.iii..
tii ~je:;, . ~
:~ ~ :~J~ ~=C:S1)
jjf L1ie::o-I;r"n (U>er<:ontolI
! ~ Ptoj"ctz (P,oje<:tZ)
i:: ~_~ Fo<m;
I:1 @, i1@ !i1
1-'.1
", '
--
. 14.6. projecl, ActiveX cotrol UserControI1 .
32 1
control .ctl, project
.vbp, , , group projects .vbg.
ActiveX control , .
. ActiveX Inlerlace Conlrol Wizard
Add-Ins. 6.10., default ,
ForeColor, BackColor, Click ..
,~"
",.yn<RudC omI ete
AuoR. e<Ir _
C~ IA.yncRed
Event
PrOefly
Med>od
"""'
En~d
,~
"- "
"' oe<y
~=Y ~
c~tyCh blqe" Mel:hod ForeCo/Qr
a...,. ,-
"""""
, Net,
, . ( 14.8.)
.
InitValue, tet box scrollbar ActiveX control.
<
e- -
@\,-
. 14.8. .
Finish, Wizard ,
.
control, m m
m_, m_BackColor, m_Enabled . .
--
standard , Ciick, DbClick ..
3 22 - - - - - - - - - - - -- - -
Event. InilProperties con-
Irol' ReadProperties cantroI
, controI,
ReadProperly TOU u PropBag, :
Pr i v at e Sub UserCont r o l-ReadProp ertie s(PropBag As Prope r t yBag )
Er ro r Re s ume Ne xt
' ~ ~ ~ Masked.
ReadProperty ,
, default .
contraI ,
WrileProperties, Wr~ePropey PrapBag.
Pr ivate Sub Use rCont roL-Write Propert ies (PropBag As Prope rtyBag )
Call P ropBa9 . Wr i t eP roperty ( ~ B ac kCo lorn r mLBa ckColo r , rn-de f -BackCo lo r )
. . l. 1. . . .
End Sub
, WrilePrOperty
, , defau ~
.
, cantral.
.
PropertyChanged, Let,
BackColor control:
Pub l ic p rop e rty Let Ba c kCo l o r (B yVa l Ne w-BackCo lor As Long )
mLBackColo r = Ne w-BackColo r
Pro pertyChan ged ~ B ackColorw
End Pr ope r t y
Get ,
u:
,
control , design:
Initialize control .
In ~Propeti e s control ! / . n
Extender Ambient.
Resize. Paint control control
--
( p.In!).
3 23
F5 , control
design run time.
:
ReadProperties contro! vo .f
. Extender Ambient.
Resize, Paint control control
( Pain!).
c ontrl controls
BackColor, background controls
;
-
.-
324 - - - - - - - - - - -- - - --
Pub l i c Property Let BackCo l or ( ByVa l NewColor As OLE-COLOR)
Dim o bj Ctl As Obj ect
OLE_COLOR ,
,
.
control s
MousePo[nter, control :
Pub lic Propert y Get Mous ePointer ( ) As Mous ePo int e rCon stant s
MousePointe r = UserControl .Mous ePoint e r
End Pr op ert y
(Object >rerte 5 )
control
ActiveX control ,
. , LabelFont, labels
controls UserControl:
Public Property Get Labe!Font ( ) As Fo nt
Set LabelFont = UserControl .Font
End Proper ty
--
Set objCtl.Font = Use rCont rol.Font
3 2 5 - -- - - - - - - - - - - - - -
End If
Ne x t
End Sub
, , Font standard .
Private Sub UserContro l-1nitProperties()
SyncLabe lFonts
End Sub
LabelFont, :
End Sub
, controls
ActiveXcontrol . :
ETlJJ n~v
, FavorIteDinosaur,
.
' :
--
mdnoFavoriteDinosaur = NewDino
3 26
PropertyChanged ~FavoriteD inosaurH
End Property
E xterder
control captIon,
control. :
Pri v a te Sub use rControl-Ini tProperties()
Capt i on = Extender. Name
End Sub
Arnbtert
--
.
3 27 - -- - - - - - -------
declaration module control:
Opt ion Explic i t
, publ i c Click
, MouseUp UserControl :
oval ( shape contol
control), Click RaiseEvent.
GoBack GoForward
history Ilst:
Privat e Sub Us e rCont ro l-Cl i c k ( )
Error Re s ume Next
Hyperlink. GoForward
End Sub
--
, .
3 28
i Picture control:
Pub l ic Prope rty Ge t Picture ( ) As Pict ur e
Set Pi ctu r e = picBitmap . Picture
End Pr op erty
, , LoadFinished,
i .
, i Get Let:
Pub l ic Pr operty Get P i c tureFromURL() As St r i ng
Pi cture Fr omURL = mstrPictureFromURL
End Prope rty
End If
PropertyChanged ~ Pic tureFromURL"
End Pr o pe rt y
AsyncRead :
-
.-
329
Target
URL. AsyncType
po ov :
VbAsyncTypePicture Picture.
VbAsyncTypeFiIe Visual Basic.
, AVI .
VbSnCe ytea byte.
Property
" " . " "
AsyncReadComplete vo Select, :
Private Sub Us erCont ro l-Async ReadComplet e (As ync Prop As AsyncPr opert y )
Erro r Re s ume Ne x t
Dim Canc el As Boolean
End Se l ect
End Sub
, , LoadFinished ,
vo RaiseEvent.
Cancel True, .
, Property AsyncRead
CancelAsyncRead, " " .
. pIcturebox control ,
AutoSize .
control:
--
picB i t map. Move , , ScaleWidth, Sca l e He i gh t
3 30
Else
If ( Wi dth <> picBitmap.Width) _
Or (Height <> picBitmap.Height ) Then
Siz e picBitmap.Width, picBit map. Height
End If
End I f
End Sub
control . UserControl
, , project . '
Toolbox control AsyncBitmap. declaration
bitmap:
Option Exp lic it
Const DOWNLOADF ILE = "d: wind ows\ s amp l e s\ f i n l\Ar c he s . bmp "
Click :
End If
End Sub
U , Picture , ;
LoadPicture. PictureFromURL.
file:\. U .
, LoadFinished:
Private Sub AsyncBitmapl-LoadF inished( cancel As Boo lean)
cancel = False
Ms g Bo x " a ''"
End Sub
Cancel False, .
H#itffli ~Ic::l l
--
3 31
OC)( c;oTItrol
OCX AcliveX conlrol
, , , AsyncB~map .
ToolBoxBitmap UserConlrol b~map
Toolbox
conlrol.
, File Make AsyncB~ap.ocx,
. Oplions conlrol,
OCXconlrol 10.700 Bytes.
, Setup Wizard ,
"" conlrol , ,
conlrol Internel, cab.
ActiveX conlrol L,
OBJECT,
control, , , , ..
ActiveX conlrols Web tag < OBJECT>.
, m ActiveMovie ActiveX control,
L :
<BODY>
<OBJE CT ID="ActiveMov ie l" WIDTH=26 7 HEIGHT=73
C LAS S I D ~ " C L S I D : 0 5 5 89 F A 1 - C 3 5 6 - 1 1 C E- B F 0 1 -0 0 AA 0 0 5 5 5 9 5A "
--
VBScript.
3 32
- - - - - - - - - - - - - - - - - - - - -- - -- - - -
< OBJECT > tag, ALlGN
control, BORDER , HEIGHT WIDTH
control, HSPACE VSPACE
control . .
, ActiveXcontrols,
"" ,
,
. CodeBase tag < OBJECT >
URL constrol, :
COD E BA S E = "htt p: //actie x .m i c r o so ft .com / control s / co n tro 1 . ocx#Ve r s ion=l, 2, 3"
control.
, control '
CodeBase, .
, ,
ActiveX ' tag < OBJECT> . :
CAB
.CAB (Compressed cabinet file) ,
. ,
Lempel-Ziv, Diamo nd.Ee , ActiveX SDK.
PEs (Portable Eec utab les ) .OCX (custom control), . ( )
.DLL ( ) .
'"f
.
Ii IJjterJjet
- -- - - - - - - -- - - - -
--
333
An conten ~. ""''''''~,"",,''''''''''''''~",*~R;
Web gM ~ conn 4ctie COOenl: ltII q oential}o
~~:Ierrts The;e s~ COfbd hoo.o pol~
poblem:s a'! dMk with
S eiIy methxi
r. t{ (ecnneMed w ers)
/! polected IQl serty pob!em$. Poten~
lI'"I$afe contert i$ oide: al"ld yoo ! noI~ed.
r Medun !recommended to e:ert AeI$ aI"Id dev~J
You '! -neo:t .,. fe~ ~You conchoose
whethe noI to vew pedily .ns8! cone.-.
r tlone InoI ~
ou ! noI polected ftorn ~ sedy pablem; , U$e 1
S'eltrg ~ }'CIU! R8'eeI.:I:~ Ir'isj re vJe
0< c.....
Niaoso ft ( l
25 2 COI'I01MrcZ! 1HJbJ',"'" rm<N' Cl'Nertzl5 $~ by ,
, Ve riSiqn C91!HI!!HCjf! Softwar e p ubl iWJ;;A ,
""
-.. .. Ex,p;res: 1~?i'!.997
,
.-,; ",- ~
. 14.11. l contro.
CA (digital sign)
, Microsoft GTE, control. ,
--
control
3 34 - - - - - - - - - - - - - - -
Internet I, . [ ActiveX controls
,
on HTML.
c:te}{ Doc:ument s
ActiveX Documents,
ActiveX controls, containers, Internet l 3 .
Oftice Binder.
on Visual Basic 5.0
. ActiveX
lJocument. UserDocument,
, , , '
OCX control, ActIveX
, ,
, VBD. lnternet
Explorer, .
L ActiveX Document VBScrIpt
:
1. on control -
. control ,
. , control focus,
( on Format).
control container control
textbox control.
--
3 35 - - - - - -- - - - - - - --
~,
Kio
{
n IJIterJIet
VisuaI Basic 5.0 ActiveX controls Intemet,
, " ,
i C""O; 'I~I @:"""''''''''' .
Microsoft Int~rnetControls
~ iK # % ~'IN;,, 1'. J.i ~ ' I!I
D Mc ;oft Controls5.0
~ ..uJ_~
- ...
.
D MCrosoft ~ked Edit Cotrol 5.0
O fo'iosoft ~ Control 5 .0
Miosoft 0..tIine Control
i[
O !"o'oscft Pi;tU'eQ Control 5.0
i ~ 1::.
':!J
~
O ""=rosoft RemoteO&a Control
MtSOft RemoteQo1J ecrtol2 .0 ::;" EJ 1m
Io\crosoft Rd Textbox cnrol 5.0
D fo'osoft SysIrfCl ContrtIS.o
DMicrosoft abbed DaIog Control5 .Q
"'cosoft wndows Comon Controls 5.0 'If Ilrowse...
Q..!'krosoft:_~ COfMon ctrds--2 5.0 ..:J
.~ - "'"
~rtcr~ ~ Tr5der Cotr!S.O
.!
-
'- loction: D:\WIlM\System32\MSII'Er .oc
" II ~ 1
controls,
--
TCP/IP, Intemet . .
- - - - -- - - - - - - - - - 337 - - - - - - - - -- - - -- -
CP/IP
Internet , :
CP (Transmission Control Protocol) (Internet Protocol) . 4 (Layers):
Appiication, .
@ Host-To-Host Transport, .
@) Internet, .
Network Access, .
1}
.
4 , 255,
. L 182.45.11.51.
,
. , Internet : http://wwW.
poseidon .gr/Vbonline.
, .. :
.gov = Goverment
.com = Commercial
.edu = Educational Institution
.net = Network
.org = Noncategorized OrganizatIon
.gr = Greece
.jp = Japan
Internet Network Information Center (InternIc).
(I'orts)
Internet.
Internet.
Ports, .
Internet,
Port. , :
(WWW): 80
FTP: 20 & 21
GOPHER: 70
--
3 38 - - - - - - - - - - - -- -
SMTP(Email): 25
3 : 110
L: 23
WHOIS: 43
FINGER: 79
,
, .
. hosts,
Windows : 89.0.0.107 www.address.com.
, Domain Name System
(DNS) .
Soc:ket5
Socket . ,
sockets, Barkeley Sockets,
Intemet, Windows Sockets,
Windows. ,
WinSock, m ,
TCP UDP.
LocalHostName .
LacallP .
LacalP o ~ E Joo / .
Protocol / .
RemoleHosl .
RemoleHostlP .
RemotePM / .
--
Winsock Control.
3 39 - - - -- - - - - - - -- - -
Close .
Connect .
GetData .
Lste n .
PeekData Buffer.
SendData .
Winsock Control.
Clase .
Connect Kjp .
ConnectionRequested .
DataArrival .
SendComplete .
SendProgress .
'rNetBEUI P!otocol
" N'W'l..IFWS P ~ibII ,~
"N\ILd. NetBlOS
'rCP,otocoI
. . Ber.e
O,,~
.. ..< CoMoI ~ 1 co:r.>: e comect10 f1IBM
nr/,,,,,,,,, d m rers ..tCh'ld dfec Mt","""
_d
--
. 15.2. NETWORK TCP/IP.
3 40 - - -- - - - - - - - -- - -
TCP/lP WINIPCFG.EXE
Windows 95 IPCONFIG.EXE Windows .
Winsock Control, LocalHost LocallP,
. ;
control Form_Load :
Protocol TCP D 0-
skcTCPProtocol, 1-skcUDPProtocol. SocketHandle
Winsock Control.
crteJIt
Client
Connect, RemoteHost
RemotePor!
1066, 1 1024
, Serices Windows.
State ,
Connect:
Pr ivate Sub Wins ockL-Connect {)
If Wins o c kl .State = s c kConnect e d t he n
Print nConnect ion Succe s s f ul W
end i f
End sub
State :
SckClnsed Socket .
SckClnsing / .
SckConnecIed .
SckConnecting .
SckConnectionPending Sncket / ,
SckError .
SckHostResolved Socket .
SckListening Socket .
SckOpen .
SckResolvingHost Socket .
--
3 41
SendData , . .
DataArrival,
GetData .
, Client Close, .
C len b Winsock Control ,
True AutoRedraw ( , ;)
Buttons, [ :
CIose Connec1ion j
': ~ '
Option Explicit
Private Sub Fo rm-Load( )
Caption = Win sock l . Loca lHo stNaroe & ": " & Winsockl. Loca lIP
En d Sub
, K~O
'
, i Ql Q n
--
3 42
Private Sub Winsock l _Connect( )
I f Winsockl.State = s ckConnec ted Then
Pr i nt ~ Co nne c t io n successful! W
End !
End Sub
\ oo ~ 11 client 1
Server
Server, Client,
. l acalPort
Client. , Lst en , Server
:
ReQuestld .
Server Sockets:
Clients Client.
Accept, Server
DalaArrIval GetData SendData. D
Client , Server Close,
server .
--
3 43
Serer
Serer.vbp:
DataArrival 1.1
client .
Client,
Connect / , .. 127.0.0.1.
Serer Send.
--
Close, 15.4.
3 ......
_ D
"""""'" ""'"
Lislennj 10pt 1006
l,} nn Serer
Client Serer .
Cl ents, Winsock Controls.
Winsock Control
Index, , .. :
, control ,
control ,
ConnectionRequest control Load, .. :
Private Sub WinsockL-ConnectionRequest(Index As Integer, ByVal requestI D As
Long)
Print ~Co nne ct ion request id ~ & r e qu e s t I D & _
~ from ~ & Winsockl (Index ) .RemoteHost IP
NumSockets = NumSockets + 1
Lo a d Winsockl (NumSockets)
Wi nsockl (NumSockets) .Acce pt requestID
Win s o c k l ( O). Close
Wi nsockl (O) . Li s t e n
End Sub
Serert.vbp , Serer
:
Option Explicit
Dim NumSockets As Intege r
--
3 -45
Fo rml. Show
Caption = Wins ockl ( ) . LocalH os t Name & " : " & Wins oc kl ( ) . Loc a l I P
Wi ns ockl ( O).Lo c alPort = 1066
Print "Lis t ening to po r t : " & Winsockl ( ) . LocalPort
Winsock 1 (0 ). Listen
End Sub
ConnectionReque st n 1 L1 c lient
1 .
client .
"r o\\o
--
Sever , , '
3 46
TCr/lp. .
Internet. , Serer
13 ti ck.usno .nay .m il (19 2 .5 .41 .40 ) :
Option Explicit
Document / Serer.
Prolocol URL.
Proxy Proxy Server Internet.
RemoteHost / .
ResponseCode .
Responselnfo .
Cancel .
Execute .
GelChunk .
GelHeader .
OpenURL ..
--
, Control.
3 47
StateChanged Status j .
Hypertext Transfer Protocol () FTP TELNET.
, Internet Serer 1.0.
Internet, .
(Application layer)
Internet. :
[HeaderrL.fieldname ] : [fieldN_value]
ldata]
User-Agent : Spy
<HTML><Hl>Hello, World.</Hl>< /HTML>
Get URL.
Head .
Post Sere r.
Put , .
,
Sere r .
CR/LF .
Serer :
[ He a de r N_ f i e l dn ame ] : [fieldR-value ]
--
[data]
3 48 - - - -- - - - - - - - - - - -
, Microsoft Internet Explorer :
, URL .
Internet
Browser. Keep-Alive
, If-Modified-since
.
Se ve r , :
HTTP/l.O 200 ok
Server: Micros oft -II S / 3. 0
1 2 1 99 6 1 3 : 32 : 1 0 GMT
Dat e : Sun,
Cache -cont ro l : pr ivate
Content - type: tex t / h trnl
Expires: Sun, 12 1996 13: 32 : 10 GMT
Set -Co okie : ASP SESSI ONID=QXXBABBAXGVJP GMUi path= /
Ac cept-Ranges: bytes
Last -Mo d i f i ed: Fri . 09 J u l 1996 04: 0 0 :00 GMT
Content-Length: 405 1
<HTML>Some da t a-< / HTML>
, status 200,
, , application
sever . GR/LF L.
OpenURL .
URL
textb o control:
Text l = I n et l .0pe nURL (~http: / / www .mic roso ft .comW )
Protocol,
:
Protocol.
IcUnknown .
IcOefault 1 l! Protocol.
IcFTP 2 File Transfer Protocol (FTP).
IcGopher 3 Gopher protocol.
I c 4 HypertextTransfer Protocol () .
--
I c S 5 .
3 49 - - - - - - - -- - - - - - -
Httpspy.Vbp Internet transfer control,
Internet . controls
15.5.
.. HTTPSr ~.
HTJPS~
1~ II_ DcotOltcom
ReI~HML
:J
[
. 15.5. .
l atho s :
Text2 .Text = ""
Text3.Text = ""
nw Sct >
; Secure
Sockets Layer (SSL) . , Server
CP/IP . Intemet,
UserName Password intemet transfer control.
( Client Server,
server) m, -
--
3 50
.
'
.
, PC MS-DOS Windows.
Intemet transfer control FTP
, Eecute , ,
VBTooIs FTP Serer Microso:
Execute ,
.
StateChanged control Status.
, :
State:
IcNone '{ .
IcReceivingResponse 7 Host.
IcResponseReceived 8 Host.
IcOisconnecting 9 / .
IcOisconnected 10 / .
I c r 11 / .
icResponseCompleted 12 .
GetChunk , .. :
; '' ,
:
--
3 51
Pos it ion = -1
Di rectory = Inet1.GetChunk( Q)
. 15.6. .. (160)
--
35 2
- - ------
Bus y = True
I f Listl. List (Li st l . List l ndex) = " " Then
Ex it Sub
Elsel f Listl . List (Li stl. Listlndex ) = " " Then
Inetl . Execute Te x t l . Te xt, "CD " & List1 . Li st(List l. List lndex )
El se l f Right (L ist1. List {List1. Listl ndex ) . 1) = " j " Then
Inetl. Execute Te xtl . ., "CD " & List l . Li st ( Listl . Li s t l n de x)
Else
CommonDialog l . file name = Li stl.List(List l.Li st lndex )
CommonDi alog l. ShowSave
I ne t 1. Ex e c ut e Text 1. Text, "GET """ + List1. List (List1. Listlndex ) + """
+ CommonDi alog1. fi l e n ame + "" "
End If
End Sub
, n i~ l Q ~ K ~ .
JjJj
--
35 3
Hefp
, . Windows help.
, ' ,
, help, ,
, Internet Explorer . .
help :
(HelpText ) RTF.
f9 Help Project (HPJ).
~ (compilation) Help Compiler Help
Project.
Help ,
Visual Basic.
"',
Eo11':1('tAnsi Mrtl o d
,_ ....
rIIItSr l\IttlIod
,..s,
nt)ivo lRg hl IITIV fJf:. ( 0IIUI.Jt , ty .o "- LJ[l(q
...
'
.J~:I~~Sh i\ l tt IIo,!
Pq ~_I IW6~Ai ~,br"i7
P_&-e+
,...".c
j
--
. 16.1. topics. page break.
3 55
, help
RTF. ,
TgstrIng.Rtf, Microsoft Word 97.
, topics. topIc . ,
(hypertext),
topiC. Page break
Insert Word.
topiC, (con-
text strIng). footnotes Word,
, topic .. topic.
, Insert, Footnote...
Custom mark. textbox tootnote . ,
, #,
$. , 16.2., Footnotes
. context strIngs ,
.
Footnotes . , topics
History, Bookmarks, Topics Indexed Search Results help.
'" .
E},.tractAnsi MetlIod .1.J
m pE (fI "" ltlQ(oo ~ , ANS/
,
vo[ Ci 10 " , ll( lt lQl VO _ EIC
H/3fi #. n ( m~~ h
footnotes , topiC
footnotes .
Footnotes Insert.
footnotes - +
topiCS (groups) .
topIcs Word
. topic
--
' help. ,
3 56 - -- - - - -- - - - - - --
Format Font , Underline,
,
Double. ,
context string topic.
Font, hidden checkbox. .
double underline hidden context strIng
topic, , TakeMemoField
16.3. hidden
Show/Hide toolbar Word.
~"----,---------~,---------,- P4ge Break__ ".-- ,..- - ---..-.-- ..- --.- ....,.-.-.- .....----.....-.----"!::.
m '+1f
App endMtnlOFi el d 'l\fe th o d~
.~
' 8 0 - r - ' f l d - i - l -tt e ss - .- Q - 1 - !
- ulT1f. .' ' 'io' - - ' Memo - LongBnary." np
m?lI' ,. IakeM emQFje'[n)t~M_~l@f.~!4 - - - '. - 10' )
.
vo,l m;lu .1 _
v"r t1l
1>,;, ,''' " M".m" r;"'.MI(i/d.A <~;.,M)II -;-
Eo ~ . ~
. 16.3. .
Help project
, ,
.. , help project,
help. ,
HPJ. , RTF
help, help .
HPJ :
[OPTIONS]
COMPRESS=lQ p h rase Zeck
OLDKEYPHRASE=Ye s
LCID=Q x 4Q8 ; Gr e e k
CHARSE T ~1 6 1
CONTENTS=main
--
TITLE=TgS tring Class
3 57 - -- - - - - - - - - - - -- -
COPYRIGHT=(R) Tangram Cl a s s Ac tion Ve r 1 .0
CITATION= (c) De mo s t he ne s Poseidon 1 9 9 5 - 1 9 97
BMROOT=D : \VBONLINE\voI3 \source\help
HLP=. \ t g s tring . hlp
[FILE S]
tgst r ing. rtf
[ ]
main=1000
[WINDOWS]
main= "" " 60672 , (r14876671), ( r425958 4) , f2
secon d="" , (6 53, 102, 360 , 600) , 4 , (r 1487667 1 ) , (r4227327) , f 2
, HPJ, OOS HC
Visual Basic. (compiler)
HPJ help.
OOS, :
Hc Tgstring.hpj
Microsoft Tools CO
Visual Basic HCW. .
, Microsoft l Workshap,
HPJ l , " "
OOS hc campiler.
IOPTlONS]
COMPRESS..10 phraseZ ecl:. "", 1
OLOKEYPHRASE",Yes
REVlSION500No W"",",
<4 0 ; Gleek
REPORT..Yes
QiAR5ET..161
""""
CONTENT5..rMin ", . 1
" gSITi1g C1!.ss
COPYRIGHT,,[R) Targam ClassActione 1.0
TAT!O N ~lc) Oemos.hees pooedon 19951997
.......
-"O : \VBO N LI NE \voI3\souce\help
g;;,j..
[FllfS]
Ig$Irir"g,rIf iCl\F]
16.4.,
, HPJ .
OpIions... [ help, , topic
--
3 58 - - - - - - - - - - - -- - - -
help .. , FiIes... RTF
help. Windows...
help.
default , topics
. Windows... m
detauit . Windows Properties ( 16.5.)
, m , ,
Buttons scrolling scrolling .
; . m topic
Paragrah Format.
topic ,
Paragraph Line and Page Breaks Keep with next.
?! '
Wndow ll!bul:et
r. ~ r M><iize...mow
~uHeb...inck>w<)nkp
. 16.5. .
'"
,~
~OOerMI
,'"'- ""'"' "..1""
Jnde>c ~
...
iI<
-
"
TgString
N.tl
Obftd.M>eJ (JI < Slring)
.:J
. 16.6. uv .
. m
--
topIc ' . topic Attach -
3 59 - - - - - - - - - -- - - - -
second Attach
. :
ttach~ At tach>second
'
Paste no xo RTF.
m ,
RTF. , hypergraphics.
:
{bmx picturefile}
, r c ,
. ctrefile .
' 8itmaps... Microsoft
Help Workshop. 018, WMF, SHG.
hypergraphic s Hotspot Editor.
, topic.
Hefp
'
50 .
topic , hidden , ! '
.
Notepad. :
~ v !e crgram ( calc .ee' , )
Back c .
- - - - - - - -- - - - - --
--
360
he n - he n se marker
RegisterRoutine pvj LL (RR).
CIoseWindow ro .
Vs ual Basic
Exec, .
, ,
. . . ,
, !ep ("exec B oaUt. avj " ) hidden :
H
1 AV I!ep (~ e xec Boat-l i t . av i ) .
GoWeb. URt.,
Internet Explorer URL.
, ( 18)
RegIstry
Intemet EpIorer:
Private Declare Function RegOpenKeyEx Lib ~ advapi32.dll Alias
~ RegOpe nKe y E xA (ByVal hY As Long, ByVal l pSubKey As String, ByVal
--
3 61
Const HEY-CURRENT_U S ER : & 800000 0 1
Cons t HEY-LOCAL-MACHINE : & 80000002
Cons t EY-ALL-AC CE S S : & + & 2 + & 4 + & 8 + & 0 + & 20
Sub mai n ( )
Dim hey As Long, Res As Long
Dim Buf f e r As Str i ng
Loca l Erro r Resume Ne xt
P a t h s \I E XP LORE .E XE ~ ,
GoWeb
:
J]oj
,
DLL ( DLL 18).
RegislerRauline (RR), :
Regi s t erRoutine( DLLName , Funct ionName , Parame t e r Spec )
--
reUm_type -
3 62 - -- - - - - - -- - - --
, parameteUypes
, , ,
return_type= ,
return_type parameteUypes
, S .
RegisterRoutine help.
snd PlaySound RTF Config
HPJ, Config... Micro soft Help Workshop:
help.
Tgstring.Hpj BrowseButIons,
topic, InserfMenu
, Appendltem menu items , ,
RegisterRoutine.
[C ONFIG ]
Br owseBut t ons ( )
I nsert Me n u( " Meo u-To ol s " , " &To o l s" , 4)
Calcu lato r
Appendltem ( "Menu-Too ls" r " Ca l e-I tem ", "&Calculator" , ' ( " calc . e xe' , )")
; Notepad
Regi sterRoutine ("MMSYSTEM" , " s ndP lay Sound ", " Su")
sndPlaySound, :
terp
HPJ RTF,
hlp, . Save and Compile Microsoft
Help Workshop. .
(warning) .
, help. ,
Run WinHetp.
Kjo te rp n ] 5 a5 C;
hlp
Visual Basic Context-Sensitive,
hlp F1. vx Help File
Projecl Properlies hlp.
,
hlp Systems
--
Windows.
3 63 - - - -- - - - - - - - - - -
topic F1 Contents
Options HPJ ( ), HelpContextlD
controls , F1 topic,
control (focus).
. context string topic Map...
Microsoft l Workshop, Map HPJ.
[]
main=1000
Attach=lOlO
help , ,
WinHelp, 32-bit :
Private Declare Function WinHelp Lib uuser32" Alias ~WinHelpA" ( By Val hwnd
As Long, ByV al lpHelpFile As String, ByVal wCommand As Long, ByVal dwData
As Lo ng) As Lo ng
\ vl topic i~al l
Con s t HELP_CONTEXT = &1
\ il help
Cons t HELP_QUIT = &2
, vil index
Const HELP_INDEX = &3
\ l help
Cons t HELP-HELPONHELP = & 4
\ il l Vl I n dex
Con st HELP-SETINDEX = & 5
\ i l topic lQ keywo rd
Con s t L- = & 101
wCommand. hwnd , IpHelpFile
hlp. :
WinHelp Me .hwnd , App.Path + "\TgString.h lp" , HELP_INDEX, CLng(O)
[ , , help ,
. , :
, , ShowHelp
CommonOialog control:
Const L- = &H10l
Const HELP_INDE X = &3
, Help .
CMDialogl.HelpFile = App .He l pFile
CMDialogl.HelpCornmand = HELP_INDEX
--
CMDia logl . ShowHelp
- - - - - - - - - - - - - - - 364 - - - - - - - - - - - - - - -
Crystff Reports
Crystal Reports, Visual Basic,
,
: . ReportDesigner Add-
Ins Visual Basic, ProgramGroup, . ,
interface, report, FILE :NEW REPORT
, report, Crosstab Report & Mailing labels.
, (
BIBUO.MDB). report sec~on, Page Header, Details PageFooter,
( 17.1.).
.. _ "
'
"q .. ~ .. .,. ...
>\uthol's Repolt
:
b'"
D_I.
P1oq" IDOIM
.~jj ~ j j ~ j j
. 17.1. re .
Insert Database Field, - , Detail Section report.
--
Pageheader , -
3 67
, (..
, 55555... , y-MM-DD . .) .
, Insert:Text Field,
Page header .
click textfield, ,
, , , , , , .
special fields, , ,
Group.
, Insert :Graphic Page header
.bmp, .gif, .pcx, ., .tga Insert :Object
Excel, OLE.
! Prevlew File menu,
17.2.
-d-.P
2~).(r
3.1o(.R", !/! 3 54.00
4 Adenn. V..gna
~ Mr.,...,.", b M:~ P
6.An1. Stt= E
7 ~or. L . J" 'f< e
Al .)d';ch.> , I R
9:Avis<>n.D ,
10 ~ard, Di<1t 1.941 ~6.00
1 Begel Fcb ord
12 Bww,Lua
4 ~ 1<>11 . ,;;:" Q. .;; B cad! Clo 2119 2U 5& 1, I DD",
. 17.2 Report .
, Preview ,
, ,
ASCil, txt, doc, r, xls, dif, CSv
E-Mail.
File:Print : ,
report, .
Report fonnula fields.
,
.
menu Insert : Formula Field
Edit Fannula,
, Crystal Reports,
--
.
3 68 - -- - - - - - - - - -- - --
formuIa,
( 17.3.), :
, Button Check.
FJelds: , Funetions' - O Il ol O S ;
Re po lt Fiel ds:
lhS .Ve " , ,
Au!ho ' s.Au_lO =
~
Arilhmeti c:
Rem" ind" , (num. d "nom )
Abs ()
( )
=
= ,,-,. , ""
i
Ari1hmet ic '
S ubutIet =
~
.F (
Au!hoIs.Au!ho r Round l l
@"
(
r~und (. # plo c e s )
" ,n r-"I.. (.
,r- .t?i ,,_PI,r..
~ Dii de
nl
.
. ~'* 'Th ~. ~ .,,,,
FDrmula 111><1: ==:' i
jYe..., (Tod y) - {"'h,s .e ,}
"""'" '" "'" """'~. .
~ .
..
=l 111
"'"'" ~~_tt I .'W~" " "'I' [) LL """~' L
t!elp
,
.
--
. :
3 69 - - -- - - - - - - - - - --
j
f9 j
@) j .
U :
U :
U (IF ELSE):
If Remainder (ToNurnber({file .Cus tNum}) , 2 )= Then
{ f il e .O f f e r l }
Else
{ f i l e . Of fer2}
@HARDWARE
@SOFTWARE
If (( { f i l e . SoftSa!es}lOOOO ) The n
. 10 * {{ fi le. So ftS a l e s } 10 0 00)
El s e
, function DayOfWeek:
I f Not(DayOfWee k({ f i le .Cal l Date in 2 to 6) Then
"Weekend"
Else
U Uu :
--
Wednesday 4
3 70 - - - - - -- - - - - - - -
:
I f PageNumbe r > 1 Th en
PageNumber
El s e
1 :
Date (1 9 9 0 , 1 0, 1 ) = Oc t 90
! PageNumbe r = 1 Then
Pr intDate
El s e
Da t e ( O, , )
(IF ELSE):
! { f i l e.D e g r e e } <> UPh.D . " and
{ file .Degre e} <> "M.D. " and
{f ile.Degree } <> "0. 0 . S " The n
If { fil e . S e x } = UM" The n
"De ar Mr . + {file. lname }
El se
''De a r Ms. + { file .lname}
El se
''De a r Dr. + {file . lname }
, :
//
--
:
37 1
{Authors.YearBorn } > 1990 w 1990.
""C" {Authors.Lastname} [1] "C".
{Authors.lName} [1 10 2] = ' " '" .
Visual Basic,
, SeIectionFormula, ..:
CrystalReportl. Se lectionFo rmula = " {Autho r s . Aut h or} = 'Adams'"
report
.
' RPT,
.
Crystal Custom Control control
. Tools : Custom Controls Crystal
report control, toolbox.
toolbox controI
Printer,S:etup
!:.
. 17.4. TestPrn.vbp.
Crystal Report:
Pr i v a t e Sub CmdPrint-Click()
Di m rpname As String
MousePointe r = 11
Error Re s ume Next
- - - - - - - - - - - -- -
--
372 - - - - - - - - - - - - - -
rpname = App.Pat h & ~ \ "
Cry stalReportl . DataFiles (Q ) = rpname & ~b iblio.mdb"
\ 1 0 ~o Crystal Reports
Cr ysta l Repo r t l.Re po rt Fi l e Name = rpname & ~Te s t.Rpt
Cry sta lReportl.Action = 1
MousePointe r = Q
End Sub
OJ~
CrystaI Reports (
CRPE32.DLL),
, Database
Iocation, , :
reports.
,
:
report
50%
CrystaI Custom Control.
Crystal Reports:
Sub CrystalWithAPI ()
Dim result %, j obnum%
Dim Fi l e Loc As String
r e sul t % PEOpenEngine ( )
--
If r e s ult % = Then
- -- - - - - -- - - - - - - 373 - - - - -- - - - - - - - --
MsgBox RCrysta l Repo r ts Engi ne Op e n Er r or , -,
Crystal Reports.
PEClosePrintJob .
PEStartPrintJob ' .
PEGetJobStatus status .
PECancelPrintJob .
PESelectPrinter .
PEOutputToPrinter .
oWindow .
PEOutputToFile ; .
PEGetFormula .
PESetFormula .
PEGetSelectionFormula .
PESetSelectionFormula .
--
3 74
" ,~_ VERII'Y_ON_E\lERY PRltH ,
-;.. ;. run time errors reports.
, , ',~_
""/ . ;. , Crystal Reports
PEOpenEngine ( form load )
PECloseEngine ,
- - - - - - - -- - - - -
--
- - 375
5 5C
De c lare Sub Gl o hn ame Lib "lname" [Al i as "a l i a s narne" ] [( [a rgum ent s] ) ]
Declare Function Globname Lib "lname " [Al i a s name ] [ ( [a rguments] ) ] [As t ype ]
Globname
Visual Basic. 5.0 (
32-bit) 32-bit 4.0
(case sensitive), 16-bit 4.0.
AIias name,
, , '
Globname.
Lib
. Arguments , As Type
Integer, Long, Single, Double, Currency, String ( ) ,
VarIant.
arguments :
--
377
, ,
by value. ,
, :
# I f Win32 Then
De cla r e Sub Me s s age Be ep Li b "Use r 3 2 " (ByV al As Long )
ffEls e
De c lar e Sub MessageBeep Lib "Use r" ( ByVa l As I nt e g er)
i End If
( ) '
DLL. m , by refemce ( tabs(O)).
DLL,
:
Ty pe RECT
Left As Long
As Long
Right As Long
Bot torn As Lon g
End Type
, DrawFocusRecl ,
. :
De c lare F ucti on Dr a wFo cu sRe ct Li b "user32" Al i a s "DrawFocu s Re c t " ( By Va l
--
hdc As Long , l p Re c t As RECT ) As Long
3 78
by value. , As
, .
, C+ +
32-bit 16-bit Visual Basic:
n J W d W 5
Windows (window).
, controls. background desktop .
,
"window proc". ,
Windows . ,
, Windows. , Visual Basic,
:
Function Win dow sP roc &(ByVal hwnd&, ByVal message &, ByVa l wparam& , ByVa l
lpa rarn& )
Se l ect Case message&
Cas e 1i'llLPAIN T
, v Q ~
Case M1..-SETFOCUS
, vQ
End Se lect
, Wi ndows
WindowProc& = De fWindowProc&(hwnd&, mes sage & wparam& , lparam& )
End Func t i o n
--
3 79 - - - - - - - - - - - - - -- -
hwnd
Windows,
( ) .
Windows "window proc"
, , , Message .
WM. , Seiect
Case, .
, .
( )
DefWindowProc. DefWindowProc
"window proc".
Visual Basic 2 SendMessage PostMessage
.
xl box
(read oniy), SendMessage:
Const WM-USER = &4 0 0
Dec lare Function Se ndMes s age Lib "user32" Alias "SendMessageA" (ByVa l
h wnd As Long, ByVal wMsg As Lo ng . ByVal wPararn As Lo ng , !Param As Any ) As
Long
SendMessage ( Textl. hWnd. EM.-SETREADONLY , 1, )
(window class)
Windows.
. , ,
. "window proc"
. RegisterClass,
, , WNDCLASS. WNDCLASS :
Type WNDCLASS
sty l e As Long
l p f nwndp ro c As Long
cbClsextra As Lo ng
c bWndExt r a 2 As Long
h l n s t an c e As Long
hlcon As Long
hCur sor As Long
hbrBackground As Long
lpszMenuName As Long
lps zC la ssName As Long
--
End Type
3 8 0 - - - - - -- - - - - -- - - -
10 , .
, (lpfnWndProc) "window
", ' .
style .
, CS mj OR.
, :
, .
, cbClsExtra cbWndExtra
.
(global class) child controls. Windows
7 , :
, :
, , , IpszMenuName
menu .
p~po
' "
" .
, , ,
. CrealeWindow,
32-bit :
De cl are Function Creat e Wi ndo w Lib "u s e r 3 2" Alias "Creat eWindowA" _
(ByVal lpClassName As St ring, ByVal l pWindowName As String. Byval dwStyl e _
As Lo ng , By Va l As Lon g . ByVal As Lo ng , ByVal nWi dt h As Long, ByVa l _
nHe ight As Long, ByVal hWndPar ent As Long , ByVa l hMenu As Long , _
ByVal h l n s t a n c e As Long, l p Pa ram As Any ) As Lo ng
--
. Windows -
- - -- - - - - - - -- - - - 381
. ,
hDC (device contet) ,
( video display) .
Windows ( DrawText )
. ( ) ,
(client area) "".
, hardware .
AddressOf
5. 0.
Visual Basic.
module ( )
DLL .
(Enumeration function) ,
Windows. m ,
(fonts) DC ( EnumFonts),
child ' - ( EnumChildWindows),
(proper1i es) ' ( EnumProp),
(tasks) ( EnumTasks) , ,
( EnumWindows).
(callback)
, . Enum.Vbp
EnumWindows, :
Dec la re Func t i o n EnumWi n dows Lib "u s er 3 2" ( ByVa l lpEnumFun c As Long, ByVa l
l Pa ram As Long) As Bo o l e a n
, Long , callback
. ' module
:
wParam . ,
AddessOf :
lRe t = EnumWi ndo ws (Addres s Of EnumWind s . )
--
End Sub
- - -- - - - - - - -- - - - 382
Pr ivate Su b Fo rm-Re s i z e ( )
Loca l Er r o r Resume Next
Li s t Vi ew 1. Mo v e , , ScaleWidt h, Sca l eH eight
End Sub
xaaK~a
al1KO . 1 0
aal1K
ListView cont r o l
10 Ge t Wi n dowTe xt
GetClassName Vl 0
For = iWnds
, 11
--
3 83
,
Publ i c hWnds() As Long
Public iWnds As I nteger
callback Ka ~
a EnumWindows .
1 x~ hWnd
1 ~
K K ~o 1 .
~ y ~K hHnds
. .
hWnds{iWnds) = wParam
i Wnds = iWnds + 1
End Sub
, ..
Ij Form1
OOE S _ Wndow
OIeMa8"The<fN/nf.j_
I!!I~ EJ
Fncl F&t
R......
IrioSeek Ewtemion / N ~o
B~ M eter
MSWE B~S_
~~
History
VINCII Ba:ic 800. O*le
V~uaI Basic:: Bock $ O*le
" ;10
F~e
MiclmofI\Iord vb5
PIogram Marage
. 18.1. l istView control .
AddressOf
Windows, Subclass Superclass, controls (
) ] .
textbox control .
Windows
control textbox control
. . textbox controls ,
"window proc", Windows .
. GelWindowLong,
GWL_WNDPROC, "window proc" .
SetWindowLong
. . "window proc"
textbox cantrol.
Hook.Vbp . textbox control
--
commandbutton controls. "window proc" textbox control,
3 84
WM_CHAR Windaws.
"window proc" control.
. Hook.Frm:
gHW l l
t e xthox control .
Const GWL-WNDPROC = -4
Const WM-CHAR = &2
"window proc"
y ~ ~x2
, E ~ ~
Public Su b Unhook ( )
Dim temp As Long
t emp = S e tWi ndo wLo ng ( g HW, GWL-WNDPROC, lpPrevWndProc)
End Sub
Eyx~ WM-CHAR K~ 2~ ~ -1
' ~~
--
l
3 8 5 - - - - -- - - - - - - - - -
, ~ Cal lWindowPro c.
Se lect Ca se uMs g
Ca s e WM...-CHAR
! Not IsNumeric (Ch r$ (wParam Then
Beep: windowProc = -1 : Exit Funct ion
End !
Case Els e
End Select
\ l
\ "window p ro c"
Windo wProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam. lParam )
End Func t i on
Shell
Visual Basic Shell, .
, ,
CreateProcess
.
WaitForSingleObjec!
.
Shel132.vbp. , , ExecCmd,
:
--
cbRese rved2 As !nteger
3 8 6 - - - -- - - - - - - - - - -
lpReserved2 As Long
hStdlnput As Long
hStdOutput As Long
hStdError As Long
End Type
hThread As Long
dwProcessID As Long
dwThreadID As Lon g
End Type
start.cb = Len(start)
,
ret& = CreateProcessA( 0&, cmdline$, 0&, 0&, 1&,
NORMAL-PRIORITY_CLASS, 0&, 0 &, start, proc)
l l li
ret& CloseHandle(proc.hProcess)
End Sub
--
3 87
ReadlNI$ Wr~elN I .
$ ,
. Sec~ons, Keys .
:
(Section]
ke=au e
! :
. C (
C), ASCII
. , Visual asc .
System Menu
Visual Basic System ( Control
) ,
KillSystemMenultem . System n
( ) . .
4 , Minimize.
hWnd
.
, Dec la rations
De c la re Function GetSysternMenu Lib U us e r 32" Alias uGetSystemMenu" (ByVal
hwnd As Long, ByVal bRev e rt As Long) As Long
Dec l are Function RernoveMenu Lib ~ u s e r 3 2 " Alias ~ RernoveMenu N (ByVal hMenu
--
3 88 - - - -- - - - - - -- - - -
As Long, ByVal nPosition As Long , ByVal wFlags As Long) As
Long
Sub Form......Load ()
Call Kill Sy sternMenuItem(4 )
End Sub
Sub Kil l SysternMenuItem ( i As Intege r )
Cons t MF-BYPOSITION = & 400
HSysMenu = GetSy stemMe nu (Forml .hWnd, )
k = RemoveMenu (HSysMenu, i , MF-BYPOSITION)
End Sub
. GetTempFileName
Temp
Windows. GetTmpFile$ .
. DLL,
, ' .
Space$. ,
. , Left$
.
GetTmpfile $ = fil e $
End Funct i on
Program Manager
, Program Manager Windows 95. m
, , .
Run Windows Progman.
Program Manager; ,
FindWindow ,
.
( hWnd) . U Pointers ( As Any)
(ByVal 0&) L:
\ Declarations
--
3 89 - -- - - - - - - - - -- - - -
Pri v ate Dec lare Funct ion FindWindow Lib ~u se r32" Alia s
~ F i ndW i ndowA "
Su b F orLLoa d ()
Di m hwn d As Integ e r
hWnd
FindWindow :
, , .
,
(always on ). SetWindowPos.
, Command1_Cl ck
, Command2_Clck .
, Declarations st a nda rd modu le
Declare Su b SetWindowPos Lib ~user32" Alias ~ S et W i ndowP os " ( ByVa l
hwn d As Long, ByVal hWndlns ertAfter As Long, ByVal As Long, ByVal
As Lo n g, ByVa l cx As Long, ByVal cy As Lo ng, ByVal wFl a g s As Long )
Sub CommandL-Click ()
SetWindowPos formI. hWnd, -1, , , , , & 5 0
End Sub
Su b Command2_Cl ick ()
Set Wi n d owPo s formI. hWnd, -2, , , , , &50
En d Sub
Recycle
,
ShellDelete , Win32
SHFileOperalion,
Recycle Bin . ParamArray
. main
32-bit Visual Basic. ,
SHFileOperatIon, , wFunc,
, , .
Option Expl ic it
Type SHFILEOPSTRUCT
--
3 9 0 - - - - -- - - - - - - - - - -
hwnd As Long
wFunc As Long
pFrom As String
As String
fFlags As Integer
fnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String ' FOF-SIMPLEPROGRESS
End Type
,
Public Const FO_COPY "" &2 YlQ l
Public Const FO-DELETE = &3
,
YlQ l
Public Const
, YlQ
FO---MOVE "" &
Public Const
,
FO--RENAME "" &4 YlQ
Sub main()
Dim lResult
ReDim sFileName(l 3) As String
, l
, l a
sFileName(l) uFirst"
sFileName(2) uSecond"
sFileName (3) uThird"
lResult = ShellDelete(sFileName())
\ l l
lResult = ShellDelete (UFirst" r uSecond" r UThird")
--
End Sub
3 91
Formal
u Win32 , u
Visual Basic.
Format.Vbp command buttons
DriveLlstBox u Drive, u
. u SHFormaIDrive. format
u. u u :
a f rma t ~K
Else
RetFrornMsg = MsgBox ( " f l oppies " & " " , 64, _
"Dis kCopy Exampl e")
End If
End Sub
--
3 92
, E~o ~ou Dr ive
,
GontrolBox.
ChangeSlyleBiI, ,
iHwnd, ui]
( VB) . afNew ,
f , True False :
Declare Func t i on Ge t Wi ndowLong Lib ~ u s e r 3 2 " Alias ~Ge tWi ndowLongA n (ByVa l
hwnd As Long. ByVa l nlndex As Long) As Long
Decl a re Function SetWi ndowLong Li b "us e r 32" Alias "SetWindowLongA" (ByVal
hwnd As Lon g, ByVal n lndex As Long, ByVal dwNe wLong As Long ) As Long
De c l a r e Fun ction SetWi ndowPos Lib "use r 32" Al i a s "SetWindowPos " (ByVal
hwnd As Long , ByVal hWndlnsertAfte r As Long, ByVal As Long, ByVal As
Long, ByVal c x As Long, ByVal cy As Long. ByVal wFl ags As Long) As Long
Sub Cha ngeSt yleBit (iHwnd As Long , f As Boolean. afNew As Long )
Dim af As Long
! iHwnd = Then Exit Sub
a f = GetWi ndo wLong ( i Hwnd, GWL-S TYLE)
I f f Then
af af Or a fNe w
Els e
af af And (Not afNew )
End !
Cal l SetWindowLong (iHwnd, GWL-STYLE. af )
Call SetWindowPos (iHwnd, HWND-NOTOPMOST, . , . , _
SWP-NOZORDER Or SWP-NOSIZE Or SWP-NOMOVE Or SWP-DRAWFRAME )
End Sub
Timer
Timer Visual
Basic. .
--
3 93
Timer = timeGetTime / 10 00 !
End Funct ion
Dec la re Function SendMessage Lib "us er32 H Alias " Se ndMe s s ageA" (ByVal hwnd
As Long, ByVal wMs g As Long, ByVal wPararn As Lon g, lPararn As Long ) As Long
Sub SetListHor( Li s t 1 As Li s t Box )
Const WM-USER = &400
Cons t LB-S ETHORI ZONTALEXTENT = (WM-USER + 21 )
SendMessage List1.hwnd, LB-SETHORIZONTALEXTENT, CIntListl.Width * 2 ) /
Screen.TwipsPerPixelX ),
End Sub
ShExecute - Shell
ShExecute ,
, ,
. , Dac1.Doc,
Word. ,
ShellExecute.
De c l a r e Functi on ShellExecute Lib " shel132 . d l l H Al i a s "ShellExecut eA H
(ByVa l hwnd As Long , ByVal lpOpe r a t i on As String, ByVal l pFi l e As St r i ng,
ByVal l pPa rarnete rs As String. ByVa l l pDi r e c t o r y As Stri ng , ByVal nSh owCmd
As Long ) As Long
Fun ction ShExe cute ( iF ile As String) As Integer
Cons t SW-SHOW = 5
If Dir$ (iFile) <> . Then Exi t Func t i on
ShExe c ut e = Shell Execut e (O&, vbNullSt r i ng, iF i le,
vbNullSt r i ng , vbNul l St ring, SW-SHOW)
End Fun ction
Taskbar
Tbicon.Vbp ,
taskbar Windows 95 '
' . , taskbar
, picturebox control .
MouseMove .
:
- -- - - - - -- - - - - --
--
39-4
hWnd As Long
uld As Long
uFlags As Long
ucallbackMessage As Long
h lcon As Long
szTip As String * 64
End Type
Dim t As NOTIFYICONDATA
, t
, NOTIFYICONDATA
Private Sub Fo rffi-Load()
t .chSize = Le(t )
t.hWnd = pichook.hWnd
t.uld = 1&
t .uFlags = NIF_ICON Or NIF_TIP Or NIF---MESSAGE
t.ucallbackMessage = WM....MOUSEMOVE
t.hlcon = Me.lcon
t . szTip = ~Shell-Notifylco. .. " & Chr$ (O )
Shell-Notifylcon NIM-ADD. t
Me.Hide
App.TaskVisible = Fa lse
End Sub
\ in Click
\
taskbar.
--
39 5
Pr i v at e Sub pichoo1L.MouseMove (8 utton As In tege r . Shift As
In tege r , As Si ng le, As Single )
Iistbox conlrol
Iistbox ( combo box) controI
LockWindowUpdate, :
Declare Functio n Loc kWi ndowUpdat e Lib ~ u s e r 3 2" Alias "Lo ckWindowUpdate"
( ByVal hwndLoc k As Long ) As Long
Dim i %
--
3 96 - - - - - - - - - -- - - ---
multiline text baxes cantrals
SendMessage,
multiline text boxes controls, Visual Basic
.
multiline text box control:
Function ScrollText& (TextBox As Control, vLines As Integer, hLines As
Integer)
Const EM-LINESCROLL = &406
GetLineCount
multiline text box control:
Function GetLineCount (TextBox As Control)
Const EM-GETLlNECOUNT = &400 + 10
GetCetLe caret (
) text box:
Function GetCurrentLine (TextBox As TextBox)
Const EM-LINEFROMCHAR = &400 + 25
LineLength . CharPos
lndex . -1,
:
ReplaceSel
Bufter$:
Function ReplaceSel (TextBox As TextBox, Buffer$)
Const EM-REPLACESEL = &400 + 18
--
3 97
Undo
tetbox control:
Funct ion Undo (TextBox As Te xtBo x )
Const WH-USER = &4 0 0
Co n s t EM-UNDO = WM-USER + 23
, " "
tet box s$ en$:
Sub i nsert-char(st$, en$)
Const WMLPASTE = & 3 02
, Vlewer
Visual Basic.
1. GetSystemDirectory,
System Windows.
3. GetSystemMetrics, .
4. DISKSPACEINFO GetDiskFreeSpace,
, bytes,
- - - - - - - - -- - - - - -
--
398 - -- - - - - - -- - - - - -
..
' .
5.
. GetComputerName.
.
6. 32-bt, Gaia32.DLL.
, Compress & Decompress,
. :
De clare Func tio n DeCompres s Lib ~Ga ia32 .D LLW (ByVa l source$ , ByVal tar -
getS)
As Long
. .
Compress,
( ) .
, DeCompress,
.
, (PKUNZIP) .
- - - - -- - - - -- - -- -
--
399 - - - -- - -- - - -- - --
Collections 35, 295
ComboBox Control 155
Command button Control 7
ljI ActlveControl 214 Command$ 44
r. ActiveForm 56 CommonOialog Control 170
ActiveX Controls 319 Const 31
ActiveX LL 19 CreateOatabase 261
ActiveX Oocuments 335 CreateField 268
ActiveX 19 Createlndex 268
ActiveX Interlace Control Wizard 322 CreateObject 305
AddNew 235, 279 CreateProcess 386
AddressOI 382 CreateOueryOel 265
Aggregate Functions 284 CreateRelation 265
opoi 26 CreateTableOef 266
Ambient 327 CreateWindow 381
And 27 CreateWorkspace 259
Animation Control 195 Crystal Reports 367
377 Currency 28
69
Append 55
252
Oata Control 232
AppendChunk 271
Oatabase 262
Arrange 89
OataField 233
Array 34
OataGrid 176
Asserts 63
OataObjecf 130,132
AsyncRead 329
OataSource 232
AutoRedraw 95
Oate 28,47
r: Bi 249 OateSerial 47
.: BOF 236 Oay 47
BookMmark 236 Grid Control 244
Boolean 28 OBEngine 25
Bound Controls 243 216
Reference 38 Oebugging 60
Byte 28 Oellnt 30
ByVal 38 Oeftype 28
OefWindowProc 380
~ Caption 10
: CCur 32
Oim 28,33
71
oi 37
OirecIory List 161
CheckBox Contol 152
00 52
Checked 78
OoEvents 49
Circle 100
34
Class Module 295
Oouble 28
Clipboal 213
Orag-and-Orop 122
Clone 279
OragMode 123
--
Cls 54
4 01
OrawFocusRect 378 GetWindowsOirectoty 378
OrawMode 103 GoTo 52
OrawStyle 102
O rawTet 382 I I HdC 382
OrawWidth 96 l 355
List 160 54
D Early Bound
303
239
Hour
47
332
348
Enabled 78 HyperLink 328
EndOoc 11
Enum
Enums
326
35 11 :~age Control
ImageLlis! Control
50
164
185
EOF 236
Erase 34 Implements 302
Err 62 Indexes 251
62 Input 56
Event 298 Input$ 56
Eto O 327 InputBax 29
11 Field
Field
269
269
InputBox$
Instancing
29,49
296
Instr 45
File List 162 Integer 28
FileCopy 59 Internet l 311
FillColor 102 IntemetTransfer Control 347
F111Style 103 IsArray 30
FindWindow 389 IsOate 30
Font 107 IsNu11 30
FontTransparent 107 IsNumeric 29
For 53 IsObject 30
For Each
Forrn Module
53
17 13 Keyboard
KeyPreView
143
143
Forrnat 46
293
Frame Control 149
FreeFile 55 Kiil 64
Fdend 297 D l abelControl 150
m
FTP 351 Late Bound 304
GetChunk 272 LBound 34
GetOata 130 Lcase 46
GetFormat 130 l eft 45
GetSettIng 71 Len 45
GetSystemOirectory 378 Line 98
GetTempFile 389 Line Control 168
GetTet 213 Line Inpu! 56
GetWindowLong 384 ListBox Control 153
--
Listview Control 186
...02
Base 33
LockWindowUpdate 396
Lof 59 Option l 30
Long Integer 28 Optional 43
OptionButton Control 151
lJ Main
upo 48
Or 27
44
BV 284
87
Menu
Methods
75
23
54
m OufPuf
P-code
Page
55
13
111
Microsoft Mail 181 Painf 95
Mid 45 PaintPicture 1
47 ParamArray 43
Modal 54 Parameter 275
Modeless 54 Parent 138
Month 47 PictureBox Contol 166
Mouse 11 9 n l 32
Mouselcon 127 99
MousePolnter 127 Polymorphism 302
MS AexGrid C o ntol 197 PopupMenu 79
MS Word 307 PostMessage 380
MSChart Contol 176 Prevlnstance 69
MSComm Conto l 178 Primary Key 232
MsgBox 29, 48 Primary Key 251
Multimedia Control 196 107
m NewPage
NoMatch
!
11
238
27
PrintForm
Private
Program Manager
11
31
223
ProgressBar Contol 184
Now 47
Projects
m
17
Object 293 PropBag 323
Objecf Variables 36 Property Procedures 40
OOBCOirect 253 PropertyChanged 323
L 226 Pset 97
LAufomation S ere rs 304 Public 31
L Orag And Orop 128 Puf 57
OLEOrag 132
OLEOra9Drop 130 ! QueryDet 274
OLEOragOver 130
OLESetData
OLEStartDrag
133
132
11 RalseEvent
RalseEvents
298
37
Error 61 Read 55
55 ReadPropertles 323
OpenDatabase 262 Record 231
OpenRecordSet 263 RecordSet 235, 276
--
- 403
RecordSource 234 Structures 34
Recycle 390 , 39
Redim Pre sere
RegisterClass
34
380 D Table
TableOef
231
267
RegisterRoutIne 362
abStrp Control 195-
RegSvr32 169
C 338
Rem 25
24
Resume 61
26
RGB 97
xt 10
RichTextBox Control 188
xt Control 5
Right 45
TextHeight 108
Rnd 63
TetWidth 108
37
Then 50
t SaveSetting 71 Time 47
Scale 96 TimerControl 163
ScaleMode 96 TimeS eal 47
Scroll Bars 157 oolBar Control 188
Second 47 Transactions 242
Seek 57,282 TreeView Control 193
Selec! 51 m 46
SendKeys 146 34
SendMessage 380 , 28
SetAttr 162
SetFocus 54 ! UBound 34
.SetText 21 3 Ucase 46
SetWindowLong 384 Update 235
S eWin d owPos 390 UpdateControls 242
Shape Control 167 UpdateRecord 242
Shell 386 U pd ateWnd ow 381
S hell Eec ute 394' UserMode 327
SFnmat e 392
! aa 28
Show 54
Vartype 28
ShowWnd ow 381
Sc ! 335
Single 28
Slider Control 184 !!J WebBrowser ControI 312
Sockets 339 WeekOay 47
Space 45 While 52
Speil Checker 311 Wincosk Control 339
SQL 283 WinHeIp 364
SSTab Control 181 WithEvents 37, 299
Standard Module 18 Worl<Space 260
Static 31 We 55
StatusBar ControI
Str$
183
45
m Wte P roper1ies
Year
323
47
--
Strng 28, 45
.. ..