Click here to load reader
Upload
thanos-katsa
View
198
Download
39
Embed Size (px)
Citation preview
Visual Basic 5.0
~ 1998
21 - 189 03 . : (01) 46.63.419, 094-410.042 Fa : (01) 46.65.356 E-mail: [email protected] Web: http://www.poseidon.grpress / .
Q TS -AR
.
&
. .
:
. : Fa:
8 & 26 92.41.571 -2 92.31 .293
ISBN: 960-861-230-6 , , , , ; .
~o , 1. ,
t
. , . , . ,
. ,
.
Eo,ywrn
-.uu
K~Wo
1__ _ _ _ _ _ _ _ _ _ _
n n Textbox control Command button control (templaIes) - calculator
K~o 2 (
Project5project
__ _ _ _ _ _ _ _
,
,
Custom Controls project compilation
__ _ _ _
(camparisan)
- - - - - - - - - - -- - -
--J
_ _ ..,_ _ _ _ _ _ __
(Structures)
Enums
- (Object Variables)
""
_ Visual Basic _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
main
U
DoEvents
1... 1 Then Select Case
(Melhods) (Debugging)
Asserts
Meru
_
Menu Editor ~--:---,--- ----------------- Menu Conlrol _ Submenus _ ,---_ _ _ - menus _ _
K~o5Mu/tLp/e - DocumeJ1t
lJ1tert'r.ce ()
__ _ _ _
~o6[a
__ _ _
Pset line
__--.;
C rcle
a i nt ctu re
-
l
----iMill
lilll
DrawWidth DrawStyle
---1l1iii
FillColor FiIIS e -------------------lIiiii tyl 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
F e ram Labe nbutt n o Chec kBox List Com bo Scro11 Bars Rle - System Controls ore List Directory List ; Fle ist Time Imag e PictureBox Shape Line Data - L Custam cantrals custam contrals Visual Basic Com monDialog MSC ha r MSComm SSTa b Microsoll Mail Statu sBar ProgressBar Slide r Imag eList ListView RichTextBox Toolbar eeV Tr iew TabS
.
'-. ~
R
~~
n
rr.n rr.n m
~ "' ~ ' IIJ' ~
""
"'~ ~
rm :w n m m. .
n '!''
...,,;
m
lll
-
.. m't I'r.'!"t- --
Animation Multimedia _ ,----
~
-J
...
Microsoft FiexGrid ---------------------, -
.L2.
1IIi
K&tPlvo 10 -------------1111ii1 clipboard DDE-I
_
D --------------------------IilliI _ _
K~o l1 Datl Data Contral data control RecordSource Recordset data control, data control
C;oTItro l_
_-Iilill
_ _ --I _--Ii
Transactions - - -- - - - - - - - - - - - - - - - - - - --1 Bound controls _ Data Bound Grid control 1 Eo ---Ii L:
O
~iIIiII
-----,----------------Iiil.. _ -,-------,------------------IiIiiiI (Indexes) ---ii DD - - -- - - - - - - - - - - - -- -- -- 11 Visual Basic 5.0 ------------Iii D ---------------Ii
index '
-iilii
- --
-
-
-
-
-
-
-
-
-
-
-
(relations)
(Referential lntegrity) __
_
-------------- D D
SQLl (Aggregate Functions)
- -- - - - - - - -- w_ _-ii
D
DEETE
...
_
- - - - - - - -- - - - W__
-
K~o 13K_-,----iilil
l
(objecl)
l
l
_ _ _ _
--------------------IWI _ OI Kl -liII~
l ll (objecl hierarchy) --- ----- -- -sli ----------------------lilil~ Automalion Servers -------- ------- ------ililil w rd -5Ii
. -------------------lilliI Eol -liiI1IiI ---"''-&8'''0
Ac;ttveX
coJjtrol5
_
AcliveX controI -------------------liiI... ActiveX Interface controI Ward -;i l (Objecl Properties) -----------------lliiil Enum ----------------J1iI
Extender --------- ------ ----- -Ilii8 Ambienl ----------------------iliil oo
l
Internet
controls
-
~
..o...,.,,..
OCX control, _ AcliveX control ' ----------;,;; " " AcliveX control, -liI , .C .INF -------------------Ii~ AB Internet, fIilil ActiveX Oocuments ---- -----------------Si~ -II:.I~
K~o 15nwj l t er et ---IOIIIiJ
TCP/IP
--------- ------ ----l iii.. (PortS) -------------------lil0IiI Sockets ---li
Microsoft Winsock Conlrol ------------------liIiW Winsock, lnlernel transfer controls TCP/IP -------------Cii Clienl, -liI Server --------------------Cii Server -I1IOIi UDP --------------------IlIOIill Microsofl lnternet Transfer Control --------------~~1I --------------- ------11i1.. SECURE ---- ----------- -fIill FTP - - - - -- - - - - - - -- - - - - --c , --'=:.
K~o 16J)oj K,
Help ------------IiI_--1i11,;,
HeIp project
Help -----------------Ii _ help ------------------ help Visual Basic _ --'=c. K,
Crystul Reports
_
formula fields Crystal Reports Visual Basic
_ELL::
- --
-
-
-
-
-
------
~
_ _. _
__
--------------Im
IJII
Kefo 1.8I/5: :5C; ----- Windows (Window Class) O
- _--lilill-iilil
AddressO! -------------- -------ililiill .. U .......
X ll
A ctVe){
DocurneJItsVisual Basic 5.0
L.
AcliveX
Document.
UserDocumenl,
, , , '
OCX conlrol, AcliveX
Object BrowserObjecl Browser. TOl1lbar, Code Window , . Object Browser Visual Basic, ' , ,
coJItrols controls Internet Transler control.
5.0
,
MSChart, MSF lexGrid, UpDown, Winsock
. :
l
Typed Oplional
:
C+ +
Visual Basic.
Public Sub SetTime (Optiona l lTime As Long
=
10)
Asserts .
Debug (executable) .
Enums
AcliveX controls,
' .
Property
OplionaI
,
Properly Lel (Optional argumenls).
Property 6el,
Evenl,
,
,
ActlveX conlrol, RaiseEvent.
AddressOI ,
(pointer)
" " . u
Addre ssOf,
Professional
, ,
Visual Basic. , Hints &
, . ,
, - , . ,
.
Vi sual Basic 5.0.
r
E-mail: [email protected] 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.ionMi:i miz eBox
(
Clo~
MeDJB",.
~~!IIIIIII""EIlefd ~ ~e arch
t!elp
_ _~V etic ~ Scfol1 Bar
~ ClientAfe~. 1 .1 . Wndows 95.
Visual BasIc,
' .
1.1 .,
, .
Windaws,
, . ,
, ( ,
Visual Basic, F orm ( ), l Minimize Maximize . .) , controls, . controls textboxes, buttons , . OCX, Visual Basic, System ,
1
,
controls. , control , (fonts) .. , . ,
control
button.
, "" , , , .
button, ,
xr
1.2.: Fo rm1
I!lIiJDSub Comman l C!1ck( ) d
Object: j Coua
.&Wl!J
, ~ . ~ /;i. (j . ;j. $ 8
.; - ~ . " ~g
P ,
~~-'~ , '"~~
-> ...... ->MS Sns Setl
"..."... ",,,.",
::=::J
.
1.7. command bunon contr ol7
-
.
,
C.ncel C .ption
, u
control u
" ", u u
nou controI. u
access key, " A/t"
TOU u
,
"&", u control uu
+ ,, .
Def.ult
True, control u "E nter" .
,
(events)
cantrals
( , ) . ,
cantrals, text box cammand buttan cantrals. , : text box, caption command button , b tton caption . controls . 1.8. . . _ lal,
. """""'" :::: ..
~
: ' :
::.
.
1.8.
controls
.
, textboxcontrol. (
CodeW indow. 1.9.,
(Object) o ~ control, 1~1Pr l v a l;e 3
editor, editor . controI ( Name), (Proc) ' .
control),
_
J3
1 -~
J
T"xl;l_ Ch.. n",,, O
~
,.~
~..-
-
.
'. ;&
.
1.9. Code Window text box control8
-
events.
, ' ) , :
editor
(
Private Sub Contro lName-EventName () End Sub
ControlName
.
Name control, control
EventName controls
ControlName. Pr ivat e Sub End Sub
:
C o ntrolNam e-Ee nt N ame
(I ndex As Intege r )
,
control.
'
' .
Index Index controls event. O bject, control ' events ( 1.10)._tol )(1 !Cho
'rfffi'0ftj'$I ed1
=. ........,.m
~
,~~
~Iconlrols,
-: !
.
1.10.
.
(Name) Text1
events textbox control. control controls. eventChange, text box. :
Private Sub TextL-Change () End Sub
controls. , DblClick control, . event GotFocus control ( ) , , , LostFocus ( ' ) . events Change. controls , . F orm O bject, Proc events ( ) . . event Laad , . : . Clck
events
Pri v ate Sub End Su b
F o r...Lo ad
()
~
- -
-
- --
-
- --
-
-
-
-
Unload
. ' :
Pr ivat e Sub Form-Unl oad (Canc e l As Int ege r ) End Sub
Cancel , , Windows event QueryUnIoad.
. / .
C lick DblClick
. . .
MouseDown, MouseMove, Mous eUpKeyDown, KeyPress, KeyUp
. .
ResizePain t
. .
,
Change lext
button conlrol :Privat e Sub Text L-Change () commandl .Caption = t ext l . Text End Sub
controIs
, .
(read - write) .
(read only), Caplion command button Tex1 text box
control :
' . , ,
FormName!ControlName.P r o pe rty :
events
,
F onnName,
Cont ro l Name . Pr op e r t y
=
NewVa lue
conlrol,
:
OldValue
=
Cont ro l Name. Pr operty
. , , ,
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
butt n o
command2,
" " .
" " ,
Start
"F 5" Run Visual Basic. , , 1.1 1.I!!I~EJ
Fo rml
.
1.11.
, .
, , " "
Visual Basic.
designtime 1.1 2 . View Code codeeditor controls , Editor , ,
.i; F onl1 I!!I~EI
: .
-
.
1.12.
.
Lock Controls
" "
.
11
controls , Paste
clipboard,
, ,
Properties
.
" "
Visual Basic,
() ,
Visual Basic. . Save Project As... F ( 1.13.), ile, ( project1.vbp), vbp. , , Save Fle As... .Irm )>>
!f4#,
?~1
.
1.13.
.
, ,
File
vbp.
,
project
Open Prajecl... New Project . , mod-
u1es
( )
' ,
Project Explorer ( 1.14.). View Form , View Code events controls . , ( module ) , ( Name). , , , modules .!
Ei ! fl&:.1I! _Slt-':V1CI! v a e _~O oll
u
"U U U U U
Cb ) ee >:. Cb, ec>:. St.-':l no;1 St.-':lno;1 S>:.-.: lno;1S -': l nQ1
''''', . "... "..
C l> :. - 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
_ ! '
J
-
,. : '~. ~ r-~.? ~n_e :;.~I:'~A:""-"~.~ ,, ,, ~7 .,,~. n~
~
.
3.4. GlobaI .
Visual Basic =
.
,
Currency,
CCur:
Pa y Pe r Wee k
Cc ur ( hou r s * h ourlyPay)
(con-
version function):
Cbool CByte CCur CDate CDbl Clnt;
Boolean Byte
CLng CSng Cstr CVar C VErr
Long Single String
Curr ency D ateDouble InIeger
Varia nt Error
(array)
. ;
32
Visual Basic
Basic.
,
Dim
Redim.
, . . :
Dim
(4 0) ,
Con (lO ,15 )
41
.
11
() (l) (2 )
16.
:
256= 324=
100= 55
(40)
.
1 (
), :
Dim Ar (l
40 ) As String, :
Con (l
15) As I nteger
,
Declaration,
Opt ion Bas e 1 ,
Dim,
Declaration
module.
; , '
. ,
module
Dim
Declaration,
:
Dim DynArray() As I nteger
, :Redim Dy nArra y()
As Integer
( ) ,
Redim
S tatic
Dim . ,
Public Global Dim
Declaration,
j
modules
, :
Publ i c MyArr ay(45) As Integer , :
Public MyArray( ) As I nt e g e r . ( )
. , . EuX ,
Viusal Basic
Preserve,
Redim.
' ( ) , -
33
-
-
-
-
-
-
-
-
- --
-
-
-
-
.
' ' . ,
, :
Redim Pres e rve M yAr ray( UBound(MyArray ) + 1 )
. ,
UBound , LBound Erase (, - 2 3 2 232 -1 .
) .
(Long Integer)
Array,
. . :
Variant
Option Base 1Dim M Week, yMyWeek=
MyDay"Tue" , "Wed" ,1 1 1
Ar r a y ("Mon " .
"T hu" ,
"Fri" ,
"S at" ,
" Sun " )
MyOay MyDa y
=
MyWeek( 2 ) MyWe ek ( 4)
MyDa y MyDay
"Tue" . "Thu ".
Array
Data
Basic
DOS.
j
(Structures)Visual Basic
, ( ) .
Type
.
module.
,
Declaration Private. ,
. ,
Declaration module:
Type Sy stemI nfo CPU As Variant
Mm e ory As Long Di skD r i v e s ( 3 0) As St ring Cost As Cur rency End Ty pe
Systemlnfo . AllSys tem() As S ystemI n fo
:
Dirn M S y stern As S ysteml n fo , y
, , :
Systemlnfo.
MySystem. CPU
=
"4 8 6DX"=
My S yste~ Disk Dr i ves ( O )
"1.44
"
34
AllSystem(2) .CPU -
' 3 8 6SX'" 1.44 MB If
AllSy s tem(2) .OiskDr i ve s(1 0) :
AllSys tem(l)
=
M ys tem yS
. (
DiskDrives
) . . m
Declaration
Standard modl e, ,
Private
Public,
modle
. '
Form
,
Class modl e , . Systemlnfo ' Standard
module
:
Public Type Systemlnfo End Typ e
ET1um5
Visual Basic 5.0
enum,
' . :
Privat e Enum DaysO fT he W e k e Sunday = 1Monday
TuesdayWednesday
Thurs day Fr idaySatu rday
End Enum
1 Sunday, 2 (
)
Monday
. .
, :
Di m Week as DaysOfTheWeek ArrivalDate = M day on ! ArrivalDate < M day Then on){nj nv
(collections)
,
, . ,
ReDim.
, .
:
Pub lic co lURLHist ory As New Collection
Add
' :
co l URLHi s to r y . Add URLAddress
35
oi] :
Dim URLAdd re s s As Variant For Each URLAddre s s in co l URLH i story Debug .P rint URLA r e ss ddNe x t URLAdd r e s s
13.
- (Object l'l r l'l b r e ~)cantrols,
, ) .
oi] (
Visual Basic F orm1.
. :
Dim F As Fo rml F. Sho w
F
Form1 .
F orm1,
:
Dim F As Fo rml, F.Caption.
As Forml
=
~ New
title W
Show
, ,
F orm1 .
New
Dim. ,
:
Dim F As New Forml ,.
As New Forml
Show
F.Show
(instances)
F omn1 ,
. , :
ReDim fArray (2 0 ) As New Fo rml '
control :
Dim a ny Co nt r o l As Cont r o l
control ,
! bo:
Dim anyCo nt r ol As TextBo x , ,
controls.
.
. ,
36
Form1:
Ca l l
Sh owForm (F orml)
Sub Sh o wFo rm (for.mx As Fo rm) fo r.mx. Show End Sub
text
box control. Sub fillTex t
:
(Source As Cont ro l ,=
va l ue $ )
If Ty peOf So u rce Source Is Text Box Sou rce . Text va lue$
End I fEnd Sub
1I ... I
EIse11 ... I
control.
Visual Baslc 5.0
(
) .
NoKeyPress.
Declaration
NoKeys:
Pub l ic Ev e nt NOKeyPresses ( Key$ )
KeyPress
:
Private Sub End Sub
Form-eyP ress(KeyAscii
As Integer )
RaiseEvent NoKeyPre sses (Chr (KeyAscii
" , 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$ ) M sgBo x End Sub~ 1 \n
& Ke y$
> m ,
modules
(
Visual Basic bas),
(
37
Irm CLS ) , ,
OCX . events controls . (private) , module. public, . modules. ( ) (
public,
default
standard modules).
, , , .
Sub, Function ( ) Properly. Sub , , Property (custom) . Sub (procedure) .
[Pr i var e IPub l i c ] [Static ] Sub procedurenarne (arglist ) End Sub :
Sub Pa r s e Pa t h (file $, d %)End Sub ate , ,
fomn
standard module
,
. ,
Public , Slatic Private, '
, .
(default)
standard
module Public.
. (arguments) ,
. . :
(ByVal ] var i abl e n ame
[( )]
[As type]
" "
by reference. ByVal,
' , ' . ,
. " " , , :
Ca l l Reve rse ({ V), 5) :
Ca l l
Parse Path ( ~Dernon ,
al u e %)
Pa rsePat h "Derno " , va l ue %
38
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
m
SomeSub
Public '
module
F orm1,
, :
Ca l l Fo rml. SomeSub(a r g uments)
,
lorm module, Fom1 . standard modules public. ,
' , ,
modules,
module:
M odulel .CommonSub(argume nts),
Exl' Sub
End Sub.
Windows
(even's),
,
, . ,
. :
(resources) Visual 8asic Windows.
( , )
Pr ivate Sub Form-ev entname
(arg ume nnt)
End Sub ,
Form
eventname
, :
Private Sub FormLLoad ( )
F orm1 .
.
, '
button
controls , text box con'rol. :
Private Sub Co ntrolname-eventname ( a rgurnents) End Sub
Controln ame
control
, ,
.
Public Priva'e,
(unique) default
, , ' .
, .
Visual
8asic Sqr, Chr . . , . :
39
-
-
-
-
-
-
-
-
-
-
-
-
- --
[ Pr i v ateI Public] [Static] Function f unctionnarne ( argli s t } [As t yp e ] End Function , Prvate ,
Public
Static.
. , . ' , :fucti o n arne
=
retvalue
:
Func tion Exist
( fi l e $ ) As Integer
Exist = re t % End Funct i on :
ex% = Exist (filename$ )
Function
End F unction.
:
(property procedures) standard modules . , module . Visual Basic ' , :
read-only
,
. . ' .
Property Let Pr opertyGet Property5e!
,
Inverted
.
Public
module
:
Publ i c Inve rt e d As Boolean :
Forml.Inv erted
=
Tru e
:
V
=
Fo rml . Inverted ,
Private, module. . Private Islnverted re LeI :
Pr ivate IsInverted As Boolean
40
Property Let Inverted IsInverted = ! IsInverted Then El s e End ! End Property
(
As Boolean )
, j ' uj :
Forml. Inve rt ed
=
True
j .
Property Get.
Pr operty Get Inverted ( ) As Boolean In verted = I sInverted End Property oj:
Property [Get ILetISet ] [Static ] propertynam e [ ( arqument s ) ] {AS type] End PropertyXjo ,
Property Sel Property Let. ,
Property Get Names:
Property Let Names End Property
(
As Integer,
As Int e g e r,
As Variant )
Property G et
:(
Property Get Names End Property
As Int eger,
As Int e ge r) As Variant
: Prope1y [o bj ect] . p ro pe1yna me [(a rg u me nts)j
Le! Get 5et
= argument = vanable
Prop e1yProp e 1y
vanable - [objec prope 1ynam e[(argum ents)j t]. 5e![objectj .prope1yn ame[(arg umen ts)j
.
Property Sel Property Lel, , Visual Basic w, , :
j Kj . , ,
a, b,
c d
Demo ( a, b, c )
= d
"1
Property Le t Demo (w, End Property
,
,
)
,
praject PROP _IND.VBP.
Property Let Property Get, command b tton,
. , j , ,
text box label control
lndex . Label controI . lndex textbox command button, label . Declare , , intlndex, . .
Private vntDemo() As Va r iant Private intlndex As I nt e g er Load , , .
Private Sub Forffi-Load() ReDim v ntDe mo (l ) As Variant End Sub button.
Private Sub Comman d l_Clic k ( ) If Tr im$( t x tNewValue .Te xt)
=
~"
Then Ex i t Sub '
intlndex = intl ndex + 1 De mo ( i nt l nde x ) = t xtNe wValue. Te x t Labe13.Caption = i nt l n de x t xtNewValue.Text End Sub" .~(&r pot; ( ve u'
Let
-
" "'*
2
,_ .. 1" n:px{:o
1rJe" vv6c.o V
) IrcIe.
1_ 2_
rou!ndex
"""
...
I~ -]I
.
3.5.
.
,
Let Demo , vntDemo, :
- 42
Le t Demo (In dx As Intege r , Indx > UBou nd (vntDemo ) The n ReD im Pre serve vntDemo ( Indx) End Ifvnt Demo( I ndx) = End Prope rty
Proper~ y
As Vari an t )
button.
Privat e Sub -C i c k ( ) If Tr i m$ ( txt NewKey .Text ) , Get Lab el4.Caption End Sub=
=
n. Then Ex i t
Sub
1 0
Demo(Cl nt (txt Ne wKey. Text))
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 ntD emo( I n dx ) Demo End I f End Pr operty .
Trim$
Visual Basic m
'
aJ) aD~ naDaDw , , . .
Visual Basic - . Optional ParamArray. Optional,
, :
,
~ aOX l
ReturnTwice' E ~ o lE ~ ~
l 00~K6
a~6
Ret urnVa lue Re t urnValue
=
ReturnTwice () ReturnTw ice (2 ) , .
Null. 4.
,
O ~
IsMissing
6 Xl
Func t i o n ReturnTwi c e (Op t i onal I f I s M s sing (A ) The n i
)
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
Sub Sum ( ParamAr r a y i n t Num(
For Each
IntNum
=
+
Next Int Sum End Sub
=
Private Sub Command-Click ()Surn 3 . 6, 8 . 10 Msg Box CStr( IntSum )
End Sub Sum .
ParamArray.
For Each ,.. Next
Ti1U l JI ( .
2.3)
main ( DO main). S standard modle . , , , " " Command$ Visual Basic. Visual Basic VD. EXE :
C
VD C: \QVD \ SAMP LES \FIN l \ Em r i k. Ma k po
main
, :
Sub Mai n ( )file$=
Command$
End Sub
file$
. ,
main (
End),
.
[. vt"'UA I BA", tC' '
Visual BasIc,
, .
....
Ap~
Visual Basic. : .
Str$ %
Slr$
VaI:23
~
St$ - Str$(T %) % ~ Val( St$ ) + 12 0 0
Inslr, InstrB Instr
InstrB Target$ = Searchl$ Se a r ch 2$ Sear ch3$
v~
byte.
:
~Au " " " a "
a~ 1K N
"Vi sua l"Se a r chl$) Search2$} Search3$} 0 0 0
= I n St r ( Ta r get $, v = InStr(Ta r get$ , = InSt r ( Ta r g e t $,
6 16
Len, Lenb
Len . LenB byte. , , resul11 :
28 = =
String l resultl
"
l e n ( s t ring l )
Left, LeftB, Mid, MidB, Righl, RightB . , ,
left
Mid
,
Righl
.
, :
byte.
strinqlresult l
"
a l l K 6"
result2 r esul t 3
4) M (s tringl , 6, 4) id Right ( s t r i n g l , 6 )
Left ( s t r i ng l,
\ . " . " . .
" "
" "" . "
Space, Slring . , . , ,
Space
45
20 , S lring ASCII 45, 20 :
re su l t1 result2
==
Space (20 ) St ring( 20,45 )
Lcase, Ucase .
TrIm, L!rIm, R !rim .
Trim
.
Format u
Format
u .
:
Format ( expression [,
forrnat J )
u lormat u u
expression .
nou
nou lorma!.
. .
#
. . .
. - + $ () .
Visual Basic lorma !
("").
nou nou u , u
.'
.
G ,ner_1NumberCurrency Percent Scientific
10
. .
100
(%) .(Cntrol Pane ~ .
(s c i entfic ) . og _,
L _, ong M'dium _, ShM -, Lang Tim,Medium Time
sysl,m selMgs
dd-mmm-yy Shon _,
( . . 03--93) .
syst,m
settings
.
Shon Tim,
syst, msettings . sysl,msettings . , " " " ", "hh:mm /" , , hh:mm .
:
Dim M me, MyDate , MyStr yTi MyTime 1 17 :04 : 2 31 MyDate = IJanua ry 27, 19931
0 46
E~ ~
long time .
M St r y
=
Format (Time,
"Long Time" )
E~ ~
long dat e .
MyStr MySt r MyStr
Fo rmat(Dat e ,
"Long Date" ) "h : m: s " ) E ~ ~ "17 : 4 : 23". "hh:mm: ss "') 'E~ ~ "05: 0 4 : 2 3 \ Jan 27 19 9 3 "' .
Fo rma t( M Ti me, y Format (MyTime,
" .
\
"Wed.nesday,
MyStr
=
Format( M Date , y
"d ddd,
mmm d
" )o~ ~K
\ x ~ f o rmat , ~ ~ \ n St r $. MySt r = Format (2 5 ) , . . , "2 5''. Format( 5 45 9. 4, " , . 00" ) MySt r M ySt r Format( 3 3 4. 9, . 00 " ) Fo rmat (5 , "0.00% ") MyStr MyStr MyStr Format ( "HELLO"' , " < "') Fo rmat( "Th i s i s i t ", ">" )
1.0 1. E1 ~ E~1.E~ 1.
"5 ,459 . 40". "3 3 4. 9 0" .
'500.00 %'."hello"' . "TH1S 1S " .
E~ 1
" "
Visual Basic .
.
Date, Tme , Now . . ;
res u lt1 r esult2 result3
Dat e Time Now
~ ~ ~ ~ ~~
"2 4 / 9 / 9 7" "2 : 10 :44 " "24 /9 /97 2 : 10 :44
"
Day, Month, WeekDay, Year, Hour, Minute, Second . [ :
,
K ~
n
Da t e
1.~
24 /9 /9 7
,
n Time
~1
2 : 10 : 4 4
result1 r e s ult 2 r es ult3 r e s ult 4 r e sult5 re s ult6 r esult 7
Day (Dat e ) M nth( Da t e) o Week Day( Dat e) Year( Da t e) Hour (Time) Minut e(Time) Se c ond(T i me)
~~ 1 ~ 1. ~ ~ ~ ~ ~ 1. ~
24
94,
1997
210 44
~ ~
DaleSerial, TmeSerial DateSerial
,
47
. TmeSerial. l ( 1)
Visual Basic
,
, : m .
. . m .
Sin.
e (
) .
LogSqr
. . . .
Randomize
Rnd
nvv
MsgBox,
'
. , , . :sg (rmt
buttons J [,
t itle])
,
prompt title . prompt chr(1 3) & chr(1) (vbCrLf) ~ L i ne l n
, :
M g Bo x s
& v bCrLf & nLi n e2 " & vbCrLf &
~ L ine3n
buttons
, . defau~ ,
:
.
12
C.ncel' Ignore.
b , Retr
34
Yes,
CanceI.
5
Y , es Retr C.ncel'
, :
48
.
1
23
Cance1. Abort. Retry. Yes.
4 5
I,.
7
.
, l $ :
I nputBox$ ( prompt [, t itle J [,
defau l t J [,
]
[ , ] )
pr ompt
ttl e . defau ~ , . ,
3.6.
dim r c rc = nut $( ~ aaa vbCrLf & v bCrL f & UMn ~ 10 a " " , " . " , , )Io:/;J rpooy:rte cme . Mro( t ree (.
.
& _
."
, _
13
.
3.6.
l t $ .
tt
p r r
l>oEveJIt s
( ) , , ,
16-b! .
,
OoEvents. 32-b! Windows 95 "preemtive multitasking". Window$ 3 ., , ""
OoEvent$
standard
.
DimFo r
,
OpenForms=
1
1 5 0 00 00
Ope nForms Next
= DoEvents \
.
"9
1. 1 .
. :
Basic, 11 ...Then ... EIse, Do For,
Basic. , 11 ... Then
Visual Basic
:! !
Conditi on The n s t a t ement
Condit ion The n[ s t a teme n ts ]
End If
Condition , True F . , condition True, Visual alse Basic Then. , . condition F alse , ! ... Then ... E lse:
If Conditi onl Then[ s t a tements l ]
Elself cond i t ion2 t he n[state ments 2 ] Else
[statements3 ]End If .
E lself. . , 4 command button controls event Click, :
Sub Command1-Click (Index As Integer)!
Index
=
Then
Elself IndexEl s el f I nde xElse
1 Then2 Then
End I fEnd Sub ,
myDate:
Su b FixDa t e()
oim myDa t e myDate - # 2 /13 / 95#
50
If my Da te < Now Then myDat e End Sub
=
Now
Elself , SelecI Case. , , 1 I boolean. :"")
If (age < 16 And sex =
Or
( a g e > 14 And s ex = "F") Then
BlE1se
- 10
BlEnd If
:1=
(age < 1 6 And sex
=
~M " )
Or ( a g e > 14 And sex
=
~F ")
* 10
Select Case Visual Basic
1 ... Then ... Elself, Select Case, I
. :
Sele c t Case test e x p ress ion Cas e expres si on l [ s t atements1 ] Ca se expre s s i on2 [ s t a t e men ts2] Ca se El se [stat eme nt s 3 ] End Se lect
Case. , Case Else. , :Sub CommandL-Clic k ( I ndex As Inte g e r)Se lect Case I ndex
Case
Case 1 Case 2 Case E1s e End Se 1e ct End Sub
.
Visual Basic
51
Do ...
FO
... Next.
Goto,
-
,
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 % = 1l a b:
fi nd% = I nStr (po sition, s t r i n, If f ind% The npo s it i on = InStr(position. CSt ring% = CStri ng % + 1 GoTo l a b End I f CountSt r ing CSt r i ng %
t arget )st r i n, t arget) + 1
End Func t ion . :
...
Functi on CountSt ring ( s t rin $ ,
t a rget$ )
posit ion% = 100fi nd%=
InStr (po s i tion,
s t r i n,
targe t )
I f f i nd% = The n Exit pos ition I nStr( po s i tion, CS t r i ng % = CSt r i ng % + 1 LoopCountSt ring=
str in, target ) + 1
CSt ring %
End Function
...
While
:
00 W hile condition ( s t a t eme nts ]
Loop condtion m
(True),
False () .
:
Function Count St r ing ( s t r i n$, target$ ) posit ion % = 1
Whi le I nStr( p os i ti on, p os ition CSt ring%=
st rin,
target ) s trin,
I n St r( p o s i t i o n , CString % + 1
52
t arget) + 1
LoopCountStr ing=
CString%
End Function :
00 ... L,
[statements)
Loo p While condition j9 _~ _ poppg
F alse
Tre .
9
Unt i l condi t ion [statements) Loop
[ s t a t e me nt s ]
Loop Until condition
For ... Next,
:
Fo r co unter
=
s t a rt
end [Step in crement ]
[ s t a t e me nt s ]
Next [counter]
counter
( ) ,
end,
increment.
, . ,
ment.
counter end increFor . , ( $, $)
$ $ :Function Del imite r Dim k As
Integer,=~"
i As Integer
I f Tr i m$( A$)Fo r i=
Then Exi t Funct i on
1 Le n (A$ ) I f Mid $ ( A$, , 1) - BS Then k - k + 1=
NextDe l im i ter k + 1
End Function
For ... Next For Each ... Next, (collection) .
:
For Each e lement [ s t a t e rne nt s] Next [elemen t ]
1
g roup
text,
:
Found = False For Each MyObject
1
MyCollection~ H l lo "
If M Ob j e c t. Te x t = y
Then
53
Found "'" True
Exit ForEnd!
Next
M~oo (Mettods) VT ,
controls
:
(forms) controls, (properties)
events. control. ,
[Ob jec t . ) Method [Farameters]
O bject
(name) . object form
,
Cls:
[Fo rm. ] Cls . ,
F orm
. :
Cl s . :[ .
Hide
,
] Hi de
:
Show,
[ fo rm. ]Show [s tyle]
style
,
modeless
1
modal.
, .
modal
modeless. modeless, Show, modal. m , Visual Basic
. , . ,
, , :Sub Commandl_Click () Di rn Msg HideMsg "'"n ~ ~ ~
n
MsgBOX Msg
ShowEnd Sub
controls SelFocus
:
object.SetFocus
54
control events, () (
!
.
" " .
Basic,
,
Visual Basic
Quick
Basic
, ,
, , , control . Basic , (sequential), (random) (binary) . , , random disk, . .
(records) . 24. , , , byte-by-byte. , Visual Basic : 25
Open, ,
!
# , ! # , Wroe # , pS , Close!
Type ... E ndType, Open,
# , Len, Close, Get #
Open, Get # , ! # , Close, Seek, Input$
Open,
:
pathname For mode
[Access access ] As
[ #]file number [Le n=recleng t h]
pat!lname
,
made Append, Binary, ',
Outpul Random. access (Read), (Wri'e) (Read WrIte)_ filenumber FreeFiIe. , Len random ' . pa'hname , Append, Binary, Random mode. , Print # ' .Ope n Pr i nt~ T ES TF I LEn
For Out put As t 1
V10
.
1 1, Print 11, Print 11,Print ' 1, Pr i nt # 1,
"Thi s is a t est "
.
; .... ; "Worl d" Spc ( 5 ) ; "5 l e a ding spaces"e "
Tab(1 0) ;
' "
1110 . s t ring s . 5 . 10.
Dim MyBool ,
M Dat e , y
MyNull
55
MyBoo l
=
Fa lse : MyDate
=
t Februa ry 12 , Bo 01ean 1. dat e 1. " nu ll 1."
19 69 1 : M yNu l l
Null
Print #" 1, 01 yDate Print #1, M Pri nt #1, My Nul l Clo s e ' 1 ed= Then Ca llOpenFi l e((mnuFileArray ( Index) .Caption End If End Sub
Click Y1Q
me nu controls
menu
menu b a r. P r i v ate Sub mnu F il e ltern-C l ick (Index As Integer) Erro r GoTo errhandler - Se l e c t Case I n dex Case index = , K ~K
~ N ew "
X~K
l
t e x t box
Kl
l
caption
t xtEdi t.Text = ~" Fi lename = ~Untitled" frmE ditor. Caption = "T ext Ed i t o r : Case 1 i ndex = 1,
" & Fi lename
" .
.. "
l .
control CMD ialogl,
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
~x
As... 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 . Sub mnuFont Sizes ltern-Cli c k ( I nde x As Int e ger ) Se lect Case I ndex Case I ndex = 12 t xtEdit. Font. Size = 12 True mnuFo ntSizesl tem (O ).Checke d mnuFontS i zes l tem ( l ).Checked Fals Case 1 I nd ex = 1 t xt Edlt. Fon t .S lze = 24 mnuF ontS ize sltem(O).Che c ke d mnuFontSiz e sl t em(1).Checked End Se l e ct End Sub ,
24
Fa l s e Tr ue
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 Case 1 ' txtEd i t . Fore Co l or Cas e 2 , End Sub x ~
RGB(255,=
,
)
RGB(O,
2 5 5,
)
K ~ K
K ~
submen u
End Sel ect
OpenFlle CloseFile , tet box , , , UpdateMenu controls menu controls, menu items . Teted it.Bas . tet
box,
Dim ArrayNum As I nt e g e r Glob al Filename As String Cons t MB_YESNO = 4, ~CONQUE S T ION = 32 , o~ K~
D
=
7 , MB-DEFBUTTON2t e x t box
2 56
~
. x ~ o~ x .
~
K ~
menu i tems
n UpdateMenu menu .
~
V ~ K
Sub OpenFile (Fi l ename As St r i ng) Dim F As Int e g e r If "Te xt Ed i t o r : " + Filenarne frmEd itor. Capt ion Then Exit Sub Els e Error GoTo Er rHandler 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 ~
~
.
8 3
t e xt box VB Dir$
1
1
.
1
MsgBox
(Oerwrite ) .
Sub Close File (F ilename As St r i ng ) Dim F As Integer Error GoTo CloseEr ror!
Dir (F i l ename) ~ " Then r esponse = MsgBox (~Oe rwr i t e e xisting f ile? ", MB-YESNO + MB-QUESTION + MB-DEFBUTTON2 ) ! respons e = Then Exi t Sub
End ! F = Fr e eFile Ope n Filename Fo r Out pu t As F Print #F, f rmEdit or! t xtEdit. Te xt Close F Filename = ~Unt itledN Exit Sub CloseError: MsgBox ~BK , Exit Sub End Sub 1 1
1." ,
48
mnuFileArray. c ont r o l
menu co nt rol s Caption controls 1
1.
1 1
1
separator bar,1 1
1
Visible1
True.
ArrayNum
. 1 110
capt ion 1
1 0
co nt ro l
1
, ,
Load 1 0 men u control mnuFileArray, 1 1 1 Caption 1 1 1 .
Vis i ble
Sub UpdateMenu () frmEdito r!mnuFileArray(O ).Vis ible ArrayNum = ArrayNum + 1 For i= !
True
Ar rayNum - 1 frmE ditor!mnuFileArray (i ).Caption ArrayNurn = Arra yNum - 1 Exit Sub!
Fi lenarne Then
End Next i
Loa d frmE dit o r !rnnuFileArray(Ar r ayNurn) f rrnEd itor!mnuFil eArray(ArrayNum). Capt i on frmEditor!mnuFileArray (Arr a yNurn ).Visible End Sub
File name Tr ue
1. v v v Vsual Basic; 2. v Submenus; 3. v v v; vrr. 4. v access;
1. ' 3 menu items. , CaptIon captIon menu item. , BackGround ( Rgb). , , .
2. ' . text boxes controls (name ) Surnmame Name, random , command button . , menu item, Caption Surname control. , ' menu item, random textboxes controls . , , .
85
-
-
- --
- - - - --
----
Murttpre - DocurneJjtIJjterffCe
(MDI)
,
Multiple - Document int rface (D ) (docue ments) (D form) . Program Manager File Manager Windows 3.. child, MDI, , . child MD/Child True, D . C hild, , D desktop Windows ( 5.1 .).
ji ", NolePlId
1!!I1;]~
work$pace
MOI
Minimzed chidwindows l
.
5.1 .
child
.
child,
standard,
.
87
- - - -- - - - -- - --
-
-
poj D
multiline textbo controI. D menu document. :Privat e Sub New_Click ( )Dim Ne wDo c As Ne w Fo rml cn=
,
child F 1 , ' New,
forms .Count~Formn
Lo a d NewDo c
Ne wDoc.Caption NewDoc. ShowEnd Sub
+ Trim ( cn )
Count
caption , modal. NewDoc F orm1 ( New Dim, ) events , . , ,
' . F _Resize :
Private Sub Form-Resi ze ( )Te xtl.Top= = = =
Textl .LeftTe xt l .Width End Sub
Te xt l . Height
Sc aleHe ight Sca leW idth
text bo
.
Form1, ,
:
Fo rml. Text l .
=
' , :
Me. Text l .
=
, ; .
module
:
Publ i c NewDoc( ) As New Forml ,
MDIForm_'-oad
:
Pr i va t e Sub MD IF or.m-Load ( ) ReD irn NewDoc ( O) As New FormlLoad NewDoc ( O) NewDoc( O) . CaptionNe wDoc ( ). Show=~ Formo n
End Sub
88
:
=
UBo und ( Ne wDoc ) + 1Presere
Re Dim
NewDo c(i) As New Forml=~Form"
Load NewDo c(i) NewDo c(i) . Caption NewDoc( i) .Show
+ Trim( i)
child
, .
. , ,
Document.
. Tet1 _Change tetbox:
Pr ivat e Sub Text l-Change () t extl .Tag = -" 1" End Sub
Form_Unload. Tag tetbox , 1, . Cancel True, :Privat e Sub Fo rm-Unl oad (Cancel As Int eger) Di m M As String sgrf t ext l . Tag=
,
"1 " Then "
M sg
=
"
& Me .Caption & "
~
o~"
Re sp Onse = MsgBox (Ms9,
51 ,
MDIForrnl. Cap t i on )
Sele c t Case Response Ca se 7 Fals e Cancel Case 2 Ca nce l True Ca s e Else End Se l ect End I fEnd Sub :
Arrange,
Documents
, .
MD Iform.Arrange arrangement arrangement .
D
vbCascade vbTileHorizontal vbTileVenicalbang eJ cns
child child
. .
1
23
KOTOKpuo D
child . .
89
chiJ d
,
vbCascade,
vbTileHorizontal vbArrangelcons
MDI child.I!I~
.. D No!ePad
EJ
.
5.2.
bCascade D
chiId.
,i : iI ! ' Itt ::t\
_ l 'Q6:m ~ndow
fie
~d
~e.sch
f 'lfflt!ffi f
.
5.3.
vbTileHorizontal
D
child.
_ l l l:
.
5.4.
vbArrangelcD ns
ch ld .
Restore ,1
MDI child :
Sub Re s t ore ( )
For i
=
Forms .Count - 1=
If Forrns(i ).MDIChild
True Then=
Fo rrn (i). WindowState s
90
End If Next End Sub
Minimized
:
Sub M imized ( ) in For i = 1 Forms .Count - 1 I f Forms(i ) .MDIChild = True Then Fo rms ( i ). W ndo wSt ate i End I f Ne xt End Sub=
1
-
toolbar
Toolbar standard
,
. [ bitmap ( control Align, bitmap standard controls ) , ' buttons . , custom toolbar control. , buttons controls, . , Glick buttons :
Pub lic Sub B-Too l b a r_Clic k (Index As Integer) Se le ct Case I n de x Ca s e Cal l NewDocument Case 7 Call Cont e nt s_Clic k Ca s e 8 Call p r inte r_ Ca s e Else End Se lect End Sub
.
5.5.
toolbar
91
Mdi.Vbp.
l
MDIMDI, ,
5.6. MDI
PaInt,
.
, . , .
Mdi Child,
bitmap control
( ) .
.
Control .
,
BorderS tyle bitmap control
Resize
MDI
:
Pr i v a t e Sub MD IF o r rn-Re s i z e() Center Fo rm Form l End Sub
F orm1 Mdi Child, MDI :==
CenterForm
Sub Ce nt e r Fo rm (frm As Fo rm ) frm. Leftfrn.
(MDIForm l. ScaleWidth (MDIForml . ScaleHeight -
frm. W dth ) \ i frm. Height) \
2
2
End Sub ,
Activate
:
Pr ivate Sub Forrn-Activate( ) ZOrde r 1 Refresh End Su b
Zorder 1, .
.
5.6. bitmap
92
M DI.
. 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
[
, . , .Cls!
Visual Basic
' ,
.
,
controis, line shape, . cantrols ( image) (focus), hWnd,
. , , ( ),
picture control ,
,
printer object.
:
.
print object. debug objecI.
.
Pset !
(pixel). print object.
. . , .
LineCircle PaintPicture
( . ,
.WMF, .ICO
. . ) ' VKo
F orm, PictureBox, Printer.
, (
) ,
Paint
,
. , , ,
AutoRedraw
True.
Command1_Click command button, object ( , Visual Basic
controi, ov
, .
,
Visuai Basic.
.95
-
, , , , .
Left,Width Height
controls,
. ,
x-axi$y-aK i$
()
..
.. CI>Ofd, rate S, sIelfl E x"nple
1![!]3
() . : ':.:':" . Fme
: ... 1
"
.
6.1.
.
, , .
(0,0).
'
, .
ScaleLeft, ScaIeTop, ScaleWidth ScaleHeight defauh .
Scale,
defauIt twip, 1/20 , , 1,440 twips (inch) 567 twips 1 (cm). , ScaleMode, :
vbUser (~O)V bTwips( ~ 1)
ScaleHeight, ScaleWidth, ScaleLeft ScaleTop .
Twip (Oelaul!).l
VbPoinls(~ 2)VbPixel s (~3)
(72 nl
) .
Pixel (
) .
VbCharaeters(=4) Vblnches(= 5)VbM i l lime!ers ( ~6)
/ . ~
120twips
= 240 twips .
(Inch). (Centimeler). (
( M ll imete r).
VbCenti eters(~ 7) m
,
.
DrawWidth 1 (default)
pixels)
( )
32,767.
ScaleMode, , Circle, : ,
Pri vat e Sub Form-Clic k ( ) , 1 1 ScaleMode . ScaleMode = Sc ale M e + 1 ) M od od 7) + 1 , 1 1 ,
96
2.
Circle (ScaleWidth / End Sub
2,
ScaleHeight / 2 ) ,
2
l,} , ' Crren
CurrenlY,
' . :
( ). i .
CircleL
Print Pset
.
. :
RGB
RGB (re d,
green,
blue )
255 ( long integer) .
:
RGB
: )
RGB(O , ,
RGO(O , 255) , RGO(O, 255, ) RG B(255, ,)
RGB(255, 255, ) RGB(255, 255, 255)
,
OBColor,
RGB
,
16
OickBasic.
15
:
Forml .BackColor
=
QBColor ( 15 )
Psel . :
[object. ] PSe t
[Step]
( ,
)
[, color]
, , .
Crre n ,
Step Curr entY RGB
color
97
Q8Color.
, .
Dr awWidth
. ,
DoE vents
, .
Pr ivate Sub Form-Paint ( ) Dr a wWidth= 5
XPos YPo s
= =
300 + Rnd * 4 0 0 0 2 0 0 + Rnd * 4500
PSet (XPos . Events Loop End Sub
YPo s ) , QBColor (Rnd * 15 )
Line . :
[obj ect. ] Line [[St e p]
( 1 ,
1 )]
-
[ St e p]( x 2 ,
2 )
,
[ ,B[F]]]
Step CurrentX CurrentY. 1 , 1 , 2, 2 . color . , F oreColor. 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!!:!
... FoIml
r
.
6.2.
98
Line.
-
-
-
- - --
-
- --
-
- --
:
Priv a t e Sub Form-Clic k ()
Cur r ent X Cur renty
15 0 0 500
Line -( 3 0 0 0 , Line -(15 0 0 ,Line - (15 0 0 ,
2000 ) 2000 )500 )
End Sub
!
picture control.
:
[o bject . ] Point(x,y ) , .
objec!,
-1.
.
Priv a te Sub Fo rm-Cl i c k () Dim Le ftCo lo r , MidColor ,
Msg,
RightColor
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) - ( W d t h / 3 , Height) , , BF \ 1 n 0 1 0. i Forecolor = QBCo! o r ( 1 5 ) , for eground . Line (Wi dt h / 3 , ) - ( ( W idth 3 ) * 2, Heig ht ) , , BF. LeftColor = int . ) \ 1 0 ~ o . MidCo lor = Point(Wi dth / 2 , Height / 2 ) \ 1 . 1
Right Co lor Mg s Msg M sg Mg s Msg~T o
=
Po int ( W dt h , i
Height)
,
~
1 0
1 .
1
1
Msg & ~ ~ & Le ftCo lo r & " , ~ Msg & 1 ~ Msg & MidColor & - . ~o Msg & 1 1 - & RightColor & - # \ 1 nv
MsgBox M sg End Sub
Eiiiiiiiiiiiiiiiiiiiiiiiiii1
.
6.3.
.
99
CircIe , . :
[obj e ct. JCi r cle [Step } ( ) , radiu s [, [co lor} _ [, [start] [, [e nd) , aspect] ] ] ]
Step
,
C rre n ,
.
CurrentY. (,) radius , color start end (radians)
, . -2 2. d efau~ .
aspect (ratio) . default 1 . , FillCoIor FillStyle.
.
Private Sub Form-Clic k ( ) Sca! e M ode : 3 '\ . . , ) },
p ixels . .
.
Fil lStyleCircle
=
:
Fi l l Co l or50 ,
=
RGB ( O.. ,
255)\
,
Ci rcle ( 25 0 ,
1 0 0) , 10 0 ) ,
50 ,
RGB( 2 5 5 , RGB(2 5 5.
,
,
1 / 3 \
l.
End Sub.. FoIm lI!I~EI
8 .
6.4.
.
, :
Form_Click
,
Pr ivat e Sub Form-Clic k () Cons t = 3. 1 4\ 6 Fill Styl e = : Fil1ColorCirc1 e ( 15 0 0, Circ1e ( 3 5 0 0 , 15 0 0 ) , 15 00), =
,
RGB (2 5 5 .-
255 )- -
1 0 00 , 1000,
,
-
/ 2, / 3,
/ 3 / 2
l.
End Sub
100
-
"i
FoIml
1 !!IIi1E3
.
6.5.
v
FoIm_CIick.
PaIntPicture (. , '
.WMF, .EMF .ICO .G . . ) , IF 2, 2 ,
Form, PictureBox, Printer. 1,
:
object .PaintPicture p i c t u r e, width2 , height2 , opcode
yl , width1 ,
he ight1 ,
_
l1.
pIcture
Picture
PicrureBox control. opcode
, 1, 1
width1, height1
2, 2
width2, height2.
.
bitmapFo r i
,
=
100 10
PaintPicture pIcture controls. picture control:
Fo r j = 10 Forml . PaintP icture pi c F. Picture, picF .Width, Next j,i
j * picF . W idth,
i
* p icF. Height , _
- p i c F. He i g ht
[ . - .
default
DrawWidth DrawWidth pixels Line, PSet Circle. , , DrawWidth:Private Sub Form-C li c k ( )
Dim
,
i
- - - - - --
-
-
-
-
-
-
-
-
1
For i
12 Step 2 + 400 DrawWi dth = i Line (2 0 0 0 , 10 0 + )-(5 0 0 0. Next=
1
=
10 0 +
)
End Sub
.. ForIIl
1!!I~E3
.
6.6.
Form_Click.
DrawStyle DrawStyle Line . 6 :
Pr ivate Sub Fo rm-Cl ic k ()Dirn i ,
For i = 6 DrawSt yle = i =
( 2 0 0 * i ) + 10 0 0
Line (2 00 0,
10
+
) -(50 0 0 ,
10
+
)
NextEnd Sub.. Foml
I!II!JEJ
.
6.7.
Form_Click,
FillGolor
FillStyle
' , ,
1 02
-
(
.
(solid)
F illStyle 7 . F illColor, 1 (default) F illStyle, 6.8.
Circle Line),
.
F illColor.
Private Sub Fo rm-Click ()Di m i .=
For i
7= =)
=
( 80 0 * i ) RGB( 2 5 5, , i ( 1 0 0 0 + , 1500) ,
Fi l lCo lor Fi l l StyleCi r c l e
35 0
NextEnd Su b
.
6.8.
FiIISIVle.
DrawMode .
16
,
7 (Xor Pen)
animation,
, , , . , .
Pr ivate Sub Form-Click ()Dim i
Fo r eColor Fi l lCo!or Fi l l St y leDr a wM de o=
==
RGB (255 ,Fo reColor
,
}
=
27
For i = 1 5 0 0 0 Step 10 Ci r cle ( i, 1500) , 500Circle(i ,
1 5 0 0) ,
5 00
DoEv e nt s
NextEnd Sub
1 03
-
Scale
'
,
ScaleLeft, ScaleTop, ScaleWidth ScaleHeight default . , , bitmaps object printer. ScaleLeft ScaleTop
.
(100, 100) .
Sca l e Le ft "" 10 0 Sc aleTo p "" 100
controls
,
Left. ,
form_CliCk,
com-
mand button controlDim
.
Pr i vat e Sub f o rm-click ()
=
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
. , :
Sca l e Width
= =
1000
Sc aleHeight
500
1/1,000
. .
1/500 command button cantrol,
Privat e Sub f orm-c l ic k ()Dim
,
= commandl . W ctt h i sca l ewidth = sca lewi dth - 10 0 command l . Widt h =
= commandl. H i g ht e s cal eh e ight = s c a l e he i g ht - 100
comman dl .He ight End Sub
=
default
'
, .
104 -
-
ScaleWidth ---
-
-
-
-
-
-
-
- - --
ScaleHeight Sc a l e H eight=
. , :
- 100
. :
Scale,
[ob ject. ]Scale
[(,
)
-
( 2 ,
2 1 ]
( , 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 W d t h = 8640: Height = 57 60 i \
Move 10 0 , 10 0 \
OldFontS iz e\ \
=
FontS izebackground
BackCo lorScale For ( ,
=
QBCo lo r (7 )
=
110 ) - ( 130 , ) 10 0 10 St e p -10
l Ou Line ( , 1 ) - (2 , ) Cur r e nt y = Cu r r e nt y + 1.5
10
Print Line ( Sc a l e W dth - 2 , I) -( Sca l eWi dth, i Curre nt y Curr e nt y + 1.5 Cur r entX = Sca l ew i ctth - 9 Print
)
Next\
X lO U
Line (10 , Line (20 ,Line Line Line Line 14 0 ,
0 )- ( 20, 0 ) - (30 ,0 ) - (5 0 , 0 ) - (60 , 0 ) - (80 , 0) -(90 ,
45 ), 55 ) ,4 0) , 25), 35) , 60) ,
RGB(O, , RGB(255 ,RGB( O, , RGB(255 , RGB( O, , RGB( 255 ,
bars 255 ) ,, ,
BF BFBF
255 ) ,, ),
(50 , (7 0 , (8 0 ,
255 ) ,, ),
BF BF BF BF BF
Li ne (1 0 0 , Line (11 0 ,
0)- (110 , 0 ) - ( 120,
75 ) , 90 ),
RGB( O, , RGB( 25 5,
2 55 ),, ,
1 05
-
CurrentX
=
18 : Currenty
=
100Y 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 Li ne End Sub ( 29. ( 43 , 86) -(3 4. 86) -( 4 9, 88) . 8 8), . .
2 5 5)., ),
RGB(2 5 5,
BF BF
Widget Quarterfy SalesPIotnodv,Ao.>uoI
--
.
6.9. B.r ch.rt
.
Visual Basic, ( caption controls, text box control) ! m , bitmap control ! ( m design debug). , Font.Name ( ) , Font.Size ( ) ..
, (
(
Courier). , , object Screen) ' ( abject Printer).
, , :
Pr i vate Sub Fo rm-Cl ick () Fo nt .Name ~Modern" 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 Fonts .
,
Screen Iist box
. ' ,
object Screen.
Private Sub For.rn-Click ()Dim=
For
Printer.FontCount - 1()
Listl.Addltem Printer.Fonts Next End Sub
,
F ont StdFont:With MyFont Name ''Arial''
Dim MyFont As New StdFont
Size Bold End With
10 True
, :
[object. ]Print expressionl istJ [{ ;
.}}
1 07
-
":" "."
; ,
, , ( ) . , :
14
~Basicl " ;:
Pr i nt -Basic2"
:
8as iclBas ic2 :
Pr i nt
"Ba s ic l ", : Pr i nt "Basic2"
:
Basic l Ba si c 2 C en , :
(0,0)
,
CurrentY,
Private Sub Form-ClickCu r r e nt X Currenty Print End Sub
)
=
ScaleWidth / 2 ScaleHeight / 2
"Hello VB 5.0 "
. , , TeXHe ight :
TextWidth.
[obj e ct . ] Tex tHeigh t( s t r i nge xpress i on ) :
(ob j e c t . ] TextWidth (stringexpression) . , , .
t
ForeColor
B ackC olor.
Pr ivat e Sub Form-Cl ick ( )Dim Hal fWidth, Hal fHeight , Msg
Cl s ForeColo r = RGB(255 , M = "Visual Ba s i c " sgFo nt . Si ze Hal fWi dt h=
,
)
48 TextWidth (Msg ) /=
=
2
Hal fHe ightCurrentX=
TextHe ight( Msg ) / 22 HalfWidth
ScaleWidth /
1 08 -
-
-
-
-
-
-
-
-
-
-
- -- --
-
Cu r r e nty Print Msg End Sub
=
Sca leHeight /
2 - HalfHeight
. !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 Fo nt . S i ze
"MS Sa n s se rif" 10 Tab (22 ) ;" "
Print Print Tab( 2 ) ; ' "; Print String$ ( 62 . .... _" ) f i le$=
Dir$( .... * .
*)
While fi le$ "" i = InStr(file$ , - . ") ext$ = Mid$(file$ , i + 1 ) Select Case UCase$ (ext$ ) Case " " Desc$ = .... " Cas e . . .. Des c $ = Cas e "HLP"" K ~ 1 o "
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 Sub1 1 $ ,, " I. j #.!Qvu
k&
_Io l xl
trfjgOver
O DropMode, OLEOragO LE ver target, . :Sh ift As rnteger,
Private Sub Forrn-OLEDragOver(Data As Da t aObj e c t ,Int e g e r , As Single,
Ef f e ct As Long,
Button As
As Single ,
State As I nteger)
,
G etFormal. , DataDbject Effect : i
VbDropEftectNone VbDropEftectCopy VbDropEfteclMove VbDropE fteclScroil
Drag and
yiVEl.
.
yiVEl
.
.
,
.
Shift, State :
VbEnter VbLeave VbOver
Sour control target. cecon trol
SOU ce
target. target ,
Source control
target.
OLEl>rfjgl>roptarget,
O LEDragDrop.
G etData,
. :
Private Sub Form-OLEDragDrop(Data As DataOb ject , Effec t As Lon g , I nt e ge r " Sh ift As I nt e g e r , As S ingle , As Si ngle ) Textl .text End Sub=
But ton As
Da t a . Ge t Da t a (vb CFTe xt )
OLEDropEffects. OLEDragO ver. dragdrop.vbp textbox control , image control o pto buttons controls ( 7.4.). Image Stretch True, Multiline textbox control.
Effect
,
Shift, ,
1 30
-
lIIri
foIm1
I!!I[!]E'JrNone
DRAG DD
M O$Ol!: Vi u31 Ba,oc icr s
noI >..rlOOtptI Drag t. ,.
Dr gMode . Drag a lcon '({'- Dr gDrop a 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 Private Sub Form-OLEDragOver(Data As DataObject, Effec t As Lo n g , Button As Integer, Shift As I nte g e r , As Single, As Single, State As Integer) Effect = m-e ff e c t End Su b Private Sub Op t i o n l _ Click ( ) m-effect = vbDropE ffectCopy End Sub Pr ivate Sub Option2_C lick() m-effect = vbDropEffectMove End Sub Private Sub m-effect End SubOpt ion3~Click()
=
vbDropEffectNone
1 31
-
, ,
WordPad . , Textbox Image control. Microsoft Windows Paint L Drag and Drop.:
L
Orag and Drop, MouseDown source control. :
O LEDrag,
Priv ate Sub Fo r.m-MouseDo wn (B utton As Inte g e r , As Sing le , As Singl e) Forml .0LEDrag End Sub
Sh ift As I n t e g e r,
OLEStartDrug OLEDrag
source
control ,
OLEStartDrag,
:
Pri v a t e Su b Fo r rn-OLESt artD r a g( Data As Da t aOb ject . End Sub
Allo we dE f f e cts As Long )
, ,
Data, DataObject. AllowedEffecls
L
Dragand . O DropEffects. : LEAll owe dEffect s=
Pr iva te Sub Fo r rn-OLEStartDra g (Data As Da t a Obj e c t ,
Al lowedE ffects As Long ) vbDr o pEf f ectCopy And v bDropEffectMove
End Sub
.
DataObject Clear, files, G etDala, Gelformat SetData,
Clear
DataObject /
Files GetData G etFormat SetData
u
VBFilesFormat.
nou u
Clipboard U / DataObject.
O ataObject.
DataOb ject.
O LEStartDrag,
o~oo
SetDala,
. :
Pr ivat e Sub Form-OLESta r tD rag (Data As DataObject , Al l owedEffect s End Sub=
AllowedEffects As Lo ng)
vbDropE f f ectCopy And vbDr OpEf f e ctM v e o vbCFText
Da ta.$e t Data "Hey The r e" ,
1 32
-
vbCFBitmap, Dib, vbCFiles, vbCFMetafiles, vbCFEMetafiles, vbCFPalette, vbCFRtf, vbCFLink vbCFText, vbCF .
VbCf Bi!map VbCf Oib VbCf f iles VbCf Metafile VbCf Palette VbCfRtl VbCfText
bitmap
( . ).
bitmap
( . I ).
(Windows Explorer).
Me!a!ile (.WMf)VbCf EM e!afileEnhanced mefafile (.EMf).
( .) .
(.RTf).
L
Clipboard
Drag and Drop Windows, . source L Drag and Drop.
textbox control.
,
control.
dragdrop.vbp:Sh i f t As Int e g e r ,
Opti on Expli c i t Privat e Sub Fo r ffi-Mou s eDown (Button As Int ege r , Sing le , End Sub Pri vat e Sub Forrn-OLESt a rtDr a g (Da t a As Da t aObj ect , Al lowedE ffect s=
As
As S i ngl e)
Forml. OLEDr ag
AllowedE f f ects As Long)
vbDropEffectCopy v b CFTe xt
Da t a . SetData Te xtl .Te 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 lowedEffe ct s Data. Set Da ta. End Sub=
Al l owe dEffe cts As Lo ng )
vbDr o pEffectC opy And v bDropE ff ectMove
vhCFText And VbcfBitmap And v b c fMet afi l e And vbc f RTF
, ,
. larget -
OLESetData,
SetData,
.
1 33
-
Pr ivate Sub Form-OLESetDat a (Data As DataObj ect , Select Case Dat aFo rmat Case vbCFText SetData (Re qu e s t e d da t a here ] , Case vbCFRTF SetData (Requested data h ere] , Case v b CFM eta f i l e SetData (Requested data here ] , Case v bCFBitmap Set Data (Requested data here] , End Select End Sub Da t a Fo rmat DataFormat DataFormat DataForm at
DataFormat As Int ege r )
OLEGLvefeedfiuck
Drag and target, . , Effecl Defau ~Cursors. Effecl vbDropE ffecl Defau~Cu rsors Windows . F alse Mousepointer. L
Private Sub Form-OLEGiveFeedback (Effect As Long, Effect = vbDropEffectCopy End Sub
De faultCursors As Boolean)
OLEC.ornpletel)rug
OLECompleteDrag .
Effect,
source ..
,
(vbDropEffecIMove)
.
Private Sub Forrn-OLECompl eteD r ag (Effe ct As Long ) If Ef fec t = vbDropEffectMove Then
,
~
K~K
End ! End Sub
I) urd
I)rop
,IILrdow5
Explorer Windows, vbC iles: FF
G etFormal Butt on As
Priv a t e Sub Fo rm-OLEDragDrop(Data As DataObject, Effect As Long , Int ege r , Shift As I nteger, As Singl e , As Si ngle) ! Data. GetFormat( vbCFFiles) Then
,End End Sub
a!
Explore r
Windows
1 34
-
,
D ata.Files DataObject.
.
C t oun
10m 1
. . .
CIoar
Remove
.
,
1 - Manual.
, ,
OLEDropMode Windows Explorer,
, .
Opt ion Explicit Pr ivat e Sub Form-OLEDrag Drop(Data As DataObject , Ef f ect As Long, But ton As In teger, Shi f t As I nt e ge r, As Sing l e , As Singl e )Dim Count As Integ e r
I f Data.GetFo rmat {vbC FF i les ) The n
~Ax =
Windows Explorer #
For Co unt
1
Data. Files . Count
Pr int Da ta. Fi le s(Count)
Next CountEn d r f
End Sub
-
text boxes controls Windows 95, ' box contral, menu (Cut, Capy ..) . MauseDown teX box, default , Menu1 :
If Butt o n
=
VbRightBut t on Then= =
Te xt l. Enab l e dTextl.Ena hled Textl . Set Fo c u s
Fal s eTr ue
Po pUpMenu Menul End If
MouseDown.
cantrol Windows PapUpMenu,
.
1 35
-
"Tag Tips" Tag.Vbp tag tips controls . ' ' label control AutoSize True. tag controls MouseMove :
Priva t e Sub CommandL-Mous eMove (Button As Int eg er, Shlft As Integer, Single. As Single ) Call P utT ag (Commad l ) End Sub
As
PutTag
:
Sub putTag (ct r As Cont rol ) Label l .Ca ption = ~ ~ + ctr. Tag + Lahe l l. Top = ctr. Top + ct r. HeightLa b e l l .Le f tEnd S ub
~
= ct r .Left + ctr.W idth /
2
Labell.Visi b l e = True
MouseMove :
Private Sub Fo rm-MouseMov e(Button As Integer, Shi f t As Intege r , Sing l e , As Single ) Labell.Visible = Fa l s e End Sub
As
Circle.Vbp r
(,) , :
*
+
*
AlarmSet ting.Te xt Ad Tr im$(AlarmSetting.Te x t ) Beep
~w
The n
End I f End Sub
Im1l0e
Visual Basic controIs G JPEG Bitmap, Icon MetafiIe. IF, , ImagecontroI, controls, Picture, design , LoadPicture, : ,
Pi c t u r el. Pi ctu re ,
=
LoadP ict u re { ~ico ns \comput e r \tra s h02a .
ico#)
Image controI =
, :
Pi c t u r e l .Pi c t u r e
P i cture2 .PictureHJ'IItj ,
;
.
9.19.
.
1 64
-
True F alse , control. Image.vbp , icon , click ' , timer. check box, Image.Frm:Option Explici t Dim I mg W v
Stretch,
i mage control
KQl
v
.
vQ KOl
v
t i me r.
Private Sub Form-Load () Imagel .Picture=
LoadP icture ("a rw02 rt . ico" )
I ma g e l . LeftI mg W=
=
Imagel.Width=
Timerl . Interval Ti m r l . Enabl e d eCheckl.Caption End Sub ,
300 False"S t r e t c h Property"
6Xl
i ma ge control
Private Sub Check l-Click ()
Imagel . St retchEnd Sub
=
Checkl .Value
\
tirner
Pr i vate Sub Fo rm-Cl i c k () Time rl. Enabled=
True
End Sub , v
6Xl()
image control
Private Su b Time r l _ Time r
Static Movelcon As I nt e g e r I f Not MovelconThen Imagel .Move Imagel. Left + ImgW, Imagel .Top, ImgW * 2 ImgW Else Imagel .Move Imagel. Left + ImgW, Imagel.Top, End I f If I ma g e l . Le f t> ScaleWidth Then=
Imagel.Left = Timerl.Enabled
False
1 65
-
End ! M ove l conEnd Sub
Not Move lcon
image control image control ( down). image Padlock ' LockOpen LockClosed, Load button
toolbox.
:
Pr i v ate Sub F o rm.....Lo a d () Pa d lo c k.P i c t u r e = Lo ckOpe n. Pictu re End Sub ,
Click Padlock image
:
Priv at e Sub Pa dl o c k-Cl i c k () Stat i c Lo ck e dFlag As I nt e g e r If Loc ke dFlag Th en Pa dlo ck .P icture LockOpen.P i c t ure El se Pa dlock.P icture LockC losed.P icture End I f Locke dF l a g = Not LockedFl ag End Sub
LockedFlag,
Padlock image.
Ptc:tureBox
control Picture ;
image control, Circle
,
Line, Circle, PoInt, Print
. . , .
,
'
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(' S he IO
11iI]
('"Shape 11r.:;; hape .~r s h.e
1314
rr
Stupe
5hae.5
8
.
9.20.
cont Shape. rol
, , , ,
button
Load
(index) . control,
, , :
Fo r
= 1 5 Load Optionl ( ) Ne x t
5
button,
1 .
Load,
control Unload:
UnLo a d Opt ion l ( 3 ) , '
option button
, . . 1 _Click.
Private Sub Opt ion l-Cl ick (Index As I nteger )
Shape.Frm.1
Option Ex pl ici t n~o 5 op tion button Optionl 1 16 . 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
Option 1 (O ).Ca ption For
Shap e , 5 Lo a d Opt ion 1 ( ) Opt ion l ( I ) . Top "" Opt ion1(I Opt ion1 (I ) .Capt i on ~Shape Optionl (I ).Visible "" True Ne xt Shape1.Fi llStyle "" 1
*"
1 ) .
+ Opti on1(0 ).Height + 4 0
&
Shapel. FillColorEnd Sub 1
RGB( 255,
,
)
c on tro ls
1
Shape cont ro l Private Sub Op t i o n 1_C l i c k (Index As Integer) Sh apel .Shape "" Ind e x End Sub
LJIe , l ne
control
, . 1, 1 ,
control, BorderWidth . Line.vbp , line bmer contral. ( click ) , line. Line.Frm:Opt ion Ex pl i cit 1
timer
1
1
n
1
\
.
Private Sub Form-Cl i c k ( ) Ti mer1.Enabled"" True End Sub , 1 1
timer
1
1ine c ontrol.
Pr i v a t e Su b Fo rm-Lo a d () Timerl . I nterval = 1 0 0 Line1 . X1 Line1 . Li ne 1. Line1. End Sub
100 10 0 500 300
12 2
timer
1
(animation )
l ine c ontrol.
1 68
-
Private Sub Timerl_T imer () St at ic Odd If Odd Then Linel . 2 Linel .Y2 Else Linel . Linel.Yl End If Odd "" Not Odd If Line l . Yl > Sc a l eHe i g ht Then Time rl.Enabled "" False Linel. 10 0 10 0 Linel . Yl Linel . 2 500 Linel. 2 3 00 Odd = Fa lse End If End Sub ,
Linel. Linel .
2 2
+ 250 + 600
Linel.Xl + 250 Linel.Yl + 600
ScaleHeight ScaleWidIh ( ) .
Dfj t fj -
conIrol,
(MSAccess ) ,
. L
control.
CU5torn
ctrl5
controls Viusal Basic, OCX (DLL). controls. custom controls , C++ Studio Microsoft. OCX , Visual Basic. System Windows. Windows, Registry. . C O X , System , Dos prompt REGSVR 16-bit O Xs C REGSVR32 32-bit O Xs ( 5.0 32-bit C 4.0). : OCX. ,
REGSVR32 C: \WINDOWS \SYSTEM\CUSTOM.OCX
Visuai Basic (
) .
,
1 69 - - - - --
-
Registry -
-
-
-
-
-
REGSVR
( /
REGSVR32),
:
REGSVR32
C: \WINDOWS \ SYSTEM\ CUSTOM. OCX
custOJJJ
slJ1: GS C
custom controIs,
ViusaI Basic.
CommonDiaIog CommonDiaIog controI, , , 5 . :
, .
Save
n ,
caption
.
PrintColor Font
. , . , ; .
control
, Act o n,
,
.
[ f o rm. ] CMD i a l og. Acti on[
=
setti ng ]
setting
.
12
SaveColor Fonl Printer
3
45
6
WINHELP.EXE
ShowHeIp,
ShowColor, ShowOpen, ShowSave, ShowPrinter, ShowFont AcIion.,
CancelError, CanceI button. True False.=
[ f o rm. ) CMD i al og. Can c elEr r o r[
{True
1 70
-
Fa lse} ]
DiaIogTitle, =
caption
titIe bar
.
[fo rm. ]CMDialog .DialogTitle [
t itle ] .
read,
, . .. ... ..
11. .llHIl _!D1X. .,1 . i1. - . . ~- . .............. - . ... . - . . , . , .
_
- - - 0
,"' ".
0
.
.
9.21.
CommonDialog control.
, '
CommonDialog control
5 , declaration module:-
Dialogs.Vbp, moduIe, Dialog s.Bas, control.
Deflnt
Type FontProp
Fo ntName As String FontSiz e As SingleFo ntBold As Integ er F o tl t a li c As !nteger
FontUnderLine As I ntege rFontStrikeThru 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 . :
CMDialog. Filter[
=
des crl
Ifilter l
Id e s c r 2
Ifilter2 . . . ]
*., tet. , ": " tet
(ASCII 124) bitmaps icons.
.
,
picture,
Text ( *. t x t ) 1*.txtIPictures (*.bmp; * . ico) I*.bmp; * . ico
Filterlndex
Open
default , FIags Save. , OFN_F ILEMUSTEXIST, ~ .
,
. ,
Filename
171
.-
-
FileSelect,
, ,
(
path$, *.), titie$,
. :
Function File Se lect (path$ , tit l e $ ) As String dialogs.CMD i a l ogl. CancelError = Tru e Loca l Erro r GoTo end2dire $=
Cu r Di r $: dire $
=
Left(dire $ ,
2)
dia l ogs. CMDial ogl. DefaultExt = p a th$ d ia l ogs . CMD ia l og l. DialogTitle = t it le$ dia l ogs . CMD i a l og l .Filename = -*. + pat h$ d i a l og s . CMD i a log l. Fi l te r = -* . W + path $ + Chr$ ( 124 ) d i a l ogs. CMD ialogl. Fi l t e r l nde x = 1 d i a l ogs. CMDi a log l . Flags = cdlOFNFile M ustEx is t di al ogs . CMDialog l .ShowOpe nW
ChDr i v e di r e$
Fi leSe lec t = d ialog s . CMD i a log l. Filename Exit Function end2:FileSele c t
=
~H:ChDri ve
di r e $ :Exit Fu nc t ion
End Function :
f11e$
=
FileSelect ( " * .
"
.
" )
f 1 1e $
FileSelect ( "BAS" ,
"
" )
v a Filej)le:
IJEJ[olde :
1 11;add,ettb. U ol.bp
0
~~~~ fi~:~ B~: ~BIye:
[Q
odd Dmom CI< 1 StatusBar control.
.
9.29.
3 Panels '
Date panel,
, ,
StatusBar control. , Time panel, ,
:
Private Sub Form-Lo ad ( ) Dim As I nt e g er = 1 2 St a tus8arl .Pane l s .Add Next
For
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 '
PanelDblClick Stat s8 ar, Panel Stat s8ar control. ,
Panel.
' .
Priv at e Sub StatusBarl-PanelDblClick (ByV a l Panel As Pa nel ) P rint End Sub Pa nel . Ke y & " W idth = " & Panel.Width
Count,
Panel Index, Panels ' Stats8ar control . .
Panel,
ProgressBar Progress8ar control
,
.
@l.
9.30. Prog ressBar
contro .
Max,
control
Value
.
Slider Slider