681:3.06:800.92
22.183.492
95
:
, - . .
, . .
. .
95 Visual Basic 6.0: :
, 2002.
ISBN
. Visual Basic 6.0 .
: ;
; VB; VB; ; ;
. .
. , ,
, .
ISBN
681:3.06:800.92
22.183.492
. . 2002-06-28
2002
......................................................................................................................8
1. ......................................................................................12
Visual Basic 6.0 ........................................................................12
1. 1. ..............................................................................................12
1.1.1. ............................................................................. 12
1.1.2. ...................................................................................... 14
(Menu) ........................................................................................... 15
(Toolbars) ........................................................... 15
(Form) ........................................................................................... 16
(Project) ............................................................................ 17
C (Properties)..................................................................... 18
(Code) ......................................................................... 18
(Form Layout)................................... 19
1.1.3. ................................................... 20
...................................... 20
................................................................ 21
1.1.4. : Visual Basic ....................................... 21
1.1.5. ..................................................................... 22
1. 2. -.....................................................................23
....................................................................23
1.2.1. - ............................ 23
...................................................................................... 23
1.2.2. ........................................................... 26
.................................................................................. 27
................................................................................... 28
.................................................................................... 29
1.2.3. Label, TextBox, ........................................... 30
CommandButton ........................................................................................... 30
(Command Button) .................................................. 30
(Label) ....................................................................................... 30
(TextBox)...................................................................... 31
1.2.4. ..................................................... 32
1.2.5. : Visual Basic.................................... 33
1.2.6. ..................................................................... 39
2. ........................................................................................40
..............................................................................................40
2.1. .................................................... 40
................................................................................................ 40
2.2. ............................................................................ 42
...................................................................................... 44
....................................................................................... 46
3
M ........................................................................................ 48
.............................................................................. 49
2.3. MDI ......................................................................................... 50
MDI-............................................................................. 50
................................................................ 50
2.4. ........................................................... 51
........................................................................... 52
.............................................................. 52
................................................................................... 54
2.5. : ................................... 55
2.6. ........................................................................ 59
3. Visual Basic ......................................................................60
3.1. ........................................................60
VB .................................................................................................................60
3.1.1. ................................................................. 60
.................................................................................. 60
(Code) ........................................................................ 61
3.1.2. ....................................................................................... 64
......................................................... 64
................................................................. 65
................................................................................... 65
() .................................. 66
...................................................................... 67
....................................................................... 67
3.1.3. .......................................................................................... 67
3.1.4. : ...................................................... 68
3.1.5. ..................................................................... 70
3.2. VB. ....................................................................71
3.2.1. ...................................................................................... 71
................................... 71
TextBox.................... 71
InputBox ................................ 71
3.2.2. .................................................................................... 72
Print.......................................................................................... 72
TextBox ......................................................................... 74
MessageBox..................................................................... 75
3.2.3. ......................................................................................... 76
( ) ................... 77
........................................................................ 77
.................................................................................... 78
3.2.4. ............................................................................................. 79
.............................................................................. 79
.......................................................................... 80
4
....................................... 80
3.2.5. ................................ 82
..................................................................................................... 82
.................................................................................. 82
................................................................................... 83
3.2.6. :
........................................................................................................... 86
3.2.7. ..................................................................... 90
3.3. ..............................................................................................................91
3.3.1. . .................................. 91
. ...................................................................................................... 91
3.3.2. ................................................... 93
3.3.3. ...................................................................... 95
3.3.4. : ................................................... 97
3.3.5. ..................................................................... 97
3.4. .........................................................................98
...................................................................................98
3.4.1. ........................................................ 98
........................................... 98
.......................... 99
................................................................................................ 99
...................................................................................................... 100
3.4.2. ........................................................ 101
..................................................................... 101
...................................................................... 103
3.4.3. : ......................................... 104
............................................................. 104
3.4.4. ................................................................... 108
4. Visual Basic...................................................................110
4.1. Visual Basic. ...............................................................110
4.1.1. . Scale ........................................................................ 110
...................................................................................................... 110
Scale ............................................................................................ 111
Screen ........................................................................................ 111
4.1.2. Line Shape ............................................. 112
Line ..................................................................... 112
Shape................................................................... 114
4.1.3. ..................................................................... 116
4.1.4. : .............................................. 117
4.1.5. ................................................................... 117
4.2. Visual Basic.................................................................118
4.2.1. Line................................................................. 119
5
................................................................................ 171
6.1.4.: .............................................. 175
6.1.5. ................................................................... 177
6.2. ..................................................................................177
6.2.1. ............................................... 178
6.2.2. ................................. 179
.......................................................... 179
......................................................... 179
6.2.3. :
................................................................................................. 180
6.2.4. ................................................................... 183
7. .......................................................183
. ......................................................................................183
7.1. ..........................................183
7.1.1. ................................................................................ 183
7.1.2. .......................... 184
........................................ 184
KeyPress ....................................................... 184
KeyDown KeyUp ...................................... 185
KeyPreview................................................... 185
7.1.3. ........................................................ 186
............................................................................ 186
........................................................................................................................... 186
Change ...................... 187
.................................................................. 188
7.1.4. : ........................................................ 189
7
20 .
,
, , , .
, - .
Visual Basic
(VB).
Visual Basic: VB1, VB3, VB4, VB5 VB6.
VB 1991 . VB
Windows
DOS. , , , , ,
.
VB 1 . VB Windows Windows NT .
1
, Windows
. VB Windows , .
Visual Basic 6.0 Basic.
, , ,
Pascal, Delphi, C.
VB ,
, ,
Windows: Word Basic ; Basic for Application
; Visual Basic .
Visual Basic () ().
VB
.
. ,
. .
. ,
. - . Visual Basic 6.0
Threaded-p-Code, Threaded-p-Code.
, ,
. : , VB
; -, .
VB EXE-,
, . EXE- . , .
VB Visual Basic 6.0 ,
: VB ,
VB VB.
VB . . 9
, .
Visual Basic 6.0 . VB
10 , 80486 Pentium, 16
.
VB 100 .
Visual Basic Windows ( Windows 95)
. . , VB , , , , , , ,
.
,
Windows . VB5 VB6
ActiveX. ActiveX - Microsoft Internet Internet-, Windows .
. VB6 32- Windows 95/98 Windows NT. VB
.
.
Visual Basic 6.0 . .
; - , ,
, , , ; .
.
, , MDI-.
VB.
. , , , , , .
, .
.
10
VB: , .
.
: , , , .
: . .
.
.
. ,
,
, . ,
.
, , , .
: - ,
. . , . . , ,
.
, - . . . .
.
11
1.
Visual Basic 6.0
1. 1.
1.1.1.
VB .
,
: \ \ VB62, .
,
New Project. . :
New ;
Existing ;
Recent , .
: Windows,
, Visual Basic 6.0 .
, .
12
13
DHTML Application
HTML, Web-.
1.1.2.
(.
1.2). Visual Basic. , Tools\Options.
, .
1
4
5
12
11
1
6
10
,
Windows: (2), (12), :
-Toolbar (11) Toolbox (9).
(1) . (3, 4, 5)
, , . 14
.
: - Form1 (10), Project-Project1 (6);
Properties (7); Form Layout (8).
(Menu)
,
, :
File () - , , , .
Edit () - ,
, .
View () -
VB.
Project () - VB
,
, .
Format ()
, .
Debug () ,
.
Run () .
Tools ()
. Options,
Options,
Visual Basic.
Add-Ins ( ) ,
VB: , ActiveX .
Diagram () .
Window () .
Query .
Help .
.
Alt. ( ): [Alt- ].
(Toolbars)
VB : Standard , Edit - , Debug Form Editor .
15
,
.
.
, , , .
,
(), , ,
, .
. ,
,
, .
(Toolbox).
Toolbox .
, 3
. , VB .
Toolbox
:
-
Project\Components, Controls;
-
;
- , Ok.
(Form)
Visual Basic . , - . Visual Basic
, Form1 (.
1.2). , . , . .
,
. 3
16
interface (),
(Project)
( ) (. 1.3.)
: , , .., .
VB View Code
.
View Object
(,
..). VB
,
,
- .
.
:
; (, MDI-, , ,
);
:
.
.
.
.1.3.
,
, .
Visual Basic 1.1.
1.1
Visual Basic
Visual Basic (Project)
Visual Basic (Form)
(Module)
(Class Module)
(User Controls)
ActiveX (Property Pages)
.VBP
.FRM
.BAS
.CLS
.CLT
.DOB
.VBG
17
.FRM. .VBP. , . .
, .VBG.
,
Project\Add, Project\Remove.
C (Properties)
(. 1.4.) . Properties
, .
. , , .
(Alphabetic)
(Categorized).
.
?
:
-
;
- ,
;
- ,
()
, .
.
. 1.4.
(Code) 4
. , :
; ; . ..
18
.
VB
. 1.5. (Code)
, , , . .
, View Code
Project.
(.1.5) , ( ,
, ).
: ()
().
.
General, ,
.
, . ,
. , VB
(Form Layout)
,
.
19
1.1.3.
.
File\Save Project File\Save Project As. ,
, . (. 1.6).
,
R:,
,
.
, .
.
. 1.6.
. , VBP, FRM.
,
.
,
Open Project
, .
, File\Open Project. , : Existing (), , Recent (), .
();
, .
20
File\Print. (. 1.7).
,
, ,
. (Selection,
Current Module u
Current Project) ,
,
. 1.7.
,
.
(Form Image, Code u Form As Text) , (, ), , . ( Code).
File\Print Setup . ,
.
VB
Windows . VB
PrintForm.
5. View\Project Explorer
View\Properties Window, . .
6. . .
7. (Toolbox).
Toolbox View\Toolbox.
8. Microsoft Flex Grid.
Project\Components\Controls, Microsoft FlexGrid Control 6.0 (SP3) . Ok.
9. Project\Add Form.
10.
File\Save As.
11. File\New Project.
12. File\Open Project.
13. Form1. File\Print, Form Image Ok
( ).
14. Visual Basic.
1.1.5.
1. Visual Basic ?
2. VB.
3. VB?
4. VB.
5.
Toolbox?
6. ?
7. ?
8. ?
9. ?
10. ?
11. ?
12. ?
13. ?
14. ?
22
1. 2.
1.2.1. -
- () -
, .
-
, , .
. .
.
,
. , .
,
. ,
.
() ( ) , .
, , , , . . , +
.
. , .
, , ,
, .
- , , .
. , , VB
Form1,
. ,
23
, ,
. ,
.
- , ,
.
()
( ).
( ), , , .
, , , .
, .
, , .. .
.
, .
.
, ,
, .
, .
?
. , , ,
...
...
...
...
...
...
...
. 1.8.
Top Left ( 24
). , , Move
() .
. . , , ; .
.1.8
,
. . ,
Change.
Private Sub Text1_Change () -
...
End Sub
-
TextBox. , TextBox,
Text1. (. 1.5)
Text1, Change .
, ,
:
Private Sub Text1_Change ()
=Val(Text1.Text)
End Sub.
Text Text1 .
, , , . , - .
5
. ,
.
- :
5
, , ,
. . ,
.
25
:
.
..
:
. =
:
= .
:
Form1.Show - Form1 - ; Show -
Text1.Text = - Text1 ; Text
;
= Text2.Text - ; Text2 ;
Text
1.2.2.
(Properties).
, Object Browser (.1.9.), .
View\Object Browser.
. VB (Visual
Basic
objects
and
procedures).
Classes
VB.
Form
, Form1 , . Financial ,
Form1.
.1.9.
Members of , ,
. (MousePointer, Moveable,
Name), (MouseUp) (Move).
, - .
26
F1 ? . (). , Form,
.
(Search Results) , Members
of . . 1.9 Line.
,
, .
. , ,
, , , , .
(Name).
, , Form, Label, Text ..
, :
Label1, Label2, .. , , ,
. : , , . - : , , ,
. . .
: .
. , txt, lbl, cmd ..: txtDlina, lblDlina,
cmdStart. ,
(Dlina) - .
(Caption) , .
. . ,
, .. .
, .
:
.. =<>
frmForm1.cmdExit1.Caption =
27
. (.1.10). :
Top Left
Top
.
. -
Left
Height
. 1/20
Widtht
.
.
.1.10.
: Height Width
( ).
.
BackColor, FileColor ForeColor.
Windows.
BackColor . ,
RGB,
VBRUN (. 4).
ForeColor FillColor , .
Enabled . : True False . False,
. .
Visible . :
True False. False, .
Index . .
TabIndex .
.
Enter.
.
.
Click. Click , .
28
DblClick. DblClick
. Windows;
KeyDown ;
KeyUp - ;
KeyPress ASCII .
: KeyCode Shift. KeyCode , Shift Shift, Ctrl Alt. :
Control_KeyUp(KeyCode As Integer, Shift As Integer)
:
KeyUp, Key Press, KeyDown.
KeyPreview .
KeyPreview True, , , .
KeyPreview - . , .
Windows . , , . :
Enter , , ; , , .. , . , , , , . . :
GotFocus , ;
LostFocus , () .
SetFocus , .
SetFocus. : txtText1.SetFocus
, ,
10 , 22 .
Move , OLE Drag - OLE ( ), Refresh ,
SetFocus - .
29
(Command Button)
: , , . .
, , , ,
, , .
:
Default ,
. : True False. False. True, ,
. Enter
.
Cancel - Default. Esc Click . , Cancel cmdEnd True,
Esc ,
.
Appearance .
ToolTipText , ,
.
(Label)
,
. . :
BorderStyle - .
Font - , Windows.
AutoSize -
30
. AutoSize False
, . AutoSize
True, .
WordWrap False.
WordWrap - .
True AutoSize.
WordWrap AutoSize . . 1.11.
. .
, , .
.
WordWrap True,
AutoSize True.
(TextBox)
, .
,
:
Text Caption. ,
, ;
31
Alignment . : 0-
, 1 - , 2 - ;
ScrollBars . Scrollbars , .
MultiLine
. ScrollBars.
.
SelStart, SelLength, SelText.
SelStart .
SelLength .
SelText .
:
Text1.SelStart=2
Text1.SelLength=6
Text1.SelText =
MaxLength
0, 32 .
PassWordChar .
.
Locked .
, . ,
.
TextBox 23 . : Click, DblClick, KeyDown, KeyUp, GotFocus, LostFocus, ;
Change - .
: .
,
:
Val() ;
Str(N) Str$(N) -
Variant. :
= Val(Text1.Text)
Text2.Text = Str$()
1.2.4.
Visual Basic, . , , , , , .
:
32
- ,
;
- ;
- ( , );
- ;
- , ;
- ;
- ;
-
;
- ;
- , ;
-
.
, ,
;
- .
, , . , ,
.
33
End Sub.
DblClick.
:
Private Sub Form_DblClick( )
CLS
PRINT
End Sub.
CLS .
Run\Start.
.
:
,
.
File\Save Project
File\Save Project as ...
1.2. .
h
. a
b
. .
:
:
S=2(a+b)h+2ab, V=abh
, : a=1; b=1; h=2. :
S=10; V=2.
Click,
:
Private Sub Form_Click ( )
Let a= 2: Let b=3 : Let h=50
S=2*(a+b)*h+2*a*b
V=a*b*h
Print a=;str$(a), b=; str$(b), h=;str$(h)
Print ;str$(s)
Print ;str$(V)
End Sub
.
.
.
1.3. .
34
;
Command1 .
.
.
x2 1
( x 2 + 1)( x 4 + 1)
1
4.
(3Sin ( x ) + 2Cos( x ))2
x
7. 4
x + 3x 2 + 2
2. Sin ( x )Ln(Tg ( x ))
5.
8.
Ln( x 3 )
x
1
( x + 1)( x 2 + 1)
e x (1 + sin( x ))
3.
1 + Cos( x )
6.
x3
3+ x
9. x + Ln( x 2 4)
35
11. xLn 2 ( x )
2( x + 1) 2
x2
2
13. x 2 x / 2 e 2 + x
10.
14. xe1 / x
(4e 2 x 1)
e2 x
Ln( x )
15.
( x + 1) 2
12.
1.4. .
File\New Project.
Name, Caption.
, :
- ;
- , .
.
- ( Name , Caption -
).
(
):
, :
- File\Print;
- Form AsText Code.
- .
, .
Alignment, Apperanse, BorderStyle , .
AutoSize WordWrap ( . 1.11).
.
1.5. .
: ,
, . .
, .
:
1. .
36
. ,
.
2.
: ,
:
=(+++)/4
(.1.2).
3. .
(.1.12).
(Command)
(Label)
(TextBox)
.1.12
- .
, , , , ,
. - . - .
,
.
4. .
. 1.3.
1.2.
______________
________
:
F
_______
37
INF
FIZ
SB
SB
1.3
Forma1
()
Label 1
Label 2
Label 3
. .
Text 1
Text 2
. .
Command1
Command2
Name
Caption
Name
Caption
Alignment
Name
Caption
Alignment
Name
Caption
Alignment
frmForm1
lblText
2
lblFizika
2
lblMatematika
Name
Caption
Alignment
Name
Caption
Alignment
txtFiz
1
txtMat
Name
Caption
Alignment
Name
Caption
Alignment
cmdOK
OK
2
cmdEnd
5. Click
:
Private Sub CmdOK_Click ()
Dim As Integer, As Integer
Dim . As Integer, As Integer
Dim As Single
F = Val (txtFiz.Text)
= Val(txtMat.Text)
INF = Val(txtInf.Text)
FIZ = Val(txtFizkult.Text)
SB = (F + + INF + FIZ)/4
txtSredBall = Str(SB)
38
End Sub
----------------------------------------------------------------------------Private Sub mdEnd_Click()
End
End Sub
: .
6. .
VB.
Name
Caption .
6 , . 1.12
1.3.
. (Name),
. : txtF , txtM ,
txtInf , txtFiz , txtSB .
. 1.3.
Code.
Code Project.
mdOK, Click. .
mdEnd , Click .
6. .
7. .
8. :
- : 5, 4, 5,4
- ;
- - 4,5.
1.2.6.
1. - ?
2. .
3. , , , , .
4. .
5. ,
.
6. ?
7. Label?
8. TextBox?
9. CommandButon?
39
10. TextBox?
Text Text1 .
(, , , . .).
.
(S)
(V).
: S=2(ab+bc+ca); V=abc. S ; V , a, b, c
; a, b, c .
:
S= M+2F;
V=Fh. ,
F , h .
:
S= pb/2+F;
V=Fh/3, , b (),
: S = 2R(R + h) , V = R2h .
: S = R(R + l) , V = R2h / 3 , l , l = R2 + h2 .
: S = 4R2 , V = 4R3 / 3 ,
2.
2.1.
1.2.5 . .
.
.
, .
.
, ,
. , , : . .
40
, .
, Visual Basic .
, .
: ; ; ; ; .
,
, .
, , , , , .
.
. ,
, ,
.
, ;
;
.
OK Next .
.
. , .
.
.
. Microsoft Word.
. .
- , . ,
, .
.
,
.
, . .
Align - , Make Same Size , Horizontal Spacing , Vertical
Spacing , Center in Form
Format.
- , .
41
. , ,
, ,
.
.
,
,
.
.2.1.
, . , , . , , , , . 2.1: - ; ; - , ; . .
. . . Arial
Times New Roman.
.
.
. ,
.
, Microsoft Word, Microsoft Excel .
, ,
- .
2.2.
(. 2.2.) - ,
.. . . ,
.
Frame , PictureBox - ToolBar .
42
Windows: ,
;
;
, .
( Minimize)
. 2.2
.
( Maximize).
. .
,
. , . ,
.
Tools\Options
(
[Alt+T,O]). Option (. 2.3)
General Show Grid Align Controls to
Grid .
Format\Align\To Grid. Grid Units: Widht
Height . .
FRM.
,
.
.
: .2.3.
,
MDI , .
43
, .
.Show vbModal .Show 1
. 2.1.
.
2.1
Name
Form 1
Apperance
BorderStyle
Caption
ontrolBox
Enabled
44
Form 1
1
True
. .
frm (, frmProject1)
:
0 , 1 .
.
0 - . . .
.
1 - .
Minimize Maximize. :
.
3 - , . . :
.
4 .
Close.
.
5 - , 4, .
. .
1 - .
0 - ( ).
. True, ,
False .
Font
Height
Width
Icon
Left
Top
Mouse Pointer,
Mouse Icon
Visible
WindowsState
MS
Sans Serif
2880
3840
Windows
0
0
0
(None)
True
0
ScaleMode
1 - Twip
ScaleHeight
ScaleWidth
3195
4680
: , , , ,
.
Font
- ( ). ,
.
.
567 .
,
Windows.
.
, .ICO.
: , , .
Form Layout.
.
.
Layout
View\Form Layout Window.
Layout
,
.
. 17 . 11 13. 11
, 13 . Mouse
Pointer 99, .
. True , False .
. 0 ; 1 ; 2
,
Maximize.
. : 0
, 1 , 3 , 6 , 7 .
,
.
45
ScaleMode 0.
ScaleLeft
ScaleTop
0
0
ForeColor
BackColor
Windows
.
, .
,
. Palette .
System Windows.
20 .
Click, DoubleClick .
, , -
.
- .
Click :
Private Sub Form_Click ()
< >
End Sub.
Initialize , , , ,
( - )
, . , Initialize :
frmMyForm.Show
46
Load frmMyForm
. , ,
.
Load - . .
. Load Initialize. Load Load Show, ,
.
2.1.:
Private Sub Form_Load ( )
Dim i As Integer
For i=2 t 5
Load txtText1(i)
txtText1(i).Text = +Str$(i)
Next i
End Sub
47
, Cancel
True.
Unload Terminate. Unload ,
, .
, . Unload
End .
Cancel ,
Windows. Windows,
QueryUnload.
Terminate ,
. , Nothing:
Set frmMyForm = Nothing
, , Terminate
Unload.
M
- .
, . Visual Basic : Load, Unload, Hide, Show.
Load ,
.
, :
Load frmMyForm
,
Unload . .
Unload frmMyForm
Unload Me
Hide , .
,
. , .
Hide ,
, .
FrmMyForm.Hide
48
Me.Hide
Show . , VB Load.
Show , . , .
) :
frmMyForm.Show
Me.Show
)
frmVvodData.Show vbModal
frmVvodData.Show 1
Project, Add Form.
Add Form.
Form, Open.
.
. :
- Project Project1 Properties. Project1 Properties;
- Startup Object, ,
. .
PrintForm.
Private Sub Form_Click ()
PrintForm
End Sub.
49
2.3. MDI
MDI-
. ,
MDI-.
MDI - ,
.
MDI-
() . MDI- ,
, PictureBox, Image. MDI- .
MDI-
. Word
Excel. .
MDI- Project\Add MDI Form.
MDI- , ,
.
,
Load , :
Private Sub Form_Load()
Me.Height = 2745
Me.Width = 3090
Me.Top = (MDIForm1.ScailHeigth Me.Heigth) / 2
Me.Left = (MDIForm1.ScailWidth Me.Width) / 2
End Sub
, . , . :
Private Sub mnuExit_Click()
Me.WindowState = 0
Unload Me
End Sub
MDI- ( ), MDIChild True.
50
Show, :
Private Sub mnuVvod_Click()
frmVvod.Show
End Sub
. ,
.
, MDI-
Window (),
(Cascade) (Tile). ,
- .
(Horizontal) (Vertical).
, ,
, . Window .
, Window WindowList.
MDI-
Arrange. , VB : VbCascade , VbTileHorizontal , VbTileHorizontal - ,
VbArrangeIcons
.
Window
: , , , Click
:
MDI-.Arrange VisualBasica
:
Sub mnuCascade_Click
MDIForm1.Arrange VbCascade
End Sub
Sub mnuHorizontal_Click
MDIForm1.Arrange VbTileHorizontal
End Sub
Sub mnuVertical_Click
MDIForm1.Arrange VbTileVertical
End Sub
2.4.
51
. , Windows, ,
.
1A
1A1
.
1A2
1B
1A3
1A3A
1C
..
1A3B 1A3B1
1D
VB
.
. . 2.4.
3- . . 2.4. .
: , , . 1,
1A1-1A3; 13 13,
131.
. . 2.4.
. ,
VB.
Visual Basic 6.0
Menu Editor, Tools \ Menu Editor CTRL E.
Menu Editor . 2.5.
Caption ,
. OK
. & - ,
( ). , &, .
52
Name ,
.
mnu,
,
mnuFile.
,
.
Index
, . 2.5. Menu Editor
.
Shortcut
: Ctrl + , Shift +
. ,
.
O HelpContexID , .
NegotiatePosition
, : , , , .
Checked. True,
. ,
.
Enabled. .
False , .
Visible. ,
. , . , , Window .
WindowList. ,
(MDI).
,
.
Next .
53
Insert .
Delete .
...
. 2.6.
, ,
(Separator
Bar)
(.2.6.). ,
,
( Caption) (-).
, , mnuRaz1 . .
Menu Editor
. ,
. .
.
MDI-
, MDI- (),
, Menu Editor.
, , .
MDI- -
, . , ,
, .
() , ,
.
. , Visible False. , ,
, ,
.
PopupMenu. :
.PopupMenu
54
MouseUp .
2.5. :
2.1.. BorderStyle .
.
1. Visual Basic Standard
EXE ( ).
2.
2.2
BorderStyle-0
BorderStyle-1
BorderStyle-2
BorderStyle-3
BorderStyle-4
BorderStyle-5
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
BorderStyle-&0
mnuForm0
BorderStyle-&1
mnu Form1
BorderStyle-&2
mnu Form2
BorderStyle-&3
mnu Form3
BorderStyle-&4
mnu Form4
BorderStyle-&5
mnu Form5
&
mnuWindow
&
mnuCascad
&
mnuHorizont
&
mnuVertical
OK.
5. Project\Add Form.
frmForm0 frmForm5. MDIChild True.
6.
Click. ,
.
Click :
Private Sub mnuForm0_Click()
End Sub
Click
:
Private Sub mnuForm0_Click()
frmForm0.Show
End Sub
7. : Project\
Project1 Properties... Startup Object MDIForm1.
8.
WindowList.
: , .
, . .
.
.
9. , . 2.3.
10.
( , , , ).
11. .
2.2. : , , , , . .
.
1. (. 2.7).
2. (. 2.3) .
56
. 2.7.
2.3
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
&
mnuFile
&
mnuOpen
mnuRaz1
&
mnuSave
mnuRaz2
&
mnuPrint
&
mnuExit
&
mnuCalc
&
mnuKonus
&
mnuFull
&
mnuBrif
&
mnuParall
&
mnuPrizma
&
mnuShar
&
mnuZilindr
3. .
4. .
, , , ,
, :
57
Dim nTemp As Inteqer, sTemp As Inteqer
sTemp =
nTemp = MsqBox (sTemp, VbYesNo, )
If nTemp = VbYes Then
End
End If
, , :
Private Sub mnuFull_Click
frmKonusFull.Show
End Sub
frmKonusFull .
2.3. .
. (
): ; ...8; ...12; ...14; ...18;
...24. mnuShriftHeight Visible. mnu8,
mnu12 . .
.
Click :
Private Sub Form_Click()
Print ""
End Sub
MouseUp
. Button
vbRightButton .
Private Sub Form_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Form1.PopupMenu mnuShriftHeight
End If
End Sub
Click
:
Private Sub mnu8_Click()
Form1.FontSize =8
End Sub
Private Sub mnu14_Click()
Form1.FontSize = 14
End Sub
58
. .
.
.
2.6.
1. .
2. ?
3. .
4.
5. ?
6. Load Unload?
7. .
8. MDI-, ?
9. ?
10. ?
11. ?
12. Menu Editor.
13. ?
14.
?
15. ?
16. ?
17. ,
?
1. .
, ,
, .
2. .
59
3. Visual Basic
3.1.
VB
3.1.1.
, Windows, .
, VB, .
, . ,
(. 3.1.).
, , Project \ Add Project, Project \ Add Form.
, , , .
Project
[ -
[ - *. vbp
- *.frm ]
. . .
...
. . .
...
[ - .bas
...
. 3.1.
60
(. 1.3, 3.1).
VB ,
. , .
, .
, .
. . Project \ Add Module. Project \ Add Module
Existing Project \ Add File.
.bas.
(Code)
(. 3.2) VB.
, - . VB .
, ,
.
: . , .
.
(General) , , . . .
. 3.2 Option Explicit,
Click Load . Split Bar ( ) .
,
.
. .
61
.
. (Procedure View) , (Full Module View) . .
Windows ( , , ,
). , VB IntelliSense Microsoft. :
. 3.2.
. (64 ).
;
VB (Quick Info).
,
, , ;
, (List Properties/ Methods). ;
As
.
(Available Constants)
.
62
,
Tools\Options. Editor Auto Quick Info Auto List Members Code
Setting.
Rem . .
.
Enter
, .
Auto Syntax Check Editor
Options Tools.
,
, .
_.
10 . 1023 .
, .
Edit,
, , Editor
Format Options Tools.
VB . :
.
, , -
.
. ;
.
.
Visual Basic , ,
.
, . .
, , .
, .
.
63
, , . .
3.1.2.
,
.
. . 255 .
, . &. (. 3.1),
.
.
.
,
.
:
1. ,
(. 3.1).
:
C$ = : a! = 1.769: B% = 12674
2. DefType.
. :
DefType < >!
:
DefStr C
DefInt I-L
, ,
, , , I, J, K, L .
3. Dim, Private, Static, Public,
Global. . :
Dim <_>
<_ >]
64
As <_>
[,<_>, As
, ,
, Dim.
,
, .
Options Explicit.
(General) . ,
.
Require Variable Declaration Editor Tools \
Options. Options Explicit
.
VB 14. . 3.1.
, .
Variant. , , Variant.
Variant .
. . , Variant ,
3.1.
String
DefStr
Integer
DefInt
&
Long
Integer
DefLng
String*
DefStr
, 2
, 65400
, (-32768,+
32768)
, (
- 2 147 483 648 + 2 147 483 647)
65
DefSng
, , +4
Single
(10-45 3*1038 )
8
DEfDbl
Double
,
,
-324
308
1127, +-(5*10 1,8*10 )
8
DefCur
Cur , rency
( +- 9*1014)
2
Boolean DefBool
, ,
: True False
1
Def Byte
Byte
0 255
8
DefDate
Date
, 1/1/100 12/31/
9999; 0:0:0 23:59:59
4
Object
; OLE
16 + 1
DefVar
Variant
, .
.
.
()
VB ,
: ; ( ); .
. Dim.
,
. Dim (General)
. Private.
.
Global Public
( .bas).
: . Dim ,
As .
:
Dim a As Integer, b As Single
Dim nCount As Integer, I As Integer, J As Integer
66
, , , .
.
, . ,
. ,
, , .
Static:
Static nPageNumber As Integer
,
,
.
Static :
Static Sub <_> _<> ()
Static Sub _Click ( )
3.1.3.
, .
, . , . , .
Const. Public Const.
.
:
Public Const < >=<>
Private Const < >=<>
67
:
Public Const Pi = 3.1415926538897932
Const G = 9.81
Public Const nName =
Const = 225
Const = * * * .
, ,
: View \ Object Browser, Object Browser F2.
:
[ Public\ Private] Const < > As <_>=<>
,
.
Visual Basic ,
. VB , , . ,
Message Box.
3.1.4. :
3.1. .
[a,b]. . .
:
Visual Basic Standard
EXE.
:
Tools\Options\Editor, Require Variable Declaration.
.
.
(.3.3.).
. =:
Option Explicit
Dim a As Single, b As Single, S As Single, N As Integer
Dim x As Single, dx As Single
Dim y As Single, i As Integer
68
Sub Form_Load()
'
Left = (Screen.Width - Me.Width) / 2
Top = (Screen.Height - Me.Height) / 2
End Sub
Sub Command1_Click()
Dim y As Single, i As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
N = Val(Text3.Text)
S=0
x = a: dx = (b - a) / N
For i = 1 To N
y=x
S = S + y * dx
x = x + dx
Next I
Text4.Text=Str(S)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
. 3.3.
, ,
:
3.2
a
a
Single
0,5
.
, .
File\Save Project As.
= [0,1]
0,5.
. . .
y=x .
File\Save Project.
69
File\Print (
Print , , ).
Make Project1.exe ...
Visual Basic.
.
3.1.5.
1. Visual Basic.
2. ?
3. .
4.
Visual Basic?
5.
.
6. VB.
7. VB?
8. ?
9.
?
10. , ?
11. ?
12.
VB?
2,7
1,4
1,3x 2 + 0,8dx
;
1.
2x + 0,5
1,31,7 +
1,8
1,5x 2 + 2dx
x+
4.
0 ,8
2,5
7.
0,8x 2 + 1
0,6
x + 0,6
x 2 + 1,3dx
8.
;
0,4 x + 1,7
1, 2 1,5x +
0,7 x 2 + 1dx
10.
;
0,6x + 1,7
1, 2 2,1x +
13.
1,1x 2 + 0,9dx
1,6 +
0,6
0,8x 2 + 1,4
0,4x 2 + 1,5dx
11.
;
2 x + 0,8
0 ,8 2,5x +
14.
0,7
2x + x + 3
2
sin(1,5x + 0,3)dx
;
2
+ 1)
sin(0,7 x + 0,4)dx
;
2
0 , 5 2,2 + cos(0,3x + 0,7)
cos(0,3x + 0,5)dx
19.
;
2
0 , 31,8 + sin( x + 0,8)
1,1
20.
sin(0,6x 2 + 0,3)dx
;
0,5x 2 + 3dx
2x +
6.
1, 2
1, 6
9.
1,8 +
0 ,8
2 ,8
12.
1, 2
15.
0 ,8
1, 4
18.
2x 2 + 1,6
2 x + 1,6dx
0,3x 2 + 2,3
1,2x + 0,7dx
1,4x +
2, 4
17.
1,1
70
0,6x + 1,5dx
2,0
1, 3
2,3 + cos(0,4x
0, 4
2, 4
2 ,1
16.
1, 2
2,6
2,0
2, 4
x 2 + 2,5
2x 2 + 1dx
3.
;
0,5x + 2
0 , 4 0,8x +
0,8x 2 + 2dx
5.
;
1 1,6 + 1,5 x + 0,6
1, 3
2x +
2.
1, 2
2, 2
0,8x 2 + 1,3dx
1,4 +
x 2 + 0,5dx
1,3x 2 + 0,5
1,5x + 2,3dx
;
3 + 0,3x + 1
cos(0,8x 2 + 1)dx
;
3.2. VB.
3.2.1.
:
- Let;
- c
TextBox;
- InputBox.
Let;
:
Let <_> = <>
:
Let a=3.754
Let b=Sin(x)
Let c$=
TextBox
TextBox.
.
. Val( ). :
<__>= txtText1.Text
<__>= Val(txtText1.Text)
InputBox
InputBox (.3.4.). InputBox , . :
<> = InputBox (prompt [,title] [,default] [,xpos] [,ypos] [,helpfile], context])
: Prompt ,
( ).
Title ( ). , .
71
Default , (124.786).
XPos YPos
.
.
InputBox
. 3.4. InputBox
HelpFile Context, . , InputBox , . Cancel .
- ,
.
TextBox.
3.2.2.
:
Print; ; MessageBox; MSFlexGrid .
Print
Print
PictureBox.
Print Visual Basic Print
Basic:
Print [ ] [;/ /,] < > [;/,]
, , ;
[;/ /,] - : ; ,
. , , . . ,
. Print
14 , ;
< > - , , ,
;
72
[;/,] - .
Print .
.
CurrentX
CurrentY , Tab(N) Spc(N). :
CurrenX=100: CurrenY=50
Print x,y
CurrentX CurrentY X Y. .
Tab Spc Print.
.
Tab Spc , Tab , Spc .
, Format. Format:
Print Format (, )
: Print Format (1124.75; currency)
.
$,
(000,000,000.00).
.
, Fixed,
.
100 .
Yes,
No.
1124.75
$1,124.75
1124.75
1,1221.75
112475.00%
1,12475+03
73
True/False
On/Off
True,
False .
On,
Off.
3.4
012450023
,
12450023
0
000000000
12450
,
#########
;
124500.2375
#######.##
124,500.2345
#,###,###.##
, 0.25
100
####.##%
0,0005834
,
#.##E-
-, +
124500.24
, , 124500.2375
#.##E+
+.
1.25E+5
,
%
-
12450
124 500.23
25%
5,83-4
3.5
Format Currency
Format Numeric
Format Percent
Format DataTime
8675.309
-5000
0,1234
12-31 13:34
Round
123.6
$8,675.31
(5,000.00)
12.34%
12/31/98
1:34:00 PM
124
TextBox
TextBox
.
:
Text1.Top=Y
Text1.Left=X
74
Text1.Text =
MessageBox
MessageBox InputBox .
Windows.
MessageBox .
:
MsgBox Prompt [, Buttons] [,Title] [, Helpfile, Context]
:
< >= MsgBox (Prompt [, Buttons] [,Title] [, Helpfile, Context]
3.1:
(.3.5):
MsgBox , !, vbExclamation, .
:
Text=MsgBox ( ?, vbCritical, End)
Button ;
Icon ;
Default , ;
. 3.5. MsgBox
Modal ( ). ,
;
Extras .
.
Buttons . 3.6
3.2. Buttons.
Type=4+32+256+1
MsgBox , Type, .
. Yes No ( 4),
Warning Query ( 32), No ( 256), ( 1).
3.6
Buttons
0
1
2
Button
(vbOkOnly)
(vbOkCancel)
Cancel
(vbAbortRetryIgnore)
Abort, Retry, Ignore
75
3
4
5
(vbYesNoCancel)
(vbYesNo)
(vbRetryCancel)
524288
vbMsgBoxRight
1048576
vbMsgBoxRtlReading
(MsFlexsGrid) , ,
.
7.
3.2.3.
Visual Basic
, .
.
Sub End
Sub, . VB ( ), .
.
76
( )
.
:
[] Sub [.]_()
, . , . :
Private Sub frmForm1.cmdVvod_KeyUp(KeyCode As Integer, Shift As Integer)
End Sub
: Private ,
; Public , . frmForm1 ,
cmdVvod , KeyUp , , KeyCode , Shift
;
Private Sub Command1_Click ( )
End Sub
,
, .
(Code).
Visual Basic . ,
.
.
,
Sub Enter.
:
Sub <>()
< >
End Sub
:
Sub HelloOut()
Print
End Sub
, .
77
, ,
:
[] Sub [.]_ ()
< >
End Sub
,
.
:
Call.
:
1, 2, ...
. , ,
.
Call :
Call (1, 2,)
Call , , .
, Call (
.).
3.3. .
,
Sub SPoverch(a As Single, b As Single, h As Single, s As Single)
s = 2 * (a * b + (a + b) * h)
End Sub
------------------------------------------------------------------------------Private Sub Form_Click()
Dim x As Single, y As Single, z As Single, s As Single
x = Val(InputBox(" ))
y = Val(InputBox(" "))
z = Val(InputBox(" "))
SPoverch x, y, z, s
Print Str$(s)
End Sub
78
3.2.4.
Visual Basic .
:
- ;
- ;
- ;
- ;
- ;
- -;
- ;
- ;
-
Basic, , , , .
Basic (. 3.7)
3.7
Visual Basic
|x|
ex
x
ln(x)
]x[
]x[
Sin(x)
Cos(x)
Tg(x)
Arctg(x)
Visual
Basic
Abs(x)
Exp(x)
Sqr (x)
Log (x)
Fix(x)
Int(x)
Round (x, n)
Sgn(x)
Rnd(N)
Sin(x)
Cos(x)
Tan(x)
Atn(x)
x
x e
x
x
, x
, e x
x n
. N<0 , N, N=0 , Rnd, N>0 .
Randomize
,
79
.
arctg(). arctg(x)
.
:
Val(c) .
IIf ( , V1,V2) ,
V1, V2, .
, 1. .
,
.
:
Function
( 1 As , [, 2 As ] ) As
< >
=
End Function.
, . = ,
,
. .
,
Visual Basic. , ,
Print:
< > = ( 1 [, 2, ])
Print
:
( 1 [, 2, ])
,
: .
, .
Exit Function.
:
-
80
(Code);
Tools, Add Procedure;
;
Function;
. OK.
x3 x5
x 2i 1
x 2i 1
+
+ ... +
+ ... =
3! 5!
(2i 1)!
i =1 ( 2i 1)!
. n . .
Public Function Factorial(n As Integer) As Double
Dim i As Integer, F As Double
F=1
For i = 1 To n
F=F*i
Next i
Factorial = F
End Function
81
x(2)=b+b
ArrayFunction = x
End Function
3.2.5.
( IF) ( Select Case).
IF
If.
IF:
) (. 3.6, 3.7):
If <> Then <>
If , , , Then. ,
, If.
. 3.6.
If
. 3.7. If
:
If x<e Then Goto m1
IF x<a Then y=Sin(x)*Exp(2^Log(x)): Goto m2
) If
If <> Then <1> Else < 2
,
If.
Then Else , . , .
, ,
IF:
.
)
If <> Then
< >
Else
< >
End If
)
If <> Then
< >
ElseIf <> Then
< >
Else
< >
End If
.
, .
If , .
Select Case
Select Case, IF . .
If, ,
. :
Select Case < >
Case 1
[ ]
Case 2
[]
...
Case Else
[]
End Select
,
(1,2,3,5)
(1 T 9 )
(Is > 0)
, , , , .
"", - "".
. 83
,
, .
, ,
, , . .
IF
: For/Next, While/Wend, Do/Loop.
Rem
Rem If
M1:
i=i:
REM
< , F(i)>
i=i+di
If i<=i Then Goto M1: Rem
Print ""; F
Rem For
For i=i To N Step di
< , F(i)>
Next i
Print "";F
i=i
i=i+di
i<=N
. 3.8
For/Next.
For/Next (. 3.8)
. .
. 3.8. :
For i=i To i Step di
< >
Next I
i , i
, di
.
For Next ,
.
While/Wend.
While/Wend
, .
, ,
. . 3.9. :
While <>
< >
Wend
84
Rem If
F=<>
i=i
M1:
If F<= Then Goto M2
< , F(i)>
i=i+di
Goto M1
M2:
Print ""; F
i=i
F>
Rem
Rem While/Wend
F=<>
i=i
While F>
< , F(i)>
i=i+di
Wend
Print "";F
i=i+di
.3.9.
, .
, .
,
. ,
, .
Do/Loop - ,
"". ,
.
While, , .
Until, ,
. :
)
Do [ ( While | Until) ]
[]
[Exit Do]
[ ]
Loop
Do
[ ]
[Exit Do]
[]
Loop [(While | Until) ]
Exit Do.
85
3.5:
Dim nNumber As Variant
Dim MyArray As Variant
MyArray = Array (3,6,9,9,5,2,3,1)
For Each nNumber In MyArray
If nNumber > 5 then Debug.Print nNumber
Next nNumber
MyArray , nNumber .
nNumber .
.
.
3.6:
Sub ControlVvodaNumber()
3.2.6. :
86
1: .
.
3.1.4. .
.
Option Explicit
Dim a As Single, b As Single, S As Single, N As Integer
Private Sub Integral(a As Single, b As Single, N As Integer)
Dim x As Single, dx As Single
Dim y As Single, i As Integer
x = a: dx = (b - a) / N
For i = 1 To N
y = FNy1(x)
S = S + y * dx
x = x + dx
Next i
End Sub
Function FNy1(x)
Dim y As Single
y=x
FNy1 = y
End Function
Private Sub Command1_Click()
a = Val(InputBox(" ", " "))
b = Val(InputBox(" ", " "))
N = Val(InputBox(" ", " "))
S=0
Integral a, b, N
MsgBox " " & Str(S), , " "
End Sub
2:
. , x=a, x=b, y=0
y=a*x^2+b y=1/(a*x)+b.
87
.
1. (1).
2. : Project\Add Module
3.
.
4.
.3.10.
- .
5. .
: , Click.
6. .
7. .
8. .
9. .
Option Explicit
Public a As Single, b As Single, S As Single, N As Integer
Public x As Single, ax As Single, bx As Single, e As Single
Public Flag1 As Boolean
'
'
Public Sub Integral2(a As Single, b As Single, N As Integer)
Dim y As Single, i As Integer, R As Single
Dim int0 As Single, int1 As Integer
Dim dx As Single
R = 1 + e: int0 = 0
While Abs(R) > e ' ""
'
int1 = int0:
x = a: dx = (b - a) / N
For i = 1 To N ' ""
' N
If Flag1 Then
y = FNy2(x, ax, bx)
Else
y = FNy1(x, ax, bx)
End If
88
S = S + y * dx
x = x + dx
Next i
'
R = (int0 - int1) / 3
N=N*2
Wend
End Sub
Public Function FNy1(x As Single, ax As Single, bx As Single)
'
Dim y As Single
y = ax * x ^ 2 + bx
FNy1 = y
End Function
Public Function FNy2(x As Single, ax As Single, bx As Single)
'
Dim y As Single
y = 1 / (ax * x) + bx
FNy2 = y
End Function
Sub Form_Load()
'
Left = (Screen.Width - Me.Width) / 2
Top = (Screen.Height - Me.Height) / 2
Flag1 = False
End Sub
Sub Command1_Click() '
ax = Val(Text3.Text)
bx = Val(Text4.Text)
'
If ax = 0 And bx = 0 Then
MsgBox " "
Exit Sub
End If
If Flag1 = True And ax = 0 Then
MsgBox " "
Exit Sub
End If
a = Val(InputBox(" ", _
" "))
b = Val(InputBox(" ", _
" "))
N = Val(InputBox(" ", _
" "))
e = Val(InputBox(" ", " "))
89
S=0
Integral2 a, b, N
MsgBox " " & Str(S), , " "
End Sub
Private Sub Command2_Click()
'
Unload Me
End Sub
Private Sub Text1_Change()
Flag1 = False
End Sub
Private Sub Text2_Click()
Flag1 = True
End Sub
3.2.7.
1. ?
2. InputBox?
3. ?
4. Print.
5. ?
6. MsgBox.
7. MsgBox
MsgBox?
8. .
9. ? .
10. VB?
11. ,
.
12. .
13. VB
?
14. .
15. For/Next For/Each.
16. While/Wend.
17. Do/Loop
90
18. Select
Case.
3.3.
3.3.1. .
.
a(i,j):
11 12 ... a1j ... 1n
...
(3.1.)
i1 i2 ... ij ... in
...
m1 m2 ... mj ... mn
ij . i , j
.
VB
(.3.11.): , , .
VB . 60.
. Option Base N, N
0 1. Option Base
(, , ). ,
,
. 3.11.
:
Dim (_ TO _).
:
Dim A(10) As String , 11 ;
91
20 . 5, .
,
, . .
. Dim:
Dim Array1(10, 20). Private.
. Dim .
Public Global .
.
( ) Dim, Private, Public, Static:
Static A (1 TO 5, 1 TO 2).
. , .
( ) .
:
Dim AMassiv ( ) As Variant.
, ReDim , , Variant.
,
.
, ReDim Preserve:
ReDim Preserve MassivA(10, 50)
, Preserve,
, , :
ReDim aArray(10,10)
ReDim Preserve aArray(10,20)
ReDim Preserve aArray(15,10)
92
Erase:
Erase < _>
Erase , .
3.3.2.
Visual Basic :
Array Variant.
Lbound(, )
. , , . :
Dim aArray(5 To 10,15 To 20)
Lbound (aArray, 2) -
;
Ubound (, ) ;
IsArray () , .
3.7. .
Option Explicit
Dim OldMassiv(5 To 10) As Single, NewMassiv() As Single
Sub VvodMasiv1(Massiv As Variant )
Dim i As Integer
For i = LBound(Massiv) To UBound(Massiv)
Massiv(i) = Val(InputBox( & Str$(i) & ))
Print Massiv(; i; )=; Massiv(i)
Next i
End Sub
Private Sub Form_Click()
Cls
VvodMassiv1 OldMassiv
End Sub
93
Sub VvodMassiv2()
Dim i As Integer, j As Integer
Dim m As Integer, n As Integer
n = InputBox( )
m = InputBox( )
ReDim A(n, m) As Single
For i = 1 To Ubound(A,1)
For j = 1 To Ubound(A,2)
A(i, j) = Val(InputBox( ( & Str$(i) & , & Str$(j) & ) _
))
Print A(i, j);
Next j
Print
Next i
End Sub
. ;
Print. ; Print
. , Print
.
3.9.
.
Sub CopyMassiv()
Dim i As Integer
ReDim NewMassiv(LBound(OldMassiv) To UBound(OldMassiv))
For i = LBound(OldMassiv) To UBound(OldMassiv)
NewMassiv(i) = OldMassiv(i)
Print NewMassiv(; i; )=; NewMassiv(i)
Next i
End Sub
Private Sub Form_Click()
Cls
VvodMassiv1 OldMassiv
CopyMassiv
End Sub
Visual Basic 6 :
Sub CopyMassiv1()
Dim i As Integer
ReDim NewMassiv(LBound(OldMassiv) To UBound(OldMassiv))
NewMassiv = OldMassiv
For i = LBound(OldMassiv) To UBound(OldMassiv)
Print NewMassiv(; i; )=; NewMassiv(i)
Next i
End Sub
. ,
94
. .
Array .
Array Array , Array1,
Array2 .. :
Dim Array1 As Variant.
3.10:
Sub ()
Dim i As Long
ReDim A(1 To 20) As Long
ReDim B(1 To 20) As Long
Dim Array1 As Variant, Array2 As Variant, Temp As Variant
For i= 1 To 20
A(i) = i
'
B(i) = 2 * i
A B
Next i
Array1 = A(): Erase A()
Array1 A
Array2 = B(): Erase B()
Array2 B
Temp = Array1
Array1 = Array2
Array2 = Temp
For i = 1 To 20: Print Array1(i), Array2(i): Next i
End Sub
3.3.3.
. ,
.
.
. , , ,
. , VB 6 Swap,
. . .
.
3.12.
Sub Swap(A As Variant, B As Variant)
2
Temp
.3.12.
95
.
Sub SortMassiv(Massiv() As Variant)
Dim i As Integer, j As Integer
For i = LBound(Massiv) To UBound(Massiv) - 1
For j = i + 1 To UBound(Massiv)
If Massiv(j) < Massiv(i) Then
Swap Massiv(i), Massiv(j)
End If
Next j
Next i
End Sub
Dim OldMassiv(5 To 10) As Variant, NewMassiv() As Variant
--------------------------------------------------------------------------------Private Sub Form_Click()
Cls
Dim i As Integer
VvodMassiv1 OldMassiv
ReDim NewMassiv(LBound(OldMassiv) To UBound(OldMassiv)) As Variant
NewMassiv = OldMassiv
SortMassiv NewMassiv()
For i = LBound(OldMassiv) To UBound(OldMassiv)
Print OldMassiv(i), NewMassiv(i)
Next i
End Sub
NewMassiv. . .
, . Option1 , Option2 , Option3 (. 3.13), . : True - False.
, . .
Sub SortMassiv1(Massiv() As Variant)
Dim i As Integer, j As Integer
For i = LBound(Massiv) To UBound(Massiv) - 1
For j = i + 1 To UBound(Massiv)
96
. 3.13.
If Option1 Then
If Massiv(j) < Massiv(i) Then
Swap Massiv(i), Massiv(j)
End If
ElseIf Option2 Then
If Massiv(j) > Massiv(i) Then
Swap Massiv(i), Massiv(j)
End If
Else
Exit Sub
End If
Next j
Next i
End Sub
,
.
OptionsButton.
.
.
Click.
Value.
Value : 0 - , 1 , 2
, .
. , Option1.Value = 2.
(Frame), . Value OptionsButton , , , If Option1.Value Then If Option1
Then .
3.3.4. :
. () .
.
3.3.5.
1. .
2. .
97
3. ?
4. ?
5. ?
6. .
7. .
8. .
9. .
1. .
2. Value
OptionButton.
3. .
4. .
5. .
6. ,
.
7. ,
.
8. .
9. .
10. .
11. .
12. .
3.4. .
3.4.1.
Microsoft Visual Basic 6.0
,
. (control array).
, . ,
.
Index,
Caption
Tag. , , ,
Index . 98
Index 32767,
.
,
, .
:
- . , ,
. , . , , ;
- , ,
, ;
- . ,
, , , .
:
- ;
-
;
- .
:
1.
, .
2. Name .
3. . : ? . .
4. , .
99
:
1. .
2. .
3. .
. .
:
1. .
2. ,
.
.
3. .
.
. .
:
(). =
:
txtText1(0).Text =
txtText1(1).Text =
Load Add.
Index .
Load ()
100
. Index ,
.
Unload. () ,
:
Unload (Index)
.
3.11.
cmdAddTextbox:
Private Sub cmdAddTextBox_Click().
Dim i As Integer.
( 0)
i = txtMassiv().Count
Load txtMassiv(i)
txtMassiv(i).Top = txtMassiv(i-1).Top + txtMassiv(i).Height
txtMassiv(i).Visible=True.
End Sub
3.4.2.
MSFlexGrid
. .
ToolBox.
Project\Components
Microsoft Flex Grid Control 5.0.
80 , 20 10 .
Heigt ; Width - ; Enabled .
ScrolBar - , 4 (0- , 1- , 2- , 3 ).
: Custom Properties ,
.
.
Cols, Rows .
Col, Row - / .
ColPosition, RowPosition
. :
.ColPosition(N)=%
101
.RowPosition(N)=%
N .
ColWidth, RowHeight - . .
Text, TextMatrix - ,
. TextMatrix :
TextMatrix ( , ) =
Row Col.
ColAlignment - :
0 - ;
1 - ;
2 - .
: C. ColAlignment () = %
10 Alignment
.
FixedCols, FixedRows, FixedAlignment ,
:
. FixedRows = %
LeftCol, TopRow ,
. ,
:
. LeftCols = %
. TopRows = %
GridsLines .
ScrollBars .
3.12. 4 , 5 - ,
. :
MSFlexGrid1.Col = 3
MSFlexGrid1.Row =4
MSFlexGrid1.Text =
MSFlexGrid1.Col =0
MSFlexGrid1.Row=0
MSFlexGrid1.Text =
MSFlexGrid1.TextMatrix(3,4)=" "
ColSel, RowSel .
, :
MSFlexGrid1:Row=0: MSFlexGrid1.Col=0
MSFlexGrid1:ColSel=4: MSFlexGrid1.RowSel=3
102
0 4 0 3
Clip - :
.Clip=
, .
, .
MSFlexGrid1.Col =0; MSFlexGrid1.Row =0
MSFlexGrid1.ColSel=2; MSFlexGrid1.RowSel=1
S$=Str$(1)+vbTab+Str$(2)+vbTab+Str$(4)
S$=$+vbr+Str$(4)+vbTab+Str$(5)+vbTab+Str$(6)
MSFlexGrid1.Clip=S$
vbTab ;
VbCr - .
FillStyle - . ,
. 0.
HighLight : 0 - , 1 ; 2 .
AllowBigSelection
. : True False.
AllowUserResizing
: 0 - , 1 ; 2 ; 3 .
Sort : 0 ; 1 ; 2
; 3 , ; 4
, ; 5
; 6 ; 7 ; 8 ; 9
Compare.
EnterCell, LeaveCell .
RowColChange -
.
AddItem .
MsFlexGrid1.AddItem Item$[, ]
Item$ .
,
. .
RemoveItem .
MsFlexGrid1. RemoveItem < >
103
3.4.3. :
1.
.
. 3.14.
TextBox Text1 Index
0. .
.3.14.
.3.15.
.
Private Sub Command1_Click()
Dim i As Single
i = Text1().Count
Load Text1(i)
Text1(i).Text = "" & Str$(i)
Text1(i).Top = Text1(i - 1).Top + Text1(0).Height
Text1(i).Visible = True
End Sub
Private Sub Command2_Click()
Dim i As Single
i = Text1().Count - 1
If i > 0 Then
Unload Text1(i)
End If
End Sub
104
2. y=sin(x)
.
.
1. Visual Basic.
2. .
3. (.3.15).
4. (. 3.8).
5. Label
, , dX:
- . . Index
0;
- .
Index . (1,2);
3.8
Form1
Label(0)
Label(1)
Label(2)
Text1(0)
Text1(1)
Text1(2)
Label2(0)
Label3(0)
Command1
Name
Caption
Name
Caption
Index
Name
Caption
Index
Name
Caption
Index
Name
Caption
Index
Name
Caption
Index
Name
Caption
Index
Name
Caption
Aligment
Index
Enabled
Name
Caption
Aligment
Index
Enabled
Name
frmMassivUpravl
lblLabel1
=
0
lblLabel1
Y=
1
lblLabel1
dX=
2
txtText1
0
0
txtText1
0
1
txtText1
0
2
lblArgument
X
2
2
False
lblFunction
Y
3
2
False
cmdCalc
105
Command2
Caption
Name
Caption
cmdExit
6. TextBox
X, , dX:
- . .
Index 0;
- .
Index . (1,2);
7. , ,
Index ,
Caption X Y .
8. : .
9. .
Dim x As Single, y As Single, dx As Single
------------------------------------------------------------Private Sub cmdCalc_Click()
Dim i As Integer
Xnach = Val(txtText1(0).Text)
Xkon = Val(txtText1(1).Text)
dx = Val(txtText1(2).Text)
n = Int((Xkon - Xnach) / dx) + 1
x = Xnach
For i = 1 To n
'
Load lblArgument(i): Load lblFunction(i)
'
y = Sin(x)
'
lblLabel2(i).Top = lblLabel2(i - 1).Top + lblLabel2(0).Height
lblLabel3(i).Top = lblLabel3(i - 1).Top + lblLabel3(0).Height
Format
,
If x <> 0 Then
lblArgument(i).Caption = Str$(Format(x, "####.##"))
Else
lblArgument(i).Caption = Str$(x)
End If
If y <> 0 Then
lblFunction(i).Caption = Str$(Format(y, "####.##"))
Else
lblFunction(i).Caption = Str$(y)
End If
lblArgument Visible = True: lblFunction(i).Visible = True
x = x + dx
Next i
106
End Sub
-----------------------------------------------------------------------------------------------Private Sub cmdExit_Click()
Unload Me
End Sub
10. .
11. .
12.
.
3.
(.3.16).
.
1. 1-6 1.
. 3.16.
2. MSFlexGrid Project\Components\ Microsoft Flex Grid Control 5.0.
3. MSFlexGrid.
2 3.
4.
Dim Xn As Single, Xk As Single, Dx As Single
Dim X As Single, Y As Single, N As Integer
---------------------------------------------------------------Private Sub Command1_Click()
Xn = Val(Text1(0).Text)
Xk = Val(Text1(1).Text)
Dx = Val(Text1(2).Text)
Cls
N = Int((Xk - Xn) / Dx) + 1
Grid1.Rows = N + 1
For I = 1 To N
Y = Sin(X)
Grid1.Row = I
Grid1.Col = 0
Grid1.ColAlignment(0) = 2
Grid1.Text = Str$(I)
Grid1.Col = 1
If X <> 0 Then
Grid1.Text = Str$(Format(X, "#.##"))
Else
Grid1.Text = Str$(X)
End If
Grid1.ColAlignment(1) = 2
Grid1.Col = 2
If X <> 0 Then
107
6. . 10 - 12 1.
3.4.4.
1. ?
2. ?
3. ?
4. ?
5. MSFlexGrid?
6. MSFlexGrid
ToolBox?
7. ?
8. ?
9.
.
10. ?
11.
.
12. .
108
1.
Label TextBox
.
2.
Label a b.
3.
TextBox a b.
4.
CommandBox a.
5.
Label R n .
6.
TextBox M D .
7.
Label , .
8.
TextBox ,
.
9. 1010
.
10. 510 .
11. 105
.
12. 1010 .
13. 810 , 1 1000 D c
.
14. 1010 1 1000 D .
15. 510 ,
.
109
4. Visual Basic.
4.1. Visual Basic.
4.1.1. . Scale
, . , . Windows
800600 .
Visual Basic 6.0 , .
(Form)
(Picture Box). .
.
Line Shape. Image.
, , , .
, - , ,
, ..
.
x=0; y=0, 0
X
IV (.4.1).
VB .
YX
= 1/1440 .
. 4.1.
,
1 (1 =2,5 ).
ScaleMode, :
1. ( );
2. (72 );
3. ( ,
Windows);
4. (12 20 );
5. ;
110
6. ;
7. .
Form1.ScaleMode = 3 .
Form1.ScaleMode = 7 - .
Scale
, ,
Scale. :
[]. Scale (x1,y1) (x2,y2)
x1,y1 ; x2,y2-
.
.
Scale(-5,-10)-(5,10) ,
Scale(-5,10)-(5,-10) Y
:
Object. ScaleLeft =xxxx
Object. ScaleTop = xxxx
:
Picture1. ScaleLeft =100
Picture1. ScaleTop = 50
- ()
- ()
- ()
- ()
ScaleWidth, ScaleHeight:
ScaleWidth = 3200 -
ScaleHeight = 2000 - .
,
.
Screen
VB Screen. Screen Screen Global.
Windows, Screen , Screen.
Screen :
ActiveControl - ;
ActiveForm - ;
FontCount - ;
Fonts( )
- ;
Height
- ;
MouseIcon
-
;
TwipsPerPixelX - ( );
111
TwipsPerPixelY - ( );
Width
- .
:
HeightInTwips = Screen.Height
WidthInTwips = Screen.Width
:
HeigtInPixel = Screen.Height / Screen.TwipsPerPixelY
WidthInPixel = Screen.Width / Screen.TwipsPerPixelX
ActiveControl
. ,
Screen.ActiveControl.
:
Private Sub mnuDelete_Click ( )
.
Screen. ActiveControl.SelText =
End Sub.
:
Screen.ActiveForm.ActiveControl.SelText =
TypeOf
:
Private Sub mnuDelete_Click()
If TypeOf Screen.ActiveControl Is TextBox Then
' .
Screen.ActiveControl.SelText = ""
ElseIf TypeOf Screen.ActiveControl Is PictureBox Then
'
Screen.ActiveControl.Picture = LoadPicture()
End If
End Sub
: TextBox,
, PictureBox,
( LoadPicture ()).
. .
, .
,
SelText, .
;
&H000080FF& - .
;
- RGB : RGB (Red, Green, Blue).
RGB
: , .
0 255.
.4.2.
Line
. 255*255*255 . :
R=100: G=150: B=75
Line.BorderColor=RGB(R,G,B)
- Visual Basic. 8 : vbBlack ; vbBlue - ; vbCyan - ; vbGreen - ; vbMagenta - ; vbRed - ; vbWhite - ; vbYellow ;
- QBColor ( C), - 0 15:
-
-
-
-
-
-0
-1
-2
-3
-4
-5
-6
-7
-8
-9
- 10
- 11
- 12
- 13
-14
-15
Line ,
. Line
113
. Line Resize.
4.1. (.4.2)
Option Explicit
Dim x1 As Single, x2 As Single, y1 As Single, y2 As Single
Dim i As Integer
-----------------------------------------------------------------------------Private Sub Form_Resize()
' .
Line3.x1 = 0
Line3.y2 = 0
Line3.x2 = Form1.ScaleWidth
Line3.y1 = Form1.ScaleHeight
Line3.BorderColor = vbRed
End Sub
-----------------------------------------------------------------------------Private Sub Form_Click()
For i = 0 To 6
Line1(i).BorderStyle = i
Line1(i).BorderColor = QBColor(i + 8)
Line2(i).BorderColor = QBColor(i + 1)
Next i
End Sub
Line1 Line2 .
Shape
Shape : , , , .
Shape ,
Line, . Top, Left,
Height, Width, Shape, BorderStyle, BorderWidth, FillStyle, FillColor.
Top, Left, Height, Width . .
Shape : 0 - ; 1 ; 2 ; 3 ; 4
; 5 (. 4.3.).
FillStille - ,
. 8 : 0 - ; 1 ; 2- ; 3- ; 4 ; 5- ; 6- ; 7- .
114
BorderStyle, BorderWidth
.
Line.
FillColor
. BorderColor
Line.
4.2. Shape.
:
Shape, FillStyle, BorderStile, BorderWidth, FillColor Shape, Click
:
.4.3.
Shape
Option Explicit
Dim i As Integer, j As Integer
--------------------------------------------Private Sub Command1_Click()
If i > 5 Then i = 0
Shape1.Shape = i
i=i+1
End Sub
--------------------------------------------Private Sub Command2_Click()
If i > 6 Then i = 0
Shape1.BorderWidth = 1
Shape1.BorderStyle = i
i=i+1
End Sub
---------------------------------------------
115
Shape1(i).Visible = True
Load Label1(i)
Label1(i).Caption = i
Label1(i).Top = Label1(i - 1).Top + Label1(i - 1).Height + 350
Label1(i).Visible = True
Next i
For i = 1 To 7
Load Shape2(i)
Shape2(i).FillStyle = i
Shape2(i).Top = Shape2(i - 1).Top + Shape2(i - 1).Height + 40
Shape2(i).Visible = True
Load Label2(i)
Label2(i).Caption = i
Label2(i).Top = Label2(i - 1).Top + Label2(i - 1).Height + 350
Label2(i).Visible = True
Next i
End Sub
-------------------------------------------------------------------------------------------------Private Sub Form_Load()
Me.Height = 5150
Me.Width = 3800
End Sub
4.1.3.
ScaleMode =3
,
TwipsPerPixelX TwipsPerPixelY.
Pset. :
Pset(x,y) [, C].
Pset ,
. , VB .
Point.
, ( ). :
Object. Point(x,y)
4.4. .
ex Sin(x) 2 2.
.
. ( PictureBox) .
116
,
. ,
.
Line.
Option Explicit
Dim x As Single, y As Single
Dim xn As Single, ymin As Single
Dim xk As Single, ymax As Single
Dim dx As Single
---------------------------------------------Function FNy(x As Single)
y = Exp(x) * Sin(x)
FNy = y
End Function
---------------------------------------------Private Sub Form_Click()
Picture1.Cls
Picture1.ScaleMode = 3
xn = Val(Text1(0).Text)
xk = Val(Text1(1).Text)
dx = Val(Text1(2).Text)
ymax = FNy(xn): ymin = ymax
For x = xn To xk + dx / 2 Step dx
y = FNy(x)
If y > ymax Then ymax = y
If y < ymin Then ymin = y
Next x
Picture1.Scale (xn, ymin)-(xk, ymax)
For x = xn To xk + dx / 2 Step dx
y = FNy(x)
Picture1.PSet (x, y), vbRed
Next x
End Sub
4.1.4. :
1. , 4.1- 4.4.
2. Shape
, 4.1.5.
3. ex [-2,2].
2. ,
, . , Pset.
4.1.5.
1.
2.
3.
4.
5.
6.
7.
8.
? .
? .
?
?
, , ?
Scale. .
Screen ?
Screen ActiveControl?
117
9. Line.
10. Shape.
11. VB ?
12. RGB .
13. ?
14. PSet.
15. .
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Line
BorderStyle
BorderWidth
BorderColor (RGB)
BorderColor (VB .)
BorderStyle
BorderWidth
BorderStyle
BorderColor (QBColor)
BorderStyle
BorderWidth
BorderColor (RGB)
BorderStyle
BorderWidth
BorderStyle
BorderColor (VB .)
Shape
Shape
FillColor (RGB)
BorderStyle
BorderWidth
FillStyle
Shape
FillColor (VB .)
BorderStyle
BorderWidth
FillStile
Shape
FillColor (QBColor)
BorderStyle
BorderWidth
FillStile
Print .
.
. 4.1.
4.1
,
DrawMode
DrawStyle
DrawWidth
FillColor
FillStyle
FillColor
AutoRedraw
,
.
O .
, .
,
.
, .
, .
, ,
( Form PictureBox )
4.2.1. Line
Line .
:
[ .]Line [(1,y1)] (x2,y2), C, B[F]
. .
Current x= 1500
Current y= 750
Line (x2,y2) 1500, 750 _
x2, y2 ( )
Line (100, 850) (500,1800), vbBlue, B
Line (200,150) (300,1000), vbRed, BF '
119
Me.BorderStyle = 2: Me.DrawWidth = 2
Line (50,100) (1200,500), vbGreen, B ' , _
2
4.2.2. Circle
Circle .
:
[.] Circle [Step] (x, y), R, C, [-] (start), [-] (end),
, ; R , - ;
, 0; ,
2. . : */180, - .
, .
Const PI As Double = 3.14159
Circle (200,200), 150, vbRed -
Circle (300,100), 100, vbGreen, 30/180*PI, 120/180*PI, 1.5
30 120
Circle (500,300), 200, vbBlue, -30/180*PI, -120/180*PI
4.5. .
.
. Line.
.
Const Pi = 3.14159
Option Explicit
-----------------------------------------------------------------------------------Private Sub Form_Click()
Dim x As Single, y As Single, dx As Single
Dim xn As Single, xk As Single
Dim y1 As Single
If Text1.Text = "0" Or Text2.Text = "0" Or Text3.Text = "0" Then
MsgBox " "
Exit Sub
End If
xn = Val(Text1.Text)
xk = Val(Text2.Text)
dx = Val(Text3.Text)
Scale (xn, 10)-(xk, -10)
Line (xn, 0)-(xk, 0)
Line (0, -5)-(0, 10)
120
y = Exp(xn): PSet (xn, y), vbRed
For x = xn To xk Step dx
If y <= 10 Then
y = Exp(x)
Line -(x, y), vbRed
End If
Next x
y1 = Cos(xn): PSet (xn, y1), vbBlue
For x = xn To xk Step dx
y1 = Cos(x)
Line -(x, y1), vbBlue
Next x
End Sub
------------------------------------------------------------------------------------Private Sub Text1_LostFocus()
( )
If Not IsNumeric(Text1.Text) Then
Beep
MsgBox " "
Text1.SetFocus
End If
End Sub
4.6. (. 4.4.)
N . .
. .
.
1. . InputBox. .
2. .
, Bd=100, X
= 2*Bd =200.
Hd= max.
Y .4.4.
My=2*Hd. :
Scale (0, My)-(Mx, 0)
3. .
cx = (MxBd)/2, Y cy = (My Hd)/2.
121
4. .
, dx= bd/(N+1), N .
,
.
Line:
Line (cx, cy)-(cx, cy+Hd), vbBlue '
Line (cx, cy)-(cx + Bd, cy), vbBlue '
5. . ,
.
Line
Line (cx + (i - 1) * dx, cy)-(cx + i * dx, cy + A(i)), QBColor(i), BF
. Click . . ,
,
. , , .
, . , , . ,
. .
6. :
Option Explicit
Dim A() As Single
-----------------------------------------------------------------------------------Private Sub Form_Click()
Dim i As Integer, N As Integer, S As Single, Bd As Single, Hd As Single
Dim max As Single, dx As Single, Mx As Single, My As Single
Dim cx As Single, cy As Single
Label1.Visible = False
max = -1E+38
N = Val(InputBox(" "))
ReDim A(N) As Single
max = -1E+38
Bd = 100: Mx = 2 * Bd
For i = 1 To N
A(i) = Val(InputBox(" " & Str$(i) & ""))
If A(i) > max Then max = A(i)
Next i
Hd = max: My = 2 * Hd
Me.Scale (0, My)-(Mx, 0)
cx = Bd / 2: cy = Hd / 2
dx = Bd / (N + 1)
' '
Line (cx, cy)-(cx, cy + Hd), vbBlue '
Line (cx, cy)-(cx + Bd, cy), vbBlue '
For i = 1 To N
122
4.7. .
N .
Dim i As Integer, k As Integer, ttime As Single
Const Pi = 3.14
-----------------------------------------------------------------------------------Private Sub Form_Click()
Dim n As Integer, dx As Single
Me.Scale (0, 0)-(200, 200)
n = Val(InputBox(" "))
k=0
dx = 360 / n
For i = 0 To 360 - dx Step dx
If k > 15 Then k = 0: 'MsgBox " "
Circle (100, 100), 50, QBColor(k), -i / 180 * Pi, -(i + dx) / 180 * Pi
ttime = Timer
tretri:
If Timer - ttime < 0.5 Then GoTo tretri
DoEvents
k=k+1
Next i
End Sub
4.8. N .
4.3,
. ,
.
.
Private Sub Form_Click()
Dim n As Integer, dx As Single
Me.Scale (0, 0)-(200, 200)
n = Val(InputBox(" "))
k=0
dx = 360 / n
For i = 0 To 360 - dx Step dx
a = i: a1 = i + dx
If k > 15 Then k = 0: 'MsgBox " "
For j = a To a1 - 0.5 Step 0.5
Circle (100, 100), 50, QBColor(k),-j / 180 * Pi, -(j + 0.5) / 180 * Pi
Next j
k=k+1
Next i
End Sub
4.9.
123
.
. .
.
1. . InputBox. B(). S.
2. . , da =360/S.
3. .
. f1 .
f2= B(i)*da..
f3=f1+f2.
QBColor(k).
, k. K
15.
4. .
Private Sub Form_Click()
Dim n As Integer, dx As Single, s As Single, a As Single, a1 As Single
Dim da As Single, fi1 As Single, fi2 As Single, fi3 As Single
Dim i As Integer, j As Single, k As Integer, ttime As Single
Me.Scale (0, 0)-(200, 200)
n = Val(InputBox(" "))
ReDim b(n)
Cls
s=0
For i = 1 To n
b(i) = Val(InputBox(" " & Str$(i) & ""))
s = s + b(i)
Next i
da = 360 / s
k = 0: fi1 = 0
For i = 1 To n
fi2 = b(i) * da
fi3 = fi1 + fi2
If k > 15 Then k = 0
For j = fi1 To fi3 - 1 Step 1
Circle (100, 100), 50, QBColor(k), -j / 180 * Pi, -(j + 1) / 180 * Pi
Next j
k=k+1
fi1 = fi3
Next i
End Sub
4.2.3. Print
124
Print , .
.
Print
Print , :
CurrentX ;
CurrentY ;
Font - ;
ForeColor - ;
FontTransparent ,
.
:
CurrentX=100
CurrentY=100
, ,
, Font
Me.Font.Italic = True
Me.Font.Size = 12
Me.ForeColor=vbRed
Print
4.2..4. :
1. ,
4.5 4.9.
2. Line c
DrawWidth .
3. Circle
FillColor .
4.2.5.
1. .
2. Line. .
3. Circle. .
4. .
5. .
6. .
7.
?
125
8. Print. Print?
1. .
Y.
2. (.4.4).
3. . Y, .
4. .
5. .
6.
.
4.2
, PictureBox
.bmp
.dib
.ICO, .CUR
.wmf
.emf
.gif
.jpg, .peg
( ) 6
- (Device Independent
Bitmap)
, ,
Windows
Graphics Interchange Format - Web - Internet7
Joint Photographic Experts Group ,
, Web-
Internet8
4.3.2. (PictureBox )
PictureBox
. , .
PictureBox .
: Align, Autosize, Picture.
Align - PictureBox : 0 - None, 1 - Top, 2 Bottom, 3 - Left, 4 - Right. , (None).
, ( )
.
Autosize - , . Autosize False, , , 6
127
. Autosize True, .
Picture - , .
Picture Load Picture,
. :
C:\Windows\.bmp
LoadPicture:
.Picture = LoadPicture("_")
,
.
SavePicture. .BMP:
SavePicture(Picture1.Picture, BUILD.BMP)
PictureBox , , ( Print).
, PictureBox, , .
Picture bitmap Del.
:
.Picture = LoadPicture()
4.10.
Private Sub Form_Click()
Cls
Dim X As Single, Y As Single
picPicture1.CurrentX = 100
picPicture1.CurrentY = 100
picPicture1.Print " "
' , ,
'
picPicture1.Font.Italic = False
picPicture1.Font.Size = 12
picPicture1.ForeColor = vbRed
picPicture1.CurrentX = 400
picPicture1.Print " "
picPicture1.CurrentX = 700
picPicture1.CurrentY = 600
picPicture1.Font.Size = 8
picPicture1.ForeColor = vbBlack
picPicture1.Print " , =700 "
'
128
X = 2000: Y = 1000
picPicture1.DrawWidth = 15
picPicture1.PSet (X, Y), vbRed
picPicture1.CurrentX = 900: picPicture1.CurrentY = 900
picPicture1.Print ""
picPicture1.DrawWidth = 2
picPicture1.Line (0, 0)-(3000, 1500), vbBlue
picPicture1.Circle (2000, 1000), 500, vbGreen
picPicture1.CurrentX = 1100: picPicture1.CurrentY = 1200
picPicture1.Print "1"
End Sub
PictureBox . , (.ICO)
(.bmp).). ,
.bmp. (
4.3.3. Image
Image .
PictureBox, . Image , . Image
, PictureBox. Image .
Image Stretch Picture.
Picture PictureBox.
Stretch
. Stretch True,
Image, .
4.3.4.
. , .
Label Shape. Label Shape , BackStyle Transparente.
, ,
129
PictureBox
Image.
:
- , ;
- ;
- ;
. ;
- .
Picture MDI .
4.11. .
Image PictureBox.
AutoSize PictureBox Stretch Image True.
Image PictureBox .
, Picture
, : C:\Windows\.BMP,
C:\Windows\.BMP, C:\Windows\.BMP. .
Private Sub Form_Click()
Dim i As Double
Form1.Picture = LoadPicture()
Image1.Picture = LoadPicture()
picPicture1.Picture = LoadPicture()
For i = 1 To 50000: DoEvents: Next I
Form1.Picture = LoadPicture("C:\Windows\.BMP")
Image1.Picture = LoadPicture("C:\Windows\.BMP")
picPicture1.Picture = LoadPicture("C:\Windows\.BMP")
End Sub
4.3.5.
Visual Basic .
AutoRedraw
AutoRedraw .
False, VB
.
AutoRedraw True.
130
, AutoRedraw, True, .
VB . , .
True
.
, .
VB , ,
.
, ,
.
Paint
.
AutoRedraw , , (
Form PictureBox). True , .
Paint . Paint,
AutuRedraw, ,
.
Refresh
. AutoRedraw True.
VB
Paint, .
Form_Resize, , Paint. ,
VB , . Refresh Paint, .
:
Private Sub Form_Resize ( )
Form1.Refresh
End Sub
Refresh
. VB . .
131
Refresh.
Refresh Form_Resize
,
Paint.
ClipControls
ClipControls .
ClipControls True ( ),
AutoRedraw False, VB . ClipControls False, Visual Basic .
ClipControls True
. , VB
.
False ,
, , . , . , Image, Label, Line Shape.
ClipControls AutoRedraw . 4.3.
4.3
ClipControls AutoRedraw
ClipControl
Autoredraw
True ( - False
VB
)
False
False
VB
False
True
AutoRedraw
True, ClipControls False.
PaintPicture
PaintPicture ,
() .
height width ,
. :
.PaintPicture .Paint X, Y, B, H, X1, Y1, [B1,H1]
, , , ; X, Y
132
, B, H ; X1, Y1 ; B1, H1
.
Picture1.PaintPicture Form1.Picture, 0, 0, 1500, 1000, 0, 0, 7000, 5000
PictureBox .
(1, 1) ,
.
PaintPicture :
- , , ;
- ;
- PictureBox Printer, , .
Point
Point RGB ,
: Point ( , )
4.12. .
Private Sub Form_Load ( )
Me. AutoRedraw = True
Line (0,0) (1500,1500), VbRed, BF
End Sub
-------------------------------------------------------------------------------------------------Private Sub Form_MouseDown (Button As Integer, _
Shift As Integer, X As Single, Y As Single)
X = Val(InputBox(" "))
Y = Val(InputBox(" Y"))
If Point (x,y) = VbRed Then
MsgBox ( & x & , & y &)
Else
MsgBox
End If
End Sub.
Visual Basic c ,
, :
SavePicture
.Image.
Image ,
: .
, VB
:
SavePicture
Image._
133
,
Picture, VB , , VB bitmap (.bmp).
DoEvents
Visual Basic
.
:
. . .
DoEvents. , Visual Basic ,
.
DoEvents
, .
.
4.3.6. :
1. PictureBox. Line, Circle, Point Print (ClipControls AutoRedraw) (. 4.3, 4.10).
2. PictureBox.
. AutoSize Align . .
3. Image. . Stretch .
4. PictureBox Image. PictureBox
Image.
5. Point ( 4.12).
4.3.7.
1. PictureBox?
2. PictureBox?
3. AutoSize , PictureBox?
134
4. VB?
5. ?
6. Image?
7. Image?
8. AutoRedraw?
9. Refresh?
10. ClipControl ?
11. PaintPicture.
12. Point.
4.4.
4.4.1. Animation
Animation
.
AVI. ().
,
, .
Animation ,
, Windows.
. Image
.
Animation
,
. . , .
Click
, .
Animation : Open, Play, Stop.
Open .
Animation1.Open
135
anmAviPlayer.Play 2,5, 15
Repeat
Start
Stop
. 4.5. Play
Stop .
Animation1.Open C:\Progra~1\Micros~1\Common\Graphics\Video\ FileNuke.AVI
Animation1.Play 2,5, 15
, . 4.5.,
5 15.
4.4.2.
.
:
- Top Left CurrentX, CurrentY ;
- Move;
- ;
-
.
:
- ;
- , ( ). , ;
- ;
- .
136
VB
, . . , , .
DrawMode,
.
DrawMode
15 DrawMode. VB
, .
DrawMode = 7, or.
DrawMode = 6 Not, DrawMode = 4 VB Not
.
Xor ,
.
DrawMod = 7
.
Move.
:
Command1.Move x, y
,
, .
:
.
: , , .
:
For i=1 To 1000: DoEvents: Next i
:
T=Time() T=Timere()
While Time() T < 2: Wend
137
Visual Basic 36 .
: Intrval Enabled. Timer.
Interval - 0 10000,
. .
Enabled . Enabled True, . Enabled
False .
Private Sub Timer1_Timer()
Static TimerTimes As Integer
TimerTimes = TimerTimes + 1
If TimerTimes = 2 Then
TT = TimerTimes
TimerTimes = 0
Else
Exit Sub
End If
End Sub
Timer ,
.
.
4.13. -
.
Dim TT As Integer
Option Explicit
-------------------------------------------------------Private Sub Form_Click()
Dim x As Single, y As Single, a As Single
Dim xmove As Single, ymove As Single
Dim i As Integer, j As Integer, ttek As Integer
Dim TimerTimes As Integer
Randomize (1)
Me.ScaleMode = 3 '
Me.WindowState = 2
x = Me.ScaleWidth / 2
y = Me.ScaleHeight / 2
PSet (x, y)
For i = 0 To 50
If j > 15 Then j = 0
xmove = 100 * Rnd
ymove = 50 * Rnd
If Rnd < 0.5 Then
x = x + xmove
Else
x = x - xmove
End If
138
4.14.
Dim TT As Integer
Option Explicit
----------------------------------------------------------Private Sub Form_Click()
Dim x As Single, y As Single, a As Single
Dim xmove As Single, ymove As Single
Dim i As Integer, j As Integer, ttek As Integer
Dim TimerTimes As Integer
Randomize (1)
Me.ScaleMode = 3 '
Me.WindowState = 2
x = Me.ScaleWidth / 2
y = Me.ScaleHeight / 2
PSet (x, y)
For i = 0 To 50
If j > 15 Then j = 0
xmove = 100 * Rnd
ymove = 50 * Rnd
If Rnd < 0.5 Then
x = x + xmove
Else
x = x - xmove
End If
If Rnd < 0.5 Then
y = y + ymove
Else
y = y - ymove
End If
139
:
- , ClipBoard;
, (ImageBox, PictureBox .);
.
. 4.4.
4.4.
VbCFText
VbCFBitmap
VbCFMetaFile
VbCFFMetaFile
VbCFDIB
VbCFPalette
VbCFRtf
140
(*.bmp)
(*.Wmf)
(*.EMF)
(*.dib)
*.rtf
Image 1
Image 2
Command 1
. 4.6.
GetData() .
: .GetData [,]
GetFormat , ,
.
: .GetFormat[,]
4.15. ,
Image1.Picture Image2.Picture (.4.6.):
Private Sub Command1_Click()
Dim i As Integer, j As Long
Clipboard.Clear
Clipboard.SetData Image1.Picture, vbCFBitmap
For i = 1 To 300
Image2.Left = 1000 + i * 20
Image2.Top = 480 + i * 20
For j = 1 To 100000: Next j
Image2.Picture = Clipboard.GetData()
Next i
End Sub
Picture1
Picture2 Picture3
Picture4
4.16.
Picture6
Picture
Yellow
.
(. 4.7.) Picture7
Red
. .
. 4.7.
PictureBox Image. , , , ( Paint ).
.
Picture1, Picture2, Picture3, Picture4
Picture5, Picture6, Picture7. 1- 4 .
Picture5
Green
141
ltime = Timer()
'
While Timer() - ltime < 1: Wend
Picture6.Picture = Picture4.Picture
Picture7.Picture = Picture4.Picture
Picture5.Picture = Picture1.Picture
ltime = Timer()
'
While Timer() - ltime < 0.5: Wend
Picture5.Picture = Picture4.Picture
Picture6.Picture = Picture2.Picture
ltime = Timer()
'
While Timer - ltime < 1: Wend
Picture6.Picture = Picture4.Picture
Picture7.Picture = Picture3.Picture
Next i
End Sub
4.17..
Private Sub Form_Click()
Const Pi = 3.14159
Const Alfa = 50
Dim x As Integer, y As Integer, r As Integer
Dim xNach As Single, xKon As Single, nCount As Integer
Dim i As Integer, j As Integer, A As Integer
x = Me.ScaleWidth / 2
y = Me.ScaleHeight / 2
r=x/2
Me.FillStyle = vbSolid
'
Me.DrawMode = vbCopyPen
'
Me.FillStyle = vbFSTransparent
'
Me.Circle (x, y), r
'
Me.DrawMode = vbXorPen '
Me.FillColor = vbGreen 'QBColor(5)
Me.FillStyle = vbSolid '
nach:
For i = 0 To 360
xNach = i
xKon = i + Alfa
If xKon > 360 Then xKon = xKon - 360
Me.Caption = "" & Alfa & " " & i
Me.Circle (x, y), r, , -xNach * Pi / 180, -xKon * Pi / 180
For j = 1 To 15000: A = A: Next j
DoEvents
Me.Circle (x, y), r, , -xNach * Pi / 180, -xKon * Pi / 180
Next i
GoTo nach
Me.Caption = " "
142
End Sub
4.4.3. ,
, .
, .
Move FormResize . Move :
.Move Left, Top, Width, Height
4.18.
Private Sub Form_Resize()
Dim TheHeight As Single, TheWidth As Single
TheHeight = (495 / 4140) * ScaleHeight
TheWidth = (1215 / 6690) * ScaleWidth
Command1.Move ScaleWidth / 2 TheWidth / 2, ScaleHeight TheHeight, _
TheWidth, TheHeight
End Sub
495
4140
1215
6600
.
. .9
4.4.4. :
, 4.13
4.17.
,
, - , .
\\
.
, . .
143
4.4.5.
1. Animation.
2. DrawMode?
3. .
4. .
5. ?
6. ?
7. .
8. , .
9. .
10. .
11. .
12. .
1.
:
- ;
- ;
- ;
- .
2. .
3. , .
5.
.
144
5.1. VB
, , .
. Toolbox , . , , , , , , , , , .
5.1.1.
(CheckBox) ,
, .
(OptionButton) , , .
Click, Value.
. Value : 0 ; 1- ; 2 , . .
, , , .
.
.
5.1. c CheckBox OptionButton.
.
(.5.1.).
Check1:
Check1(0), Check1(1), Check1(2).
Check2
Option1: Option1(0), Option1(1), Option1(2).
145
Click .
. 5.1.
Const pi As Single = 3.14159
Dim x As Single, y1 As Single, y2 As Single, y3 As Single
--------------------------------------------------------------------------------------------------------Private Sub Command1_Click()
Picture1.Cls
Picture1.Scale (-2 * pi, 5)-(2 * pi, -5)
Picture1.Line (-2 * pi, 0)-(2 * pi, 0): Picture1.Line (0, -5)-(0, 5)
For x = -2 * pi To 2 * pi Step 0.01
If Check1(0).Value Then y1 = Sin(x): Picture1.PSet (x, y1), vbGreen
If Check1(1).Value Then y2 = Sin(x + 2 * pi / 3): Picture1.PSet (x, y2), vbBlue
If Check1(2).Value Then y3 = Sin(x + 4 * pi / 3): Picture1.PSet (x, y3), vbRed
Next x
If Check2.Value Then
For x = -2 * pi To 2 * pi Step 0.1
If Option1(0).Value Then y1 = Cos(x): Picture1.PSet (x, y1), vbMagenta
If Option1(1).Value Then y2 = Tan(x): Picture1.PSet (x, y2), vbCyan
If Option1(2).Value Then y3 = Exp(x): Picture1.PSet (x, y3), vbYellow
Next x
End If
End Sub
. 5.2.
5.1.2.
: , (ListBox),
(ComboBox) , ImageCombo.
, .
, .
:
Text, List, ListIndex, ListCount, Columns, Sorted, ItemData, MultiSelect.
Text ;
List . ( ), .
. :
<>=lstBox.List(i)
List Ctrl-Enter
.
ListIndex - :
< _ >= lstBox.ListIndex
List ListIndex:
<_>=lstBox.List(lstBox. ListIndex)
, ListIndex
1.
ListCount .
Columns
. 147
,
..
Sorted .
True, ,
. NewIndex. .
ItemDate(). Long ( ).
, ,
ItemData:
lstPersonal. AddItem Vogel
lstPersonal.ItemData(lstPersonal.NewIndex)=8763
List1.ItemData (List1.ListIndex)=10986
MultiSelect
. :
0 ; 1 ; 2 . Shift
Ctrl .
, Shift, ;
, Ctrl,
.
Text
.
Selected
:
<_>= List1.Selected
AddItem - :
List1.AddItem < [ , ]>
List1.AddItem ,5
RemoveItem - :
List1. RemoveItem.
ListBox Clear - .
148
(ComboBox)
, .
Click,
Change.
Style, .
:
0 ( ) - .
;
1 ;
2 - 0 ,
.
5.3. ComboBox.
Shape c ComboBox (.5.3).
ComboBox, Shape
.
ComboBox
Combo1, Shape Shape1.
List Combo1
: 0 Shape; 1 BorderStyle; 2
. 5.3.
BorderWidth. ComboBox
.
Style ComboBox 2, , Sorted True.
5.4.
.
Click
:
Private Sub Append_Click()
Dim A As String, A1 As String, n As Integer
'
A = InputBox(" ")
' ,
n = InStr(a, ",")
149
A1 = Left(a, n - 1)
n = Val(RTrim(Right(a, Len(A)-n)))
Combo1.AddItem A1, n
End Sub
5.5. Shape.
Click
:
Private Sub Demo_Click()
Dim a As String, n As Integer
Static I As Integer
Dim Index As Integer
Index = Combo1.ListIndex
Select Case Index
Case 0, 1, 2
n=5
Case 3
n=7
Case 4
n = 15
End Select
I=I+1
If I > n Then I = 0
If Trim(Combo1.Text) = "Shape" Then Shape1.Shape = I
If Trim(Combo1.Text) = "BorderStyle" Then Shape1.BorderStyle = I
If Trim(Combo1.Text) = "FillStyle" Then Shape1.FillStyle = I
If Trim(Combo1.Text) = "FillColor" Then
Shape1.FillColor = QBColor(I)
End If
If I > 0 Then
If Trim(Combo1.Text) = "BorderWidth" Then Shape1.BorderWidth = I
End If
End Sub
- .
,
Text , ,
ListIndex:
Combo1.ListIndex = 2
, ,
Text .
5.1.3. (ScrollBar)
150
, , , , .
,
.
ScrollBar Max, Min
Value, SmallChange.
Max Min , 32768 + 32767. Value .
SmallChange ,
Value .
Chnge
Scroll.
Chnge . Scroll Chnge.
5.6. (.5.4.).
, TextBox
. .
,
Value .
C
Max ScrollBar . 5.4.
255, Min ,
SmallChange 1.
Scroll,
. , Value.
Private Sub VScroll1_Scroll()
Label4(0).Caption = VScroll1.Value
Text1.BackColor = RGB(VScroll1.Value, VScroll2.Value, VScroll3.Value)
End Sub
Private Sub VScroll2_Scroll()
Label4(1).Caption = VScroll2.Value
Text1.BackColor = RGB(VScroll1.Value, VScroll2.Value, VScroll3.Value)
End Sub
Private Sub VScroll3_Scroll()
151
Label4(2).Caption = VScroll3.Value
Text1.BackColor = RGB(VScroll1.Value, VScroll2.Value, VScroll3.Value)
End Sub
5.1.4. Slider.
, Windows Slider. .
ToolBox.
.5.5. Slider
Project\Components, Microsoft Windows Common Controls 6.0 (SP3) Common
Controls 5.0 (SP2).
Slider Min, Max Value .
SmallChange LargeChange
.
, .
SelStart SelLength, . Text , .
TextPosition.
Validate. .
5.1.5. (UpDown)
( UpDown)
.
, AutoBuddy,
SyncBuddy, BuddyControl BuddyProperty Buddy.
Buddy , UpDown
(.5.6.). Buddy Buddy-Control
AutoBuddy.
, UpDown,
, TabIndex ,
UpDown.
152
BuddyProperty ,
Buddy -
.5.6.
Value UpDown.
TextBox +UpDown
TextBox
Text. BuddyProperty Default, , ,
UpDown.
Min, Max, Value.
UpDown:
SyncBuddy UpDown .
Wrap ,
, ,
( ).
Aligument (, );
Orintation .
TextBox
UpDown
.5.7. UpDown
UpDown.
1. C TextBox
Text1.
2. C UpDown
UpDown1. TabIndex
.
3.
UpDown
Properties (Property Pages)
UpDown.
4. Buddy (. 5.7)
AutoBuddy. Text1.
5. BuddyProperty Default. SynBuddy -
Text Text1.
6. Scroling Min, Max Increment.
Text Text1 UpDown1.
153
7. , , UpDown General .
8. , OK.
5.1.6. :
1. 5.1, 5.3, 5.4.
2. ( 4.13.) UpDown Y.
5.1.7.
1. CheckBox OptionButton.
?
2. CheckBox
OptionButton.
3. Value
CheckBox OptionButton.
4. CheckBox OptionButton.
Index .
5. List ComboBox?
?
6. ComboBox. ComboBox.
7. ComboBox. ComboBox.
8. ?
9. ComboBox List
?
10. ScrollBar?
11. .
12. ScrollBar
Slider?
13. UpDown?
14. UpDown ?
(, , , , , , , ) CheckBox OptionButton.
154
. .
5.2.
. , ,
,
, . .
, ,
.
Visual Basic,
- StatusBar;
- ProgressBar;
- Animation.
5.2.1.
, Project\Components Microsoft Windows Common Controls 6.0 (SP3).
. 16 , , , , .
, (Property Pages) (.
5.8).
, .
Align Style .
Style . (sbrSimple) (sbrNormal)
. ,
. .
155
. 5.8.
Align , . :
vbAlignTop ; vbAlignBottom ; vbAlignLeft ; vbAlignRight ; vbAlignNone .
.
Properties. (. 5.8).
General , Panels 16 .
,
.
Text , .
;
ToolTipText , ;
Alignment : ,
;
Style . : sbrText- ,
Text Picture ; sbrCaps CapsLock; sbrNum -
NumLock; sbrIns - Insert;
sbrScrl - ScrolLock; sbrTime ; sbrDate .
Bevel ;
AutoSize ;
MinWidth ;
Picture .
: Insert Panel Remove Panel
.
Add, Remove Clear.
Add . :
Add ([Index] [,] [,] [, ] [,]) As Panel
Remove . :
156
Remove [Index]
Clear . : Clear
5.7. :
StatusBar1.Panels(1).Text =.
5.8.
.
. ,
(. 5.9). .
. 5.9.
.
StatusBar
Project\Components, Microsoft Windows Common Controls
6.0 (SP3) Ok.
Align 2
, Style (sbrNormal).
Property Pages Panels.
Text .
Load KeyPress :
Private Sub Form_Load()
Me.Width = 8000
Me.Height = 1500
Dim S As String
With StatusBar1
'
.Panels.Add 2, , " ", sbrText
.Panels(2).AutoSize = sbrSpring
'
.Panels.Add , , , sbrTime
End With
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
'
With StatusBar1
157
.Panels.Remove 1
End With
End Sub
5.2.2.
(ProgressBar) . .
:
Max Min . , Min
0, Max 100;
Value . ,
:
Sub LoadFiles()
Progress1.Min=0
Progress1.Max=nFiles
For i=1 To nFiles
Call LoadFile(i)
Progress1.Value=i
Next i
End Sub
5.2.3. ,
Visual Basic 6 , : DriveListBox ( ), DirectoryListBox ( ), FileListBox ( ). , , . Change.
.
.
DriveBox Drive,
, , C:\.
158
. . Path. ,
(, C:\Windows\Word).
.
FileName Pattern.
FileName (,
Bock.doc).
Pattern ,
. : *.ICO, *.BMP ..
:
File. Pattern=*.ICO;*.BMP
File FileListBox.
:
) :
Private Sub Drive1_Change( )
Dir1.Path=Drive1.Drive
End Sub
) :
Private Sub Dir1_Change( )
File1.Path=Dir1.Path
End Sub
) :
- :
lblPath.Caption=File1.Path & \ & File1.FileName.
\ :
Private Sub File1_Click ( )
If Right (File1.Path,1)= \ Then
lblPath.Caption=File1.Path & File1.FileName
Else
lblPath.Caption=File1.Path & \ & File1. FileName.
End If
End Sub
. 5.10.
159
, ,
.
VB 6 . Windows.
. 5.10.
5.2.4. Windows
CommonDialog.
Project\Components. Microsoft
Common Dialog. Control 6.0 OK.
Common Dialog, ,
:
Open () (.5.11.). ;
Save As (
),
;
Print (), Windows
;
Font ( ),
;
.5.11. Open
Color (),
;
160
Help
(
),
Windows.
Open Save As
(.5.11) Windows.
(. 5.12.),
. 5.12.
CommonDialog.
CommonDialog Properties, Property Pages. Open/
(*.dan) | *.dan| (*.bak)| *.bak
. 5.13. , Filter
Open ShowOpen. :
.ShowOpen.
<>= .FileName.
ShowSave:
. ShowSave.
<>=.FileName.
<> .
5.2.5. .
PrintForm Printer.
PrintForm
C PrintForm ( 96
dpi). PrintForm .
, ,
.
,
, .. , , ..
.
PictureBox
, AutoRedraw True.
.
Load frmForm1
frmForm1.lblOutput.Caption=< >
frmForm1.picOutput.Picture=LoadPicture(c:/bibl.bmp)
frmForm1.PrintForm
Unload frmForm1
Printer
Printer .
PrintForm, Printer , , ,
. . ,
.
162
Printer
Printer Print, :
Printer. Print
Printer. Print
, Printer. Font:
Printer. Font. Name = Times New Roman
Printer. Font. Size = 12
Printer. Font. Underline = True
Printer. Print = ,
ScaleMode.
.
ScaleMode vbCentimeters,
vbMillimeters vbPixels , , .
CurrentX
CurrentY. urrentY , CurrentX .
ScaleWidth ScaleHeight.
TextHeight
TextWidth.
Tab, (;) (,) Print.
Pset, Line, Cirle Printer
Printer. Line (1,1) (10,5)
PaintPicture (. 4.3.5):
Printer.PaintPicture Form1.Picture, 0, 0, 1500, 1000, 0, 0, 7000, 5000
Printer . ,
. NewPage.
, , EndDoc, .
KillDoc.
5.2.6. :
163
1. .
. .
.
.
.
(.5.14).
: ;
,
().
:
Option Explicit
.5.14.
Dim Xn As Single, Xk As Single, Dx
As Single
Dim Yn As Single, Yk As Single, Dy As Single
Dim X As Single, Y As Single, Z() As Single
Dim M As Integer, N As Integer
Dim NameFile As String, NameFile1 As String
Dim Nkan As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Xn = Val(Text1(0).Text)
Xk = Val(Text1(1).Text)
Dx = Val(Text1(2).Text)
Yn = Val(Text1(3).Text)
Yk = Val(Text1(4).Text)
Dy = Val(Text1(5).Text)
Cls
'
N = Int((Xk - Xn) / Dx) + 1
M = Int((Yk - Yn) / Dy) + 1
ReDim Z(N, M)
Grid1.Rows = N + 1
Grid1.Cols = M + 1
'
X = Xn
Grid1.Col = 0
Grid1.ColAlignment(0) = 2
For i = 1 To N
Grid1.Row = i
Grid1.Text = Str$(X)
164
X = X + Dx
Next i
'
Y = Yn
Grid1.Row = 0
For j = 1 To M
Grid1.Col = j
Grid1.ColAlignment(j) = 2
Grid1.Text = Str$(Y)
Y = Y + Dy
Next j
' Z
X = Xn
For i = 1 To N
Y = Yn
Grid1.Row = i
For j = 1 To M
Z(i, j) = X + Y
Y = Y + Dy
Grid1.Col = j
If X <> 0 Then
Grid1.Text = Str$(Format(Z(i, j), "#.##"))
Else
Grid1.Text = Str$(Z(i, j))
End If
Next j
X = X + Dx
Next i
StatusBar1.Panels(1) = "N=" & Str(N)
StatusBar1.Panels(2) = "M=" & Str(M)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
.
.
5.2.7.
1. ?
2. ?
3. ?
4. .
5. DriveListBox, DirectoryListBox, FileListBox.
6. DriveListBox, DirectoryListBox, FileListBox.
7.
DriveListBox, DirectoryListBox, FileListBox?
8. CommonDialog?
9. CommonDialog?
10. Save Open?
11. PrintForm?
12. Printer?
13.
?
14.
?
6.
6.1.
6.1.1.
. : , , .
. Visual Basic 6 , . ,
, , , ,
166
.
. Visual Basic 6.0, Basic, .
,
.
( ) - .
. : ,
Enter () .
.
.
. . . .
( )
. . .
, .
() . , , , . .
,
, , , . Basic.
Open.
Open _ For { }[Access{}]
[Lock{}] As [#] N [Len=]
167
_, , ,
,
.
:
R:/Prognoz/Ucheb/prognoz1.dan. MS DOS,
MS DOS. T
, , 8 , , . . .
For .
:
Input , ;
Output , ;
Append - , ;
Bynary :
Random .
Access
. :
Read ;
Write ;
Read Write - . .
Lock. -, ,
,
,
. , :
Shared
;
LockRead .
. , .
LockWrite .
. ,
.
LockReadWrite , . , , .
As . # . 1 255. 168
, Config.sys.
, , FreeFile.
FreeFile .
Len . .
, ,
:
- . , ;
- ,
-.
, , ;
- ,
.
Close. :
Close [# < > ]
Close .
Close . Close
[FAT]. - Windows.
, , .
c
Close Reset. , Close,
.
c
Close Reset.
.
6.1.2.
, .
169
, ,
,
.
: .
:
( Open Append c Output)
.
( Close)
,
.
:
( Open c Input)
.
( Close)
Print # Write #.
Print # Print, . , ,
, ,
.
Write # , Print #,
Print # , Write #
, :
Print #1, , , 17 , 3.75
17
75
: , , 17, 3.75
Write #.
Input #, Line Input # Input$.
Line Input # .
(
170
Enter).
255 .
Input # :
Input #, ,< >
.
Input$
, . Input$:
<_>= Input$ (n, #N),
n , , # N .
6.1. .
Open R:Test.dan For Output As #1
A$ =
B%=13875
!=7.58
Print#1, A$, B%, Str$ (C!)
Close #1
6.2.
Open R:Test.dan For Input As #1
Input Line A$
Print A$
Close
:
, 13875, 7.58
13875 7.58 .
Open R:Test.dan For Input As #1
Input #1, A$, B%, C$
Print A$, B%, Val (C8)
Close #1
:
13875 7.58
13875 7.58
Input #
Write #.
6.1.3.
.
. .
. .
. .
.
171
, , ,
.
6.3.
. ,
, (, , )
.
, ,
.
.
1. ( 6.1):
BD(n,5). n , 5 .
, .
MSFlexGrid. .
N
. 6.1.
. 6.2.
2. (. 6.2).
3. (. 6.1).
172
4. , (.6.2)
5. .
.
Dim i As Integer, j As Integer, bd() As String
Dim n As Integer, Sb As Single, nKanal As Integer
.
Private Sub Form_Load()
Me.Height = 5000
Me.Width = 8000
For i = 0 To 4
Grid1.Row = 0
Grid1.Col = i
Label
lblLabel1
lblLabel2()
.
TextBox
txtText1
txtText2( )
.
MSFlexGrid
Grid1
Command
cmdVvod
cmdSave
( )
cmdOpen
cmdExit
Grid1.Text = Label2(i).Caption
Grid1.Visible = True
Next i
Grid1.Col = 5
Grid1.Text = " "
Grid1.Visible = True
Grid1.Row = 0
Grid1.Col = 0
Grid1.ColWidth(0) = 600
Grid1.ColWidth(1) = 2000
Grid1.ColWidth(2) = 1000
Grid1.ColWidth(3) = 1100
Grid1.ColWidth(4) = 1200
Grid1.ColWidth(5) = 1200
End Sub
6.1.
6.2.
173
i, j, k
Integer
n
Sb
bd(5,n)
nKanal
Integer
Single
Single
Integer
.
Change
Text1:
Private Sub txtText1_Change()
n = Val(txtText1.Text)
Grid1.Rows = n + 1
End Sub
,
.
.
Private Sub cmdVvod_Click()
Dim i As Integer, j As Integer
If n = 0 Then
MsgBox " "
Exit Sub
End If
ReDim Preserve bd(5, n) As String
If n < Val(txtText2(0).Text) Then
n = Val(txtText2(0).Text)
Grid1.Rows = n + 1
ReDim Preserve bd(5, n) As String
End If
i = Val(txtText2(0).Text)
Grid1.Row = i:
For j = 0 To 4
bd(j, i) = txtText2(j).Text
Grid1.Col = j
Grid1.Text = bd(j, i)
Grid1.Visible = True
Next j
Sb = (Val(txtText2(2).Text) + Val(txtText2(3).Text) + Val(txtText2(4).Text)) / 3
Grid1.Col = j
Grid1.Text = Str$(Format(Sb, "#.##"))
Grid1.Visible = True
bd(5, i) = Str$(Sb)
For j = 1 To 4
txtText2(j).Text = ""
Next j
If i < n Then txtText2(0).Text = i + 1
End Sub
Private Sub cmdSave_Click()
174
nKanal = FreeFile
Open "r:\Laborat\VisualBasic\file.dan" For Output As #nKanal
Write #nKanal, n
For i = 1 To n
For j = 0 To 5
Write #nKanal, Format(bd(j, i), "#.##")
Next j
Next i
Close #nKanal
End Sub
( )
Private Sub cmdOpen_Click()
nKanal = FreeFile
Open "r:\Laborat\VisualBasic\file.dan" For Input As #nKanal
Input #nKanal, n
ReDim bd(5, n)
Grid1.Rows = n + 1
For i = 1 To n
Grid1.Row = i:
For j = 0 To 5
Input #nKanal, bd(j, i)
Grid1.Col = j
Grid1.Text = bd(j, i)
Grid1.Visible = True
Next j
Next i
Close #nKanal
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
6.1.4.:
1.
2 5.2.6.
.
X, , dX, Y, Y, dY. .
\ :
Private Sub mnuOpen_Click()
Dim Z1 As String
Dim i As Integer
cldDialog1.ShowOpen
Nkan = FreeFile 'Nkan -
NameFile = cldDialog1.FileName
175
\ :
Private Sub mnuSave_Click()
Dim i As Integer, Nkan As Integer
NameFile = NameFile1
Nkan = FreeFile
If NameFile = "" Then
cldDialog1.ShowSave
NameFile = cldDialog1.FileName
End If
Open NameFile For Output As #Nkan
For i = 0 To 5
Write #Nkan, Text1(i).Text
Next i
Close #Nkan
End Sub
\ ... :
Private Sub mnuSaveAs_Click()
Dim i As Integer, Nkan As Integer
NameFile = NameFile1
Nkan = FreeFile
cldDialog1.ShowSave
NameFile = cldDialog1.FileName
Open NameFile For Output As #Nkan
For i = 0 To 5
Write #Nkan, Text1(i).Text
Next i
Close #Nkan
End Sub
\ :
Private Sub mnuPrint_Click()
Dim i As Integer
Dim j As Integer
cldDialog1.ShowPrinter
Printer.Font.Name = "Times New Roman"
Printer.Font.Size = 16
Printer.Font.Bold = True
176
2. ( 6.1.3.)
3. .6.2.
(. 1 , 2 5.2.6)
6.1.5.
1. ?
2. Open.
3. Close.
4. ?
5. ?
6. ?
7.
?
8. .
.
6.2.
177
6.2.1.
. .
.
, , Familij As String*20. .
. , . .
.
Open _ For Random [Access ] [Lock ]
As[ # ] N [ Len = ]
. , Len ().
Put # , , .
Get:
Get # , , .
.
Type / End Type.
6.4. .
Type
_ As String * 20
1 As String * 20
2 As String * 20
As String * 100
As String * 15
As Integer
As Integer
End Type
.
Dim As
.
. _ =
. =
. = .:
. = 1975
Private Sub mnuSave_Click ( )
Put # 1, 1,
End Sub
178
Private Sub mnuOpen_Click ( )
Dim As String, As String,
Dim As String, As Integer
Get #1, 1,
= . _
= .
= .
= .
End Sub
6.2.2.
Visual Basic 6 ,
. :
MkDir : MkDir C:\PROBA
Kill - : Kill *.bak
Name - , :
:
Name C:\VB\TEST.BAS As C: \ ARCHIV\ TEST.BAS
:
Name C:\VB\TEST.BAS As TEST.BAK
Dir$( [, ]) - .
If Dir$(C:\VYFILE.TXT) = Then
MsgBox
End If
CurDir$(Drive) , . Drive .
FileCopy :
179
FileCopy _, _.
FileDataTime :
FileDataTime ()
GetAttr :
GetAttr () As Integer
0 - ;
8 - ;
1 - ;
16 - ;
2 - ;
32 - .
4 - ;
SetAttr
SetAttr ,
VB 6 ,
. 6 :
0 - , ;
1 - , ;
2 - , , ;
3 - , ;
4 - , ;
6 - , , .
6.2.3. :
, 6.1.3.
1. Ekzamen:
Type Ekzamen
Familij As String * 20
Fizika As Integer
Matematika As Integer
Informatika As Integer
SBall As Single
End Type
2. Usp
Ekzamen:
Dim Usp As Ekzamen
180
:
(. 6.3.).
. 6.3.
.
Private Sub cmdSave1_Click()
Dim i As Integer
nKanal = FreeFile
Open "r:\Laborat\VisualBasic\file1.dan" For Random As #nKanal
i = Val(txtText2(0).Text) - 1
Usp.Familij = bd(1, i)
Usp.Fizika = Val(bd(2, i))
Usp.Matematika = Val(bd(3, i))
Usp.Informatika = Val(bd(4, i))
Usp.SBall = Val(bd(5, i))
Put #nKanal, i, Usp
End Sub
Private Sub mnuOpen1_Click ( )
nKanal = FreeFile
Open "r:\Laborat\VisualBasic\file1.dan" For Random As #nKanal
i = Val(InputBox(" "))
If n = 0 Then
MsgBox " "
Exit Sub
End If
ReDim bd(5, n)
Get #nKanal, i, Usp
bd(0, i) = Str(i)
bd(1, i) = Usp.Familij
bd(2, i) = Str(Usp.Fizika)
bd(3, i) = Str(Usp.Matematika)
181
bd(4, i) = Str(Usp.Informatika)
bd(5, i) = Str(Usp.SBall)
Grid1.Rows = 2:
Grid1.Row = 1:
For j = 0 To 5
Grid1.Col = j
Grid1.Text = bd(j, i)
Print bd(j, i)
Grid1.Visible = True
Next j
Close #nKanal
End Sub
:
Private Sub cmdSave_Click()
nKanal = FreeFile
Open "r:\Laborat\VisualBasic\file1.dan" For Random As #nKanal
For i = 1 To n
Usp.Familij = bd(1, i)
Usp.Fizika = Val(bd(2, i))
Usp.Matematika = Val(bd(3, i))
Usp.Informatika = Val(bd(4, i))
Usp.SBall = Val(bd(5, i))
Put #nKanal, i, Usp
Next i
Close #nKanal
End Sub
Private Sub mnuOpen1_Click ( )
nKanal = FreeFile
Open "r:\Laborat\VisualBasic\file1.dan" For Random As #nKanal
If n = 0 Then
MsgBox " "
Exit Sub
End If
Grid1.Rows = n + 1:
ReDim bd(5, n)
For i = 1 To n
Get #nKanal, i, Usp
bd(0, i) = Str(i)
bd(1, i) = Usp.Familij
bd(2, i) = Str(Usp.Fizika)
bd(3, i) = Str(Usp.Matematika)
bd(4, i) = Str(Usp.Informatika)
bd(5, i) = Str(Usp.SBall)
Grid1.Row = i:
For j = 0 To 5
Grid1.Col = j
Grid1.Text = bd(j, i)
182
'Print bd(j, i)
Grid1.Visible = True
Next j
Next i
Close #nKanal
End Sub
6.2.4.
1. ?
2. .
3. ?
4. ?
5. ?
6. ?
7. , .
.
7.
.
7.1.
7.1.1.
,
,
,
.
:
- - ,
;
- - .
183
MsgBox.
If Not IsNumeric(txtZipCode.Text) Then
Beep
StatusBar1. Panels("ErrorDescription").Text= " _
"
End If.
.
, . ,
(
TabIndex).
SetFocus:
txtZipCode.SetFocus
LostFocus:
Private Sub txtZipCode_LostFocus ( )
If Not IsNumeric (txtZipCode.Text) Then
MsgBox " "
txtZipCode.SetFocus
End If.
End Sub.
7.1.2.
- .
.
, . : KeyPress, KeyDown KeyUp. (. 1.2.2).
KeyPress
, ,
ASCII-. -
, Enter ( 13), Backspace ( 8). -
184
KeyPress .
KeyPress ,
TextBox ComboBox. KeyPress KeyASCII, .
, , KeyPress.
KeyDown KeyUp
, , . ASCII-. , trl + Del, Shift + Ctrl + Del
..
KeyPreview
KeyPreview True, ,
, .
, .
Private Sub Form1_Load()
.
KeyPreview=True
End Sub
Private Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1
MsgBox " F1"
[ ]
Case vbKeyF2
MsgBox " F2"
[ ]
ase Else
End Select
End Sub
VB Control,
. TypeOf.
TypeOf
.
185
7.1. ( cmdOK),
.
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Text="" Then
cmdOK.Enabled=False
Exit Sub
End If
End If
Next ctl
cmdOk. Enabled = True
End Sub
7.1.3.
. TextBox: MaxLength; PassWrdChar, Locked.
MaxLength , . , MaxLength, .
PassWrdChar ,
. ,
.
,
.
Locked
, Text.
KeyPress ,
.
Sub txtText1_KeyPress(KeyAscii As Integer)
KeyAscii=Asc(VCase(Chr(KeyAscii)))
186
End Sub
Chr , VCase
, Asc
.
, - 97. 97
Chr, VCase
, Asc 65.
KeyUp KeyDown : , .
Shift, Ctrl, Alt ,
Ctrl + C.
KeyCode, Shift.
7.2.
Private Sub txtText1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case Shift
Case 1
Print Shift
Case 2
Print Ctrl
Case 3
Print Shift Ctrl
Case 4
Print Alt
Case 5
Print Shift Alt
Case 6
Print Ctrl Alt
Case 7
Print Ctrl, Shift Alt
End Select
End Sub.
Shift:
Private Sub txtText1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode=65 And Shift=1 Then
Print Shift
End If
End Sub.
Change
Change TextBox.
, txtText1 txtText2,
:
Private Sub cmd OKEnabled ( )
If txtText1.Text < > And txtText2.Text < > Then
187
cmdOK.Enabled=True
Else
cmdOK.Enabled=False
End If
End Sub.
Private Sub txtText1_Change ( )
Call cmdOKEnabled
End Sub
Private Sub txtText2_Change ( )
Call cmdOKEnabled
End Sub
cmdOKEnabled Change .
, .
Visual Basic 6 ,
: IsNumeric, IsDate .
IsNumeric True,
False . IsDate True, .
InputBox:
StrValue=InputBox( )
If IsNumeric (strValue) Then
Print
Else
End If
7.3. .
Public Sub txtTextNumeral(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0") To Asc("9"), Asc("."), 8
0 9, BackSpace
Numeral = Numeral + Chr(KeyAscii)
Case Else
, KeyAscii
KeyAscii = 0
Beep
End Select
End Sub
Validate.
, , Validate CausesValidation , , True.
Validation CausesValidation 188
, . Cancel: , True, .
7.1.4. :
1.
.
2.
.
7.1.5.
1. ?
2. ?
3. ?
4. KeyPress?
5. KeyUp KeyDown?
6. KeyPreview?
7. ?
8. Change
?
9. VB6
?
7.2.
7.2.1.
.
- .
.
, , ,
., , . .
, . VB .
189
. , . Unload
. ,
.
, , ,
, .
VB6 : On Error Resume, Err.
On Error . , . .
:
On Error {[GoTo <> \ Resume Next \ GoTo 0}
.
Description .
190
Err Clear:
Err Clear
Err , .
7.2.2.
:
- ;
- ;
- .
. 7.1.
Private Sub Primer ( )
On Error GoTo metka1
[ ]
Exit Sub
metka1:
'
[ ]
Resume
`
End Sub
. 7.1. .
.
On Error. On Error . , .
.
Resume.
. Exit Sub .
, .
:
- ;
191
- , ;
-
.
.
7.4. .
Private Sub cmdVvod_(Click)
On Error GoTo OpenError
FileNameVvod:
Nkanal=FreeFile ( )
Name=Input
Open Name For Input As Nkanal
Exit Sub
OpenError:
Select Case Err.Number `
ase53 `
MsgBoxErr. Deskription
MsgBox
Case Else `
MsgBox : & Err.Description
Exit Sub
End Select
Resume FileNameVvod
End Sub.
. 7.2.
Private Sub cmdOpen ( )
On Error GoTo ErrorHandler
Open C:\Reka.dan For Input As #1
Exit Sub
ErrorHandler:
.
Resume Next
.
Resume
.
Unload
End Sub
. 7. 2. Resume
ErrorHandler:
Dim Answer As Integer
192
--------------------------------------------------------------------------------------------------Error Handler:
Answer =MsgBox( ,vbAbortRetryIgnore)
MsgBox : , _
Select Case Answer
Case vbAbort
Unload Me , _
Case vbRetry
Resume
Case vbIgnore
Resume Next
End Select
7.2.3.
. ,
, .
, .
7.5. .
Private Sub cmdGetData_Click ( )
Dim FileName As String
FileName = InputBox ( )
If OpenFile(FileName)=True Then
Open File (FileName) - ,
MsgBox
Else
MsgBox .
End If
End Sub
-----------------------------------------------------------------------------------------------------------Function OpenFile (FileName As String) As Boolean
On Error CoTo OpenError
Open FileName For Input As # 1
, True
OpenFile=True
,
Exit Function
Open Error:
Select Case Err.Number
Case 53
193
Case 55
Case Else
`
End Select
` , False
OpenFile=False
End Function
, ,
.
, , ,
.. . ,
. . 7.3.
Sub Procedure A ( )
On Error Goto Error Handler:
Call Procedure B
Exit Sub
Error Handler:
End Sub
Sub Procedure B ( )
Call Procedure C
End Sub
Sub Procedure ( )
End Sub
. 7.3.
194
CommonDialog
CancelError CommonDialog. CancelError True, Cancel
CommonDialog .
False, ,
OK Cancel .
Function OpenFile() As String
On Error GoTo Cancel
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen
OpenFile = CommonDialog1.FileName
Exit Function
Cancel:
If Err.Number = cdlCancel Then
OpenFile =
MsgBox Err.Description
Exit Function
Else
MsgBox Err.Description
Stop
End If
End Function
. , ,
. , Cancel. Cancel , , Err,
. OpenFile . Stop.
7.2.4. :
.
7.2.5.
1. ?
2. Visual Basic?
3. On Error .
195
4. Resume.
5. .
6. ?
7. , .
8. Common Dialog?
1
Visual Basic
VB6 Windows, , ( ).
.
,
: . . ,
. Windows
.
. , : , , .
.
.
.
. ,
, ,
Windows.
- .
, , .
,
.
.
196
, , ,
.
. ,
Ctrl . Ctrl . ,
, .
.
(
) . , .
(Toolbox) ,
.
. . , . ,
, ,
,
.
, :
, - . .
.
( ) (.
197
. 1.1.
1.1.). , , , , .
.
.
(Properties) Height
, Width , Top
, Left .
,
. ,
Index Name.
(Copy) (Paste)
(Edit) ,
. ( )
:
- Edit\Copy. ( ). ( , );
- Edit\Paste
. (Frame) (PictureBox).
:
? .
. ,
. ,
. , ,
Ctrl,
.
.
. 198
. 1.2.
. , .
,
. ,
. ,
.
, . 1.2.
, ,
: , , . .
.
, : , .
(Format). ():
Align . :
, ;
, ; .
Size to Grid .
( ).
Tools\Options\General. Form Grid Settings
, Show Grid.
Align Controls to Grid. .
Make Same Size .
, .
Horizontal Spacing Vertical Spacing
. .
Center in Form . .
Order .
.
, . .
Lock Controls .
.
199
+
*
/
\
^
Mod
<
>
=
Abs(N)
Atn(N)
10
Cos(N)
Exp(N)
Fix(N)
Int(N)
IIf(., V1,V2)
Log(N)
Rnd(N)
Round(N[, ])
10
( ).
<=
>=
<>
N
N.
1 +1.11
.
,
, N N
, N ,
,
V1, V2,
0 1. N<0
, N; N=0
; N>0
,
N ,
.
180/ .
/180. 3,141593, = 4*Atn(1)
11
200
Sgn(N)
Sin(N)
Sqr(N)
Tan(N)
Val(C)
And
()
Eqv
Imp
Is
Like
Not
Or
Xor
&
,
()
Option Base
Dim
Private
Public
ReDim
Static
Lbound
Ubound
Erase
IsArray
Array
.
.
. .
.
. , Static, ,
,
,
Variant
Date
..,
, , .
DateAdd(,
, ) . -
201
DateDiff(,
1, 2,
,
)
DatePart(,
1, 2,
,
)
DateSerial(, , )
DateValue(C)
Day(N)
Month
MonthName(N)
Now
Weekday(
[,
])
WeekdayName(N)
Year()
Hour Month
Minute(N)
Second(N)
Time
Timer
TimeSerial
TimeValue
202
: Yyyy , Q
, M , Y - , D ,
W , Ww , H , N , S
.
, , , . .
,
.
,
DateAdd.
.
: 0 , 1 , 2 , 3 -
, ,
1 :
,
, ,
, .
1 31,
.
1 12,
1 7,
,
,
100 9999,
0 23,
0 59,
0 59,
. .
,
, ,
Asc( C )
Chr(N)
Space(N)
String(N,Chr)
ASCII
, ASCII (
32 255)
N
, N ,
ASCII . 0 255. 255
( Mod 256), . .
256
,
LCase(C)
UCase(C )
LTrim(C ),
RTrm(C ),
Trim(C)
Len(C )
Left(C, N)
N
Rignt(C, N)
N
Mid(C, N1, N2)
N2 N1
InStr ([I,] C, C1, 1 .
Compare)
i, i , . Compare
: -1 , Option Compare, 0 ;
1 ; 2 Microsoft Access,
,
InStr (C, C1, I, , InStr,
Compare)
1 ,
Str (N)
Cint(N),
, CLng(N),
CSng(N), Dbl(N), , .
CStr(N) .
Open
Close
Reset
EOF
FreeFile
, Open
, ,
, Recordset
, Open
203
Loc
LOF
Get
Input
Input#
Input$
Line Input#
Print#
Put
Write#
Spc
Tab
Width#
FileCopy
Dir
Kill
Name
ChDir
ChDrive
MkDir
RmDir
GetAttr
SetAttr
LoadPicture
SavePicture
, /
, Open
, Input Binary
String , , Input Binary
String
Print# Print
Print# Print
, Open
.
, ,
,
,
IsArray
IsDate
IsEmpty
IsMissing
IsNull
204
Boolean, ,
Boolean, ,
Boolean, ,
Boolean, ,
Boolean, , -
IsNumeric
IsObject
Null
Boolean, ,
Boolean, ,
Err
()
Clear
()
Error
()
Raise
()
On Error
()
IsError
()
CVErr
()
Boolean
Byte
Currency
Date
Double
Integer
Long
,
()
Err
,
Boolean, ,
Variant Error,
,
205
Object
Single
String
Variant
3
Visual Basic12
CheckBox
ComboBox
CommandButton
Common Dialog
Control
DirListBox
DriveListBox
ErrObject
FileListBox
Form
Frame
Global
HScrollBar
Image
Label
Line
ListBox
MDI-Form
Menu
12
206
Windows, , ,
,
,
MSFlexGrid
OptionButton
PictureBox
Printer
Screen
Shape
Slider
StatusBar
TextBox
Timer
VScrollBar
Call
Circle
Cls
Debug.Printer
DefBool
DefByte
DefCur
DefDate
DefDbl
DefInt
DefLng
DefSng
DefStr
DefObj
DefVar
Do Loop
For/Each
For/Next
Hide
If/Then/Else/End If
Let
Line
Load
Load Picture
Move
OLEDrag
PaintPicture
Point
Windows
,
Boolean
Byte
Currency
Date
Double
Integer
Long
Single
String
Object
Variant
207
PopupMenu
Print
Print Form
Pset
Refresh
Select Case
Scale
ScaleX
ScaleY
SetFocus
Show
Unload
While/Wend
ZOrder
X
Y
.
, ( ),
, , .
4.1.
4.1.1.
.
:
1. .
2.
.
3. .
4. , .
5. .
208
(..1): (1),
(2, 3), (4) (5), (6).
.
4.1.2.
, , , . , . 100:1, 100
1 .
6
2
1
1
D1
A1
3
4
.4.1.
0
A
B
X
100
-
Y
F
L
50
45
40
150
209
C
D
E
100
-
60+40
60
80
40
-
( 1) .
, B,
Yc Xd D. 2 3.
4.1.3.
1 :
(1.1)
Xa=Xo+L1 Cos 1
Ya=Xo+L1Sin1.
(1.2)
Y
1. , C1A=Xa-Xc,
(1.3)
Y c = Y a +
CA 2 C 1 A 2
. . , Yd . Xd - .
2.
2 :
x b = x a + l 2 Cos 2
(1.4)
x b = x d + l 3 Cos 3
(1.5)
y b = y a + l 2 Sin 2
(1.6)
y b = y d + l 3 Sin 3
(1.7)
( x b x d ) 2 + ( y b y d ) 2 = l 23
(1.8)
l2 - , l3 - .
ABB1 DBD1.
: , D , l3.
1.4 1.5 X d:
x d = x a + l 2 Cos 2 l 3 Cos 3
(1.9)
1.6 1.7 3:
210
(1.10)
3 = arcsin(( y a + l 2 Sin 2 y d ) / l 3 )
(1.9) 3 (1.10)
Xb (1.4), Xd Yb (1.9) (1.6)
((x a + l 2 Cos2 (x a + l 2 Cos2 l 3 Cos(arcsin((y a + l 2Sin2 y d ) / l 3 )))2 +
+ ( y a + l 2 Sin 2 y d ) 2 ) l 23 = 0 .
(1.11)
1.11 - 2.
2
, .
4.1.4.
, , .
:
211
2
8
n=3
9
M3
10
n=4
4
n=1
11
M4
12
M1
n=2
n=5
13
M=5
14
M2
n=6
15
9
. 4.2 . ()
- ;
- ;
- ;
- ;
-
;
- .
212
. . ,
Visual Basic.
. 4.2, :
n=1 - 1 - ;
n=2 - 2 - ;
n=3 - 3 - ;
n=4 - 4 - ;
n=5 - 5 - ;
n=6 - .
4.1.5.
. MDI-. .
. 4.2 4.5.
,
. :
. .
, (. 4.1)
.
4.1
_1_
:
__
Mechanizm
Obj
Object
Object,
, -
213
Xo,Xa,Xb,Xc,Xd
Yo,Ya,Yb,Yc,Yd
1, 2, 3, 4
l1, l2, l3 , l4, l5
X(5)
Y(5)
f(5)
L(5)
fi
pi
pi2
dx
Ft
Single
Single
Single
Single
Single
Double
Double
Single
Single
i1
Double
fl
fl2
xo
Byte
Byte
Integer
yo
xr
yr
n
Integer
Integer
Integer
Integer
.
,
:
Set Obj=< >
Y
,
2
i1=2*pi
,
,
,
, .
(.
4.2). .
4.2.
_2_
__
Mechanizm
,
214
Name
Caption
AutoRedraw
MDIChild
Name
Caption
Height
Width
Name
Caption
Height
FormStatica
True
2 Maximize
Command1Statica
375
1335
Command2Statica
375
_2_
:
__
Mechanizm
,
Width
MSFlexGrid
Rows
Cols
Name
Caption
Alignment
Name
Text
1335
MSFlexGridStatic
6
3
LabelStatica
2 Center
TextStatica
0
4.2.
MDI-
Private Sub MenuEnd_Click()
End
End Sub
Private Sub MenuDinamika_Click()
FormDinamic.Show
End Sub
Private Sub MenuPasport_Click()
FormPasport.Show
End Sub
Private Sub MenuSonaDvigenij_Click()
FormZona.Show
End Sub
Private Sub MenuStatika_Click()
FormStatica.Show
End Sub
Private Sub MenuTraektorij_Click()
FormTrec.Show
End Sub
Private Sub Form_Load()
VvodDannych
End Sub
Private Sub mnuCascade_Click()
215
.4.2.
.4.3.
.4.4.
. 4.5.
216
frmMDIForm.Arrange vbCascade
End Sub
Private Sub mnuHorizont_Click()
frmMDIForm.Arrange vbTileHorizontal
End Sub
Private Sub mnuVertical_Click()
frmMDIForm.Arrange vbTileVertical
End Sub
Rem
Option Base 1
Global Obj As Object
Global X(5) As Single, Y(5) As Single
Global f(5) As Single, l(5) As Single
Global dlina1 As Single, dlina2 As Single
Global dlina3 As Single, dlina4 As Single
Global msg0 As String, msg1 As String
Global msg2 As String, msg3 As String
Global msg4 As String, msg11 As String
Global msg12 As String, msg13 As String
Global msg14 As String, msg15 As String
Global fi As Single '
Global pi As Double '
Global i1 As Double '
Global fl As Byte
Global fl2 As Byte
Global xo As Integer, yo As Integer
Global xr As Integer, yr As Integer, n As Integer
Global pi2 As Single, dx As Single, Ft As Single
Rem
Public Sub VvodDannych()
y11 = 500: y12 = 4 / 3 * y11
X(1) = 100: Y(1) = 150: f(1) = 45: l(1) = 40
l(2) = 175
X(4) = 100: l(4) = 80
Y(5) = 200: l(5) = 50
Ft = 30
pi = Atn(1) * 4
pi2 = 2 * pi
i1 = pi2: '
dx = 0.3: '
End Sub
Rem
Public Sub Raschet()
Dim x1 As Single, y1 As Single
Dim b1 As Single, f1 As Single, e As Single
Dim s1 As Single, ss1 As Single, df As Single
Dim ss2 As Single, f2 As Single
217
218
219
Obj.DrawWidth = 1
Obj.Line (xr, yr)-(xr + 10, yr + 5), QBColor(6)
xr = xr + 5
Next ii
End Sub
Rem
Public Sub Form_StrichV()
Dim ii As Integer
For ii = 1 To n
Obj.DrawWidth = 1
Obj.Line (xr, yr)-(xr + 5, yr + 5), QBColor(6)
yr = yr + 5
Next ii
End Sub
Dim tc1(6, 3) As String, Ft As Integer
Private Sub Form_Load()
Set Obj = FormStatica
VvodDannych
tc1(1, 1) = "": tc1(1, 2) = "X": tc1(1, 3) = "Y"
tc1(2, 1) = "O": tc1(3, 1) = "A": tc1(4, 1) = "B":
tc1(5, 1) = "D": tc1(6, 1) = "C"
End Sub
Private Sub Command1Statica_Click()
Dim rx As Integer, ry As Integer, i As Integer
Dim ax As Single, ay As Single
ry = 380: rx = 1.6 * ry
Scale (0, ry)-(rx, 0)
Statica
MSFlexGrid1Static.ColAlignment(0) = 2
MSFlexGrid1Static.ColWidth(0) = 1000
MSFlexGrid1Static.ColAlignment(0) = 2
For i = 1 To 2
MSFlexGrid1Static.ColAlignment(i) = 2
Next i
For i = 1 To 3
MSFlexGrid1Static.Col = i - 1
MSFlexGrid1Static.Row = 0
MSFlexGrid1Static.Text = tc1(1, i)
Next i
For i = 2 To 6
MSFlexGrid1Static.Col = 0
MSFlexGrid1Static.Row = i - 1
MSFlexGrid1Static.Text = tc1(i, 1)
Next i
For i = 1 To 5
MSFlexGrid1Static.Col = 1
MSFlexGrid1Static.Row = i
ax = Format(X(i), "###")
MSFlexGrid1Static.Text = Str$(ax)
MSFlexGrid1Static.Col = 2
220
ay = Format(Y(i), "###")
MSFlexGrid1Static.Text = Str$(ay)
Next i
End Sub
************************************************************
' Rem
Public Sub Statica()
Cls
Ft = Val(TextStatic.Text)
fi = Ft / 180 * pi
Raschet
Postroenie
Psopor
End Sub
'***************************************************
Private Sub Command2Statica_Click()
Unload Me
End Sub
Dim TT As Integer
Dim TT1 As Integer, Scor As Double, FlagDin As Byte
Dim inf1(200) As Integer, inf2(200) As Integer
Private Sub ComDinEnd_Click()
If FlagDin = 1 Then
MsgBox " ", , ""
Exit Sub
Else
Unload Me
End If
End Sub
Private Sub Form_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim beep1 As Integer, i As Integer
For i = 1 To 200: inf1(i) = i: inf2(i) = 201 - i: Next i
Set Obj = FormDinamic
VvodDannych
HScroll1Dinamic.Value = 50
Scor = HScroll1Dinamic.Value * 100
ComDinStop.Cancel = False
FlagDin = 1
End Sub
'************************************************************
Rem
Private Sub Dinamica()
Dim beep1 As Integer, i As Integer
Cls
221
dx = 0.3: beep1 = 0
dinam2:
Scor = HScroll1Dinamic.Value * 100
If Option1Dinamic = True Then
For fi = 0 To pi2 Step dx
Cls
beep1 = beep1 + 1
Scor = HScroll1Dinamic.Value * 100
If Scor <= 2 Or Scor / 100 > 148 Then
MsgBox " ", , ""
GoTo dinam1
End If
If ComDinStop.Cancel = True Then FlagDin = 0: Exit Sub
TT = 0: TT1 = 0:
Raschet
Postroenie
Psopor
If CheckDinam = Checked Then
If beep1 = 5 Then
Beep
End If
End If
While TT < Scor
Timer1_Timer
TT = TT + TT1
DoEvents
Wend
For i = 1 To 200
If Int(TT / 100) = inf1(i) Then
TextDinamic1.Text = inf2(i)
End If
Next i
If beep1 = 5 Then beep1 = 0
Next fi
End If
If Option2Dinamic = True Then
For fi = 2 * pi To Ft / 180 * pi Step (-dx)
Cls
beep1 = beep1 + 1
Scor = HScroll1Dinamic.Value * 100
If Scor <= 2 Or Scor / 100 > 148 Then
MsgBox " ", , ""
GoTo dinam1
End If
If ComDinStop.Cancel = True Then FlagDin = 0: Exit Sub
TT = 0: TT1 = 0
Raschet
Postroenie
Psopor
If CheckDinam = Checked Then
If beep1 = 5 Then
222
Beep
End If
End If
While TT < Scor
Timer1_Timer
TT = TT + TT1
DoEvents
Wend
For i = 1 To 200
If Int(TT / 100) = inf1(i) Then
TextDinamic1.Text = inf2(i)
End If
Next i
If beep1 = 5 Then beep1 = 0
Next fi
End If
GoTo dinam2
dinam1:
HScroll1Dinamic.Value = 50
TextDinamic1.Text = HScroll1Dinamic.Value
End Sub
'**************************************************************************
Private Sub ComDinStart_Click()
Dim rx As Integer, ry As Integer
ry = 380: rx = 1.6 * ry
Scale (0, ry)-(rx, 0)
Dinamica
End Sub
Private Sub ComDinStop_Click()
ComDinStop.Cancel = True
End Sub
Rem
Private Sub Timer1_Timer()
Static TimerTimes As Integer
TimerTimes = TimerTimes + 1
If TimerTimes = 2 Then
TimerTimes = 0
Else
TT1 = TimerTimes
Exit Sub
End If
End Sub
Dim k As Byte
223
224
225
Postroenie
Psopor
k=1
Ft = Val(TextZonaCon.Text)
fi = Ft / 180 * pi
Raschet
Postroenie
Psopor
Erase xa, ya
fl = 0
End Sub
Dim tc(5, 5) As Integer, XT(10) As Integer
Dim tc1(6, 6) As String, Ft As Integer
Private Sub Form_Load()
Rem
Set Obj = FormTrec
VvodDannych
tc1(1, 1) = "": tc1(1, 2) = "1": tc1(1, 3) = "2"
tc1(1, 4) = "3": tc1(1, 5) = "4": tc1(1, 6) = "5"
tc1(2, 1) = "O (1)": tc1(3, 1) = "A (2)": tc1(4, 1) = "B (3)":
tc1(5, 1) = "D (4)": tc1(6, 1) = "C (5)"
tc(1, 2) = 1: tc(2, 3) = 1: tc(2, 4) = 1: tc(3, 5) = 1
tc(2, 1) = 1: tc(3, 2) = 1: tc(4, 2) = 1: tc(5, 3) = 1
Ft = 30
End Sub
Private Sub ComTrecRis_Click()
Dim rx As Integer, ry As Integer
Traectorij
If CheckTrec.Value = Checked Then
ry = 380: rx = 1.6 * ry
Scale (0, ry)-(rx, 0)
fi = Ft / 180 * pi
Raschet
Postroenie
Psopor
Else
Exit Sub
End If
End Sub
Private Sub ComTrec2_Click()
Unload Me
End Sub
226
227
Postroenie
Psopor
traekt1:
If TextTrec1.Text = "" Or TextTrec2.Text = "" _
Or TextTrec3.Text = "" Then
DoEvents
GoTo traekt1
End If
n1 = Val(TextTrec1.Text)
n2 = Val(TextTrec2.Text)
n3 = Val(TextTrec3.Text)
If n1 > 5 Or n2 > 5 Or n1 = 0 Or n2 = 0 Then
MsgBox "T ", , ""
TextTrec1.Text = ""
TextTrec2.Text = ""
TextTrec3.Text = ""
GoTo traekt1
End If
For i = 1 To 5
For j = 1 To 5
If tc(n1, n2) = 0 Then
MsgBox "T ", , ""
TextTrec1.Text = ""
TextTrec2.Text = ""
TextTrec3.Text = ""
GoTo traekt1
End If
Next j
Next i
fi = Val(TextTrecUgol2.Text) / 180 * pi
f2 = fi
Raschet
Postroenie
Psopor
'DoEvents
For fi = f1 To f2 Step dx / 4
Raschet
x1 = X(n1) + n3 / 100 * (X(n2) - X(n1))
y1 = Y(n1) + n3 / 100 * (Y(n2) - Y(n1))
If fi = f1 Then
CurrentX = x1 + 10: CurrentY = y1 + 5
Print "F"
End If
Circle (x1, y1), 3, QBColor(12)
Next fi
End Sub
Private Sub Form_Load()
228
Picture1.AutoRedraw = True
Picture1.Height = 7800
End Sub
Private Sub Picture1_Click()
Unload Me
End Sub
Private Sub Picture1_KeyPress(KeyAscii As Integer)
If Str(KeyAscii) <> "" Then
Unload Me
End If
End Sub
4.3.
1. . B. , . .
. - .: , 1986. - 136 c.: .
2. . .
. - .: , 1989. - 288 .: .
3. , : - , , 1991. - 34 c.
1. . . Visual Basic 6. .: ,
2000.
2. . VB5, - .: ,
1998.-608 .:.
3. , . Visual Basic 6.0-.:
V, 2000-288 .: .
4. Microsoft Corporation. VB 6.0 - .: - , 2000 - 400 ..
5. . VB 6.0 - .: .; .:
, 2001.- 832 .: .
229