Professional Documents
Culture Documents
Visual Basic 6 Ellinika
Visual Basic 6 Ellinika
VISUAL BASIC 6
1.0
e-, -2, 2003-2006
http://www.auth.gr/e-topo
2005
VB 6.0 v1.0 / e- / / -
1
2
3
4
5
6
7
8
9
Visual Basic.
, , , ,
.
.
(, , , ).
.
.
.
( ).
() .
Modules, (sub-routines)
(functions).
3
18
61
72
81
97
106
121
146
155
164
188
196
VB 6.0 v1.0 / e- / / -
Visual Basic
GW Basic
Basic A (IBM), Quick Basic
(Microsoft) Turbo Basic (Borland).
Visual Basic
VB
, .
start ( windows)
.
VB 6.0 v1.0 / e- / / -
- Programs
,
:
,
Microsoft Visual Studio
6.0
MS VB6:
Visual Basic.
,
,
VB.
VB 6.0 v1.0 / e- / / -
Visual Basic
VB
.
Standard
EXE,
.
, , :
1. New:
.
2. Existing:
(/recent,
).
3. Recent:
.
project .
VB 6.0 v1.0 / e- / / -
2. ,
, project ,
, , , .
Standard EXE
VB:
, -.
,
project.
:
VB 6.0 v1.0 / e- / / -
ToolBox ( )
.
project.
.
.
. ,
.
.
Properties Window ( )
.
(, ,
),
(
),
, ,
.
,
, (events)
(methods).
VB 6.0 v1.0 / e- / / -
1. (Form)
project ,
.
.
. (
) . (
) (.. DLL) .
2.
. ,
(button) ,
, , .
.
3.
,
. , button
move. . .
,
.
VB 6.0 v1.0 / e- / / -
Project Explorer ()
O Project Explorer
project
.
, modules,
class modules .
Module
. , ,
. module
, .
Class Module VB. class
module (compilation & build),
DLL.
project.
- ,
DLL (Dynamically Linked Library).
Form Layout ( )
.
.
,
.
VB 6.0 v1.0 / e- / / -
10
Immediate Window ( )
.
(debuging) project
.
Menu ( )
VB.
:
File
Project
Project
project
project ...()
EXE project
(
)
project
VB
VB 6.0 v1.0 / e- / / -
11
Edit
Undo / Redo
VB 6.0 v1.0 / e- / / -
12
View
Immediate Window
Project Explorer
Properties Window
ToolBox
ToolBars
Project
Module
Class Module
Project
(References): project
.
-.
VB 6.0 v1.0 / e- / / -
13
(Components):
ToolBox VB,
, Microsoft, .
.
VB 6.0 v1.0 / e- / / -
14
VB 6.0 v1.0 / e- / / -
15
Format
2
/
.
Run
/
Tools
(Options):
studio Visual Basic. ,
, ,
, .
VB 6.0 v1.0 / e- / / -
16
Help
Microsoft
Visual Basic.
project.
VB 6.0 v1.0 / e- / / -
17
;
1.
( ) ToolBox.
.
, .
a. .
b. .
c.
.
2. .
().
3. Properties Window
.
1. project ;
2. ;
3. ToolBox;
4. ;
5. project ;
6. ;
7. ;
8. module;
9. project ;
10. ;
11. ;
1. () .
. : 2000,
1500. .
Press me!. .
VB 6.0 v1.0 / e- / / -
18
, , , ,
(Controls).
. ,
(Command Button)
( ).
. ;
.
, .
, .
!
, .
VB 6.0 v1.0 / e- / / -
19
,
.
) .
) ( )
.
) ( ,
).
Pointer (): ,
. , .
.
Label ():
( /
caption).
.
( Properties Window)
.
(Name)
Label.
Alignment
Label
Label
AutoSize
(
)
Visual Basic.
012
,
.
True False
0:
1:
2:
True: Label =
False: Label =
.
VB 6.0 v1.0 / e- / / -
20
BackColor
-
Label.
BackStyle
Label
(
)
Label .
Label
BorderStyle
Caption
Enabled
Label
.
Font
Caption ()
ForeColor
(
)
:
VbRed, vbGreen,
vbCyan, vbYellow,
vbWhite
01
Label
.
01
0:
1:
,
,
.
True False
Label
Caption.
.
(, )
.
(
)
:
VbRed, vbGreen,
vbCyan, vbYellow
0: ()
1: ()
True:
(..
)
False:
.
H Label
VB 6.0 v1.0 / e- / / -
21
Height
Left
MousePointer
ToolTipText
Top
Visible
Width
WordWrap
Label twip.
AutoSize
True.
Label
twip.
.
.
Label (
)
.
Label.
Label.
Label
twip.
Label
.
Label
twip.
AutoSize
True.
Label
.
Pointer (
)
Label
.
Label
.
( /
)
,
,
.
.
True False
Label
.
True:
False:
.
.
Label (
)
.
True False
True:
.
False:
Label
.
VB 6.0 v1.0 / e- / / -
22
Change
Click
Label
( Caption)
Label.
DblClick
Label
MouseDown
(
)
MouseUp
MouseMove
,
.
Label.
(Sub).
( (Name)
Label1)
Private Sub Label1_Change()
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label1_DblClick()
End Sub
Private Sub Label1_MouseDown(Button As
Integer, Shift As Integer, X As Single, Y As
Single)
End Sub
Private Sub Label1_MouseUp(Button As
Integer, Shift As Integer, X As Single, Y As
Single)
End Sub
Private Sub Label1_MouseMove(Button As
Integer, Shift As Integer, X As Single, Y As
Single)
End Sub
(sub) : (subroutine)
. .
,
(!, Caption),
VB 6.0 v1.0 / e- / / -
23
Click,
.
,
.
,
( .. ,
Label1 ).
, Label,
.
Move
Refresh
ZOrder
)
Label
.
Label
(
Label
Label1)
Label1.Move 100,200
Label1.Move
100,200,400,400
Label1.Refresh
0: ( )
1: ( )
Label1.Zorder = 0
Label1.Zorder = 1
VB 6.0 v1.0 / e- / / -
24
! ! !
,
, Label,
.
Label1.
Click Label.
Private Sub Label1_Click()
' Hallo Caption
Label1.Caption = Hallo
' ( )
Label1.Left = 500
Label1.Top = 500
' ( )
Label1.Width = 250
Label1.Height = 200
End Sub
' (Remark) Visual Basic
.
. .
REMARKS
.
.
( Label1) Visual Basic
. .
Label1 .
,
:
,
VB!
VB 6.0 v1.0 / e- / / -
25
Frame ():
.
.
,
Label ( )
:
(Name)
AutoSize
BackColor
BorderStyle
Caption
Click
DblClick
MouseDown
(
)
MouseUp
MouseMove
Move
Refresh
ZOrder
Enabled
Font
ForeColor
Height
Left
MousePointer
ToolTipText
Top
Visible
Width
VB 6.0 v1.0 / e- / / -
26
CheckBox ( ):
.
,
CheckBox.
Style
CheckBox.
0: (Standard)
1: (Graphical)
Value
CheckBox
.
0: UnChecked
1: Checked
2: Grayed
0:
.
1:
0:
.
1:
.
2:
(default option)
CheckBox .
Click
MouseDown
o
CheckBox. (
,
)
.
(Sub).
( (Name)
Check1)
Private Sub Check1_Click()
End Sub
Private Sub
Check1_MouseDown (Button As
Integer, Shift As Integer, X
As Single, Y As Single)
End Sub
VB 6.0 v1.0 / e- / / -
27
(
)
MouseUp
,
, .
MouseMove
Label.
GotFocus
(
Tab Key)
.
LostFocus
(label, frame) .
VB 6.0 v1.0 / e- / / -
28
ComboBox ( ):
ComboBox
,
.
(
).
. ,
.
.
(Name), BackColor,
Enabled, Font,
ForeColor, Height,
Left, MousePointer,
Style, ToolTipText,
Top, Visible, Width
Locked
Sorted
Text
List
ListCount
ComboBox
.
ComboBox
.
(
True False
True:
False:
()
True:
False:
ComboBox.
True False
Index:
vName = Combo1.List
(1)
iLength =
Combo1.ListCount
VB 6.0 v1.0 / e- / / -
29
vName iLength .
,
Visual Basic. To
v i
:
Variant Integer.
.
Variant .
, , , .
Integer
>=0.
.
.
Change
Combo ( Text)
Click
Combo.
DblClick
Combo
GotFocus
LostFocus
(
Tab Key)
.
Scroll
DropDown
(
) .
(Sub).
(
(Name)
Combo1)
Private Sub Combo1_Change()
End Sub
Private Sub Combo1_Click()
End Sub
Private Sub Combo1_DblClick()
End Sub
Private Sub Combo1_GotFocus
()
End Sub
Private Sub Combo1_LostFocus
()
End Sub
Private Sub Combo1_Scroll()
End Sub
Private Sub Combo1_DropDown
()
End Sub
VB 6.0 v1.0 / e- / / -
30
ComboBox
. .
.
Clear
ComboBox
()
ComboBox
RemoveItem
ComboBox
Refresh
Index:
AddItem
SetFocus
(
ComboBox
Combo1)
Combo1.Clear
Combo1.AddItem
" 1"
Combo1.AddItem
"12.45"
Combo1.AddItem
"mail@mail.com"
Combo1.RemoveItem(1)
Combo1.RemoveItem(2)
Combo1.Refresh
Combo1.SetFocus
VB 6.0 v1.0 / e- / / -
31
HScrollBar ( ), VScrollBar (
) :
.
, . ,
.
.
.
(Name), Enabled,
Height, Left,
MousePointer, Top,
Visible, Width
Min
Max
[-32768, 32767]
[-32768, 32767]
in
[-32768, 32767]
Min
Max
[-32768, 32767]
[-32768, 32767]
(
)
Value
SmallChange
(
)
(
,
)
LargeChange
(
)
VB 6.0 v1.0 / e- / / -
32
( )
.
.
GotFocus, LostFocus
(Sub).
( (Name)
Hscroll1)
Private Sub
HScroll1_GotFocus()
End Sub
Private Sub
HScroll1_LostFocus()
Change
Scroll
.
.
End Sub
Private Sub HScroll1_Change()
End Sub
Private Sub HScroll1_Scroll()
End Sub
Move, Refresh,
Zorder, SetFocus
(
scrollbar
Hscroll1)
(
Hscroll1)
VB 6.0 v1.0 / e- / / -
33
Timer ():
(
), ,
.
.
. . .
Left, Top
Enabled
Interval
(
,
)
Enabled
.
,
Enabled
().
,
.
msec (1000msec=1sec)
True False
True
.
0 65535
Control Timer :
Timer
Timer
Enabled = True
Interval.
(Sub).
( (Name)
Timer1)
Private Sub Timer1_Timer()
End Sub
VB 6.0 v1.0 / e- / / -
34
DriveListBox ( ), DirListBox (
), FileListBox ( ):
DriveListBox
.
.
,
.
DirListBox
,
,
.
,
.
FileListBox
(
).
DriveListBox
DirListBox,
.
,
FileListBox.
, ,
,
.
VB 6.0 v1.0 / e- / / -
35
,
.
DriveListBox
(Name), BackColor,
Enabled, ForeColor,
Font, Height, Width,
Left, Top,
MousePointer, Visible
Drive
DirListBox
(Name), BackColor,
Enabled, ForeColor,
Font, Height, Width,
Left, Top,
MousePointer, Visible
Path
FileListBox
.
,
.
,
.
,
:
Drive1.Drive = C
C
SYSTEM
,
.
.
,
.
,
.
,
.
(Name), BackColor,
Enabled, ForeColor,
Font, Height, Width,
Left, Top,
MousePointer, Visible
Path
,
.
,
.
FileName
,
,
.
.
VB 6.0 v1.0 / e- / / -
36
. : Drive1, Dir1
File1:
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub File1_Click()
Dim SingleName As Variant
Dim TotalPath As Variant
SingleName = File1.FileName
TotalPath = Dir1.Path + "\" + File1.FileName
End Sub
.
3 blocks Private
Sub End Sub. 3
.
DriveListBox
Drive1. ; Drive1 ,
. ,
.
D, , , DirListBox,
. ,
FileListBox.
, ,
.
()
,
(
).
,
. , .
, - ,
. ,
, .
Dim, ,
VB 6.0 v1.0 / e- / / -
37
. Variant
. ,
,
. ,
(.. MyText.doc).
/ (..
C:\Program Files\MyProgram\Backup\MyText.doc).
, .
,
,
. ,
:
1. ;
;
,
.
( )
,
,
.
DirListBox ( Dir1).
VB 6.0 v1.0 / e- / / -
38
2. ;
, (
Properties Window)
. ,
. :
Private Sub Dir1_Change()
Dir1.
End Sub
,
.
. (
, ).
VB 6.0 v1.0 / e- / / -
39
Shape ():
Shape
.
.
Shape ,
.
.
shape .
(Name), Left,Top,
Width, Height, Visible
BackColor
.
(
)
.
.
(
)
01
(
)
0, 1, 2, 3, 4, 5, 6
1 8192
BackStyle
BorderColor
BorderStyle
BorderWidth
FillColor
FillStyle
(
)
0, 1, 2, 3, 4, 5, 6, 7
0:
1:
0:
1:
2:
3:
4: -
5: -
6:
0:
1:
2:
3:
4:
5:
6:
7:
VB 6.0 v1.0 / e- / / -
40
Shape
0, 1, 2, 3, 4, 5
0:
1:
2:
3:
4:
5:
shape
.
Line ():
Line
Shape.
. 2
(Refresh ZOrder)
.
(Name), BorderColor,
BorderStyle,
BorderWidth, Visible
X1
Y1
X2
Y2
.
.
.
.
VB 6.0 v1.0 / e- / / -
41
Image ():
.
,
:
(Name), Appearance,
BorderStyle, Enabled,
Height, Width, Left,
Top, Visible
Picture
(
)
()
Image
.
.
True False
Stretch
True:
.
False:
.
Image
, .
.
.
, ,
PictureBox.
VB 6.0 v1.0 / e- / / -
42
PictureBox ( ):
PictureBox,
Image, ,
.
PictureBox,
,
,
.
,
.
.
(Name), Appearance,
BackColor,
BorderStyle,
DrawStyle,
DrawWidth, Enabled,
FillColor, FillStyle,
Font, ForeColor,
MousePointer, Height,
Width, Left, Top,
Picture, Visible
Align
.
()
0, 1, 2, 3, 4
0:
1:
2:
3:
4:
True False
True:
.
False:
.
.
AutoRedraw
VB 6.0 v1.0 / e- / / -
43
AutoSize
FontTransparent
ScaleMode
ScaleLeft
ScaleTop
ScaleHeight
ScaleWidth
.
.
.
True False
True:
.
False:
.
True False
True:
False:
.
0:
1: Twip
2: Point
3: Pixel
4:
5:
6:
7:
.
.
.
.
0, 1, 2, 3, 4, 5, 6, 7
.
.
, ,
.
(0,0).
.
, ,
. Scale
.
Scale .
PictureBox
.
VB 6.0 v1.0 / e- / / -
44
Move, SetFocus,
ZOrder, Refresh
Circle
PictureBox.
Cls
PictureBox
PictureBox.
.
.
,,
R, ,
( )
Line
Point
Pset
Scale
TextHeight
TextWidth
.
.
(
PictureBox Picture1)
(
Picure1)
Picture1.Cirlce (X,Y), R, Color,
Start, End
Picture1.Cls
X1,Y1 X2,Y2,
(,)
Picture1.Line (X1,Y1)-(X2,Y2),
color
TheColor = Picture1.Point (X,Y)
(,),
1:
1:
2:
2:
MyW = Picture1.TextWidth
(TheText)
MyH = Picture1.TextHeight
(TheText)
,
.
VB 6.0 v1.0 / e- / / -
45
TextBox ( ):
.
(Name), Alignment,
Appearance,
BackColor,
BorderStyle, Enabled,
Font, ForeColor,
MousePointer, Height,
Width, Left, Top,
Visible
Locked
.
.
True False
True:
False:
()
,
TextBox
.
.
TextBox,
.
True False
.
True:
False:
MaxLength
MultiLine
PasswordChar
ScrollBars
(1
)
0, 1, 2, 3
0:
1:
2:
3:
VB 6.0 v1.0 / e- / / -
46
Text
.
.
(Move, Refresh,
Zorder ..) .
, (Click,
DoubleClick, Change, MouseMove ), textbox
, .
KeyPress
()
.
KeyDown
()
.
KeyUp
(
),
(Sub).
( (Name)
Text1)
Private Sub Text1_KeyPress
(KeyAscii As Integer)
End Sub
Private Sub Text1_KeyDown
(KeyCode As Integer, Shift As
Integer)
End Sub
Private Sub Text1_KeyUp
(KeyCode As Integer, Shift As
Integer)
End Sub
VB 6.0 v1.0 / e- / / -
47
CommandButton ( ):
.
.
:
(Name), Appearance,
BackColor, Enabled,
Font, Height, Width,
Left, Top,
ToolTipText,
MousePointer, Visible
Caption
Cancel
Default
,
.
[Esc]
.
.
[Enter]
.
.
.
True:
[Esc]
False: ,
[Esc]
True False
True False
True:
[Enter]
False: ,
[Enter]
VB 6.0 v1.0 / e- / / -
48
Style
01
DisabledPicture
Enabled False
(
)
(
).
.
DownPicture
Picture
0: (Standard):
.
.
1: (Graphical):
.
,
,
.
, .
, .
VB 6.0 v1.0 / e- / / -
49
OptionButton ( ):
OptionButton
.
CheckBox
,
checkbox
.
optionbutton
.
;.
,
!
.
(Name), Alignment,
Appearance,
BackColor,
DisabledPicture,
DownPicture, Enabled,
Font, ForeColor,
MousePointer, Left,
Top, Height, Width,
ToolTipText, Visible
Caption
,
.
VB 6.0 v1.0 / e- / / -
50
Style
01
Picture
.
Style
Graphical.
Value
True False
0: (Standard):
.
CommandButton
,
.
.
1: (Graphical):
CommandButton.
.
.
,
.
True:
.
False:
.
VB 6.0 v1.0 / e- / / -
51
:
( ), :
(
, -)
;
:
.
VB
2
. ,
(
, ).
;
!
Frame ().
!
.
2 Frames (
PictureBoxes,
)
Frame
,
:
.
OptionButtons
.
VB 6.0 v1.0 / e- / / -
52
ListBox ( ):
(ComboBox),
,
.
(Name), BackColor,
Enabled, Font,
ForeColor, Height,
Left, MousePointer,
ToolTipText, Top,
Visible, Width
Locked
ListBox
.
ListBox
.
True False
True:
False:
()
True:
False:
012
0:
1:
.
2:
[Shift] [Ctrl].
Style
01
Listndex
0...1
ListCount
0: Standard: (
)
1: CheckBox: (
)
(
List1):
AnInteger =
List1.Listindex
(
List1):
AllRegs = List1.ListCount
Sorted
MultiSelect
True False
VB 6.0 v1.0 / e- / / -
53
List
ListIndex
ListIndex.
(
List1):
MyChoice = List1.List
(List1.ListIndex)
ComboBox.
, ListBox Style
CheckBox:
ItemCheck
.
Item
.
(Sub).
( (Name)
List1)
Private Sub List1_ItemCheck
(Item As Integer)
End Sub
VB 6.0 v1.0 / e- / / -
54
Form ():
.
(Project).
,
.
(image), (Label), 3
CommandButtons
.
. ( )
.
.
: , ,
/,
Windows
.
,
.
VB 6.0 v1.0 / e- / / -
55
: ( Caption)
,
,
project.
: ( , ,
) .
,
, .
: .
.
:
.
: ( )
,
...
(Name), Appearance,
AutoRedraw,
BackColor, Caption,
Enabled, FillColor,
FillStyle, Font,
FontTransparent,
ForeColor, Left, Top,
Height, Width,
MousePointer, Picture,
ScaleMode, ScaleLeft,
ScaleHeight,
ScaleWidth, Visible
VB 6.0 v1.0 / e- / / -
56
orderStyle
,
,
0, 1, 2, 3, 4, 5
ControlBox
True False
Icon
(
)
(
)
Ico, cur
.
True False
MaxButton
MinButton
True False
0: None:
.
1: Fixed Single:
, ,
.
.
2: Sizable:
.
3: Fixed Dialog:
Fixed Single.
4: Fixed Tool Window:
Light,
Fixed
Single,
.
5: Sizable
ToolWindow:
.
True:
.
False:
.
.
True:
False:
True:
False:
VB 6.0 v1.0 / e- / / -
57
MDIChild
Moveable
StartUpPosition
WindowState
.
.
MDI Form
.
.
.
True False
True:
MDI Form
False:
True False
0, 1, 2
True:
.
False:
.
0: Manual:
.
1: CenterOwner:
( MDI
)
2: CenterScreen:
.
3: WindowsDefault:
Windows .
0:
1:
2:
0, 1, 2, 3
(
Form1)
.
MENU
MENU
Form1.Hide
To MENU
Form1.PopUpMenu
[]
Form1.PrintForm
Form1.Show
PopUpMenu
PrintForm
Show
VB 6.0 v1.0 / e- / / -
58
MENU:
.
. Menu Visual Basic
. Menu
.
.
, .
Activate
DeActivate
Initialize
,
( ).
,
.
.
Load
QueryUnload
[x]
.
Resize
.
project.
.
.
Terminate
Unload
(Sub).
( (Name)
Form1)
Private Sub Form_Activate()
End Sub
VB 6.0 v1.0 / e- / / -
59
:
,
, , ()
Form1.PrintForm
Me.PrintForm
Visual Basic Me
.
VB 6.0 v1.0 / e- / / -
60
;
1. , .
2. o Properties Window. (
) ,
, . .
3. , ,
.
4. ToolBox
.
5.
: . =
1. project ;
2. ;
3. Caption ;
4.
mouse ;
5.
;
6.
;
7. 3
; ;
8.
; ;
9. ;
10. ComboBox ListBox;
11. CheckBox OptionButton;
12. ;
13. ;
14. 12
;
1. project 1 , 1
ComboBox.
ComboBox.
ComboBox
TextBox.
VB 6.0 v1.0 / e- / / -
61
ToolBox
MicroSoft
() ,
.
, Menu
standard Visual Basic ( ToolBox),
, .
VB 6.0 v1.0 / e- / / -
62
Menu :
,
VB,
menu
Menu
.
Editor Menu
.
menu .
VB 6.0 v1.0 / e- / / -
63
Visible: ,
.
Next:
.
Insert: .
Delete: .
: *
: *
: .
: .
: .
Cancel: .
Menu .
. , .
Menu
.
VB 6.0 v1.0 / e- / / -
64
(*)
.
.
[]
.
Menu,
.
[] []
- [] 1.
Menu ,
.
, , [e-mail]
[] ()
, [],
. [e-mail] [] 2.
.
[Ctrl+O]
. [Ctrl]
[Shift], [Alt], {F keys} .
, ,
.
Caption - ,
( , )
(
).
VB 6.0 v1.0 / e- / / -
65
[]
.
[].
Caption
.
; , ,
,
:
Private Sub mnuOpen_Click()
End Sub
[]
Name mnuOpen.
Menu ,
,
.
VB 6.0 v1.0 / e- / / -
66
Components Microsoft
Common Dialog Control. ;
1 : ToolBox
(pop-up) menu
[Components].
2 : menu Visual Basic ( 1
), [Project] [Components]
Ctrl+T.
,
Common
Dialog.
, ;
. Common Dialog
, /
VB 6.0 v1.0 / e- / / -
67
,
..
o
ToolBox, , (
).
.
( Name) CD1.
ShowOpen : T
.
: CD1.ShowOpen
: .
()
, File name, Files of
type.
.
:
VB 6.0 v1.0 / e- / / -
68
DialogTitle: .
:
CD1.DialogTitle =
FileName: (
).
:
CD1.FileName = MyCords.txt
Filter: / .
:
CD1.Filter = " *.txt (*.txt)|*.txt| *.seq
(*.seq)|*.seq"
H CD1.ShowOpen
.
ShowSave :
.
: CD1.ShowSave
( )
.
ShowColor : .
: CD1.ShowColor
VB 6.0 v1.0 / e- / / -
69
Na
(
).
:
Color: H
.
MyColor = CD1.Color
ShowPrinter :
.
: CD1.ShowPrinter
:
Copies: .
CD1.Copies = 5
FromPage: .
CD1.FromPage = 1
ToPage: .
VB 6.0 v1.0 / e- / / -
70
CD1.ToPage = 12
:
Flags .
CD1.Flags = cdlPDPageNums
ShowFont :
.
:
Flags
:
CD1.Flags = cdlCFBoth
: CD1.ShowFont
:
FontName: .
yFont = CD1.FontName
Common Dialog
.
VB 6.0 v1.0 / e- / / -
71
;
1. Menu Common Dialog
ToolBox. Menu VB
Common Dialog
.
2. Menu
. .
3. Name Menu
.
4. Common Dialog . ShowOpen
ShowSave
DriveListBox, DirListBox FileListBox.
5. H Flags ( )
ShowFont.
.
1. Menu ;
2. Common Dialog
Scanner ;
3.
;
4. ShowColor a
Menu;
5. Menu;
6. Common Dialog
ShowSave ShowPrint,
Common Dialog ;
1. project
ToolBox ( ). .
Menu 2 , [Show]
[Hide].
(.. Label, CommandButton
). Menu [Show],
, [Hide]
.
VB 6.0 v1.0 / e- / / -
72
1) (, , , )
2)
1)
.
.
,
; .
,
.
.
:
Result = 10 + 15
Result
.
Result = X1 + X4
(
) Result X1, X4 .
1 12 (1 = 12) 4 5.
Result 17.
Result
.
( 1 4).
Result, X1, X4 .
(
). ,
VB 6.0 v1.0 / e- / / -
73
,
() .
Byte
Integer
1 byte
2 bytes
Long
4 bytes
Single
4 bytes
Double
8 bytes
String
1 byte /
Variant
Boolean
8 bytes
1 byte
[0255]
[-3276832767]
[2147483648...2147483647]
[ 3.402823*1038
1.401298*10-45]
[1.401298*10-45...
3.402823*1038] .
[ 1.79769313486232*10308 ...
4.94065645841247*10-324 ]
[4.94065645841247*10-324
...1.79769313486232*10308]
.
,
.
True False
;
(
Visual Basic) .
, .
.
: Dim
:
Dim MyVariable As
:
Dim MyName As Variant
Dim MyCounter As Integer
Dim Ok_Pressed As Boolean
Dim X3, Y3, X4, Y4 As Double
VB 6.0 v1.0 / e- / / -
74
: Dim ,
.
.
Private Sub Command1_Click()
Dim MyName As Variant
MyName = George
Print MyName
End Sub
(MyName) ,
, . MyName
.
Private Sub Command2_Click()
Print MyName
End Sub
: Public
:
Public MyVariable As
:
Public MyName As Variant
Public MyCounter As Integer
Public Ok_Pressed As Boolean
Public X3, Y3, X4, Y4 As Double
: Public Declarations
().
.
,
.
.
public ;
VB 6.0 v1.0 / e- / / -
75
Public
.
,
,
( Form2, Form1) :
Print Form1.MyName
, Public,
(
).
,
.
:
Private Sub Command1_Click()
Dim
Dim
Dim
Dim
MyName As Variant
MyCounter As Integer
Pressed As Boolean
X3, Y3, X4, Y4 As Double
MyName = "George"
MyCounter = 12
Pressed = True
X3 = 15.3456
Y3 = -24.9912
X4 = (X3 + Y3) / 2
Y4 = X3 - X4
End Sub
True (
False) VB.
MyName
George. ,
VB () George
.
MyCounter, Integer a
George
( !). ;
VB 6.0 v1.0 / e- / / -
76
,
. 12.87
. (
13).
Pressed,
(True False), .
Pressed, =
True False , .
( ) Single Double,
( ).
4 4 .
,
.
:
1. ;
2. ;
(1).
:
) .
) Visual Basic.
,
.
:
Dim
Dim
Dim
Dim
Dim
Dim
Dim
vMyName As Variant
iMyCounter As Integer
boPressed As Boolean
dX3, dY3, dX4, dY4 As Double
siNumber As Single
sNameOfFile As String.
lCounter As Long
(2).
. .
VB 6.0 v1.0 / e- / / -
77
Variant ( ), ,
.
( ) Option Explicit
Declarations , .
:
)
( )
= .
1 = 2 * 1.00023 + 2 * 3 / 4 + 55.12
1.
) (
), ,
3 = 3 + 50.412
Visual Basic : 3 50.412
( ).
,
.
1 = 1647.2791
1 = 2 * 1.00023 + (2 * 1 ) / (4 + 55.12 + 1)
VB 6.0 v1.0 / e- / / -
78
2)
,
.
,
.
,
.
,
( / records ),
.
(
!!!).
.
,
, .
.
Public Module.
,
.
65 :
Dim MyAr(65) As Single
. MyAr
. n- , ..
Dim MyAr(65, 5, 4) As Single
, .
Visual Basic
!
Dim MyAr(65, 5, 4, 2, 12) As Single
;
; ,
VB 6.0 v1.0 / e- / / -
79
.
:
Dim dX(50, 3) As Double
dX(1, 2) = 14.455
dX(10, 1) = 15.12
dX(50, 3) = 4.488
Dim.
.
;
, :
Dim MyArray( ) As Single
(ReDim)
MyArray
.
ReDim MyArray(iNumber1, iNumber2) [As Single]
( [ ] )
. ,
.
:
iNumber1 iNumber2.
(Byte, Integer, Long).
VB 6.0 v1.0 / e- / / -
80
;
1. =
( )
.
2.
(met1 = met1 + 1).
3.
, ,
Visual Basic.
4.
,
.
5. Dim
, .
project
Public Declarations
.
6. ,
,
ReDim.
1. 13.176
String; A , ;
2. Variant
;
3.
; ,
;
4.
Boolean;
1. project 2 2 .
2 ,
,
.
Label.
VB 6.0 v1.0 / e- / / -
81
Visual Basic
.
.
(intrinsic functions)
VB ,
.
:
) :
Sin (), Cos
(), bs ( ) . :
Sin(a)
Cos(a)
Tan(a)
Atn(a)
Abs(a)
Int(a)
Rnd *
0
.
>0
>=0
ea
Log(a)
Sqr(a)
Sgn(a)
Exp()
>0 1
=0 0
<0 -1
VB 6.0 v1.0 / e- / / -
82
, .
Microsoft ( VB)
,
:
(Arcsin)
(Arccos)
Modulo ( )
a = Sin(b)
a = Cos(b)
,b
:
arcsin, arccos, arctan2 (
) intrinsic functions .
, ..,
2 (
: tanG12 = DX/DY , G12 = arctan [DX/DY] ).
, Arccos
,
Arccos ( Atn ).
()
,
VB 6.0 v1.0 / e- / / -
83
Derived equivalents
Secant
Sec(X) = 1 / Cos(X)
Cosecant
Cosec(X) = 1 / Sin(X)
Cotangent
Cotan(X) = 1 / Tan(X)
Inverse Sine
Inverse Cosine
Inverse Secant
Inverse Cosecant
Inverse Cotangent
Hyperbolic Sine
Hyperbolic Cosine
Hyperbolic Tangent
Hyperbolic Secant
Hyperbolic Cosecant
Hyperbolic Cotangent
Inverse Hyperbolic
Sine
Inverse Hyperbolic
Cosine
Inverse Hyperbolic
Tangent
Inverse Hyperbolic
Secant
HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)
Inverse Hyperbolic
Cosecant
Inverse Hyperbolic
Cotangent
Logarithm to base N
VB 6.0 v1.0 / e- / / -
84
: ( .. Arcsin)
.
.
:
Private Sub Command1_Click()
Dim dCos As Double, dSin As Double, dAtn As Double
Dim siRand As Single, dMyNum As Double
dMyNum = 1.3466
dCos = Cos(dMyNum)
dSin = Sin(dMyNum)
dAtn = Atn(dMyNum)
Randomize Timer
siRand = Rnd * dMyNum
Debug.Print dMyNum
Debug.Print dCos, dSin, dAtn
Debug.Print siRand
End Sub
Command1.
.
dMyNum.
dCos, dSin, dAtn
Cos, Sin Atn ( ),
dMyNum.
Randomize Timer: VB
, , Rnd.
Rnd
.
[0...dMyNum),
siRand.
Debug.Print: ,
Immediate Window ( ).
.
Atn.
VB 6.0 v1.0 / e- / / -
85
Immediate Window :
. ,
.
) :
,
, .
String Variant.
Len(aString)
aString
.
Mid(aString,
iStartP, iEndP)
aString
iStartP
iEndP.
().
(),
.
Variant String
VB 6.0 v1.0 / e- / / -
86
Left(aString,
iLength)
Right(aString,
iLength)
Trim(aString)
Ltrim(aString)
Rtrim(aString)
aString
(
)
.
aString
(
)
.
.
.
.
(),
()
(),
()
Variant String
Variant String
().
().
().
VB 6.0 v1.0 / e- / / -
87
:
Private Sub Command1_Click()
Dim vMyName As Variant
Dim iStPos As Integer, iEndPos As Integer
Dim iLength As Integer, vNameAfter As Variant
vMyName = "
Fanis "
iLength = Len(vMyName)
Debug.Print " = "; vMyName
Debug.Print " = "; iLength
vMyName = Trim(vMyName)
iLength = Len(vMyName)
Debug.Print " = "; vMyName
Debug.Print " = "; iLength
iStPos = 1
iEndPos = 3
vNameAfter = Mid(vMyName, iStPos, iEndPos)
Debug.Print " = "; vNameAfter
End Sub
:
. vMyName .
vMyName iLength.
.
.
vMyName .
2 ,
(1 3 ).
vNameAfter 3 vMyName
( 1 3). .
.
VB 6.0 v1.0 / e- / / -
88
) :
,
.
Now
Date
Time
Year(aDate)
Month(aDate)
Day(aDate)
Hour(aTime)
Minute(aTime)
Second(aTime)
.
.
.
.
.
.
.
.
:
Dim MyDate As Date
, Variant
.
VB 6.0 v1.0 / e- / / -
89
:
Private Sub Command1_Click()
Dim vMyDate As Variant, AnotherDate As Date
vMyDate = Now
Debug.Print vMyDate
Debug.Print Hour(vMyDate), Minute(vMyDate), Second(vMyDate)
AnotherDate = #8/22/2005#
Debug.Print AnotherDate
End Sub
,
.
) , :
.
MsgBox ( )
:
Prompt : ( /
.
Buttons As VbMsgBoxStyle = vbOKOnly :
MsgBox .
Title : O MsgBox.
VB 6.0 v1.0 / e- / / -
90
HelpFile :
.
Context : Visual Basic
( ).
.
:
vbInformation + vbOKCancel
. HelpFile
Context
.
Prompt
.
(Active
Interface).
VB 6.0 v1.0 / e- / / -
91
InputBox ( )
:
InputBox
InputBox. Answer.
Prompt : InputBox
.
Title : O InputBox.
Default : ( ).
XPos :
InputBox.
YPos : InputBox.
HelpFile :
.
Context : Visual Basic
( ).
,
, 145.522.
XPos, YPos HelpFile
Context. XPos, YPos
.
VB 6.0 v1.0 / e- / / -
92
Answer.
InputBox Prompt.
Format
:
:
Format( , )
.. Format(MyNumber, 0,000)
H Format ,
, .
Format ,
.
Private Sub Command1_Click()
Dim dNum1 As Double, dNum2 As Double
dNum1 = 23.342342
dNum2 = 0.12342342
Debug.Print
Debug.Print
Debug.Print
Debug.Print
Format(dNum1,
Format(dNum1,
Format(dNum1,
Format(dNum1,
"0.000")
"0000.0000")
"-0.0")
"0.00000000000")
VB 6.0 v1.0 / e- / / -
93
Format
.
Visual Basic:
VB 6.0 v1.0 / e- / / -
94
Ta :
,
, .
VB 6.0 v1.0 / e- / / -
95
VB 6.0 v1.0 / e- / / -
96
;
1. Visual Basic
.
.
2.
.
Visual Basic.
3. Ta
.
4. MsgBox /
.
5. InputBox .
.
6. Format /
.
,
().
1. ;
2.
;
3.
;
4.
;
5. String;
Variant;
6.
MsgBox;
7. InputBox;
8.
InputBox
; .
1. project 3
3 3 .
VB 6.0 v1.0 / e- / / -
97
Visual Basic
.
:
2 .
,
.
.
/.
,
.
; Visual Basic
:
, .
,
set .
IfThenElse(End If)
:
If Then Else
:
MyNum1 = 12
MyNum2 = 23
If MyNum1 > MyNum2 Then MsgBox ! Else
MsgBox O !
;
;
VB 6.0 v1.0 / e- / / -
98
If...Then...Else
.
. ,
.
=
>
<
>=
=<
<>
(
,
).
(argument): , ,
, , (), ..
Cos(3.14), 3.14
MsgBox !,
MsgBox
.
Y
.
,
10. ,
:
And
Not
Or
Xor
()
()
()
VB 6.0 v1.0 / e- / / -
99
,
IfThen Block IfEnd
If
If [And ] [r ] Then
Else
End If
, .
:
X1 = 30.45 : Y1 = 23.11
X2 = -49.77 : Y2 = 16.78
Z1 = 100 : Z2 = 0
If X1 > X2 And Y1 < Y2 Then
Z1 = Z2
Else
Z2 = Z1
End If
Debug.Print Z1 , Z2
; : 100
If X1 < Abs(X2) And (Y1 - Y2) > 0 Then
Z1 = Z2
Else
Z2 = Z1
End If
Debug.Print Z1 , Z2
; : 0
If X1 < X2 Or Y1 = Y2 Then
Z1 = Z2
Else
Z2 = Z1
End If
Debug.Print Z1 , Z2
; : 100
100
100
VB 6.0 v1.0 / e- / / -
100
100
(And, Or, Xor, Not) .
Block IfEnd If ElseIf,
Else If.
If X1 > X2 And Y1 < Y2 Then
Z1 = Z2
Debug.Print Z1, Z2
ElseIf X1 > X2 Then
MsgBox " "
ElseIf Y1 < Y2 Then
MsgBox " "
End If
;
. ( 1,1
).
If X1 > X2 And Y1 < Y2 Then
1 >2 1 < 2 :
Z1 = Z2
2 1
Debug.Print Z1, Z2
1 2
ElseIf X1 > X2 Then
1 > 2 :
MsgBox " "
ElseIf Y1 < Y2 Then
1 < 2 :
MsgBox " "
End If
Block If
To
.
VB 6.0 v1.0 / e- / / -
101
OptionButton;
Block If.
4 Option Buttons ,
, ,
OptRed, OptGreen, OptBlue, OptCyan, .
. Option Buttons
, Value = True,
( ).
Check!.
:
CommandButton :
Private Sub Command1_Click()
If OptRed.Value = True Then
MsgBox " !"
ElseIf OptGreen.Value = True Then
MsgBox " !"
ElseIf OptBlue.Value = True Then
MsgBox " !"
ElseIf OptCyan.Value = True Then
MsgBox " !"
End If
End Sub
102
To
Is
,
Else
(num1 To num2)
+ / : (.. Is > 23 , Is<=12 ).
And Block If. (. 12, 23, 17, 9 )
. Else Block If.
.
.
VB 6.0 v1.0 / e- / / -
103
[0,100)
Select Case i
Case 0 To 10
Debug.Print " i [0...10]"
Case 11 To 30
Debug.Print " i [11...30]"
Case 32, 34, 36, 38, 40, 42, 44, 46, 48, 50
Debug.Print " i [31...50]"
Case 51 To 60, 62, 64, 66, 68, 70
Debug.Print " i [51...60] [61...70]"
Case Else
Debug.Print " i "
End Select
End Sub
VB 6.0 v1.0 / e- / / -
104
[0,100)
Select Case i
Case 0 To 65
Debug.Print " i [0...65]"
Case 10 To 30
Debug.Print " i [11...30]"
Case 32, 34, 36, 38, 40, 42, 44, 46, 48, 50
Debug.Print " i [31...50]"
Case Is > 66
Debug.Print " i "
End Select
End Sub
. ;
i = 21 Case
Block Select Case.
! i=
38, 28, 22.
Case Select Case Block.
VB 6.0 v1.0 / e- / / -
105
;
1. Block IfEnd If
f End If.
2. Block If, .
3. To Select Case Block
Select Case End Select.
4. Select Case Case
.
5. .
6. Else
.
7. ElseIf
.
1. (Block If
Select Case); ;
2. ;
3. Block IfEnd If;
4. Xor;
5. Is;
6. Case;
7. Case Block If...End If;
Block IfEnd If Block Select Case;
1. project OptionButtons
Block IfEnd If, Block Select Case.
, .
2. project
(ComboBox), 6 , 2
Block IfEnd If Block Select Case
.
3. project
10 30.
.
.
,
. ,
. ,
.
VB 6.0 v1.0 / e- / / -
106
( )
Visual Basic
.
. ,
.
:
40 .
40 . ,
.
. ,
.
Visual Basic.
,
,
.
, project
10
( ). 10
. ,
( ), 100 ...!
,
.
VB 6.0 v1.0 / e- / / -
107
Next
:
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 10
Debug.Print i * 10
Next i
1 i 10.
To i (i+1)
End Sub
For i = 1 To 10
10 .
( i),
Step ( Next). Step ,
.
Debug.Print i * 10
i 10.
Next i
Next
i (
= 1)
, 10,20,...,90,100.
i 11 For,
, i , .
Next.
,
:
VB 6.0 v1.0 / e- / / -
108
1
2
3
4
5
6
7
8
9
10
i
1
2
3
4
5
6
7
8
9
10
11
10
20
30
40
50
60
70
80
90
100
() i
11
)
:
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 10 Step 2 1 i 10.
Debug.Print i * 10
Next i
To i (i+2)
End Sub
1
2
3
4
5
i
1
3
5
7
9
11
10
30
50
70
90
() i
11
)
10
, i 3. i
= 2 ( Next). i 3,
ForNext .
VB 6.0 v1.0 / e- / / -
109
1
2
3
4
i
10
8
6
4
2
100
80
60
40
() i 2
(<3)
)
(embedded loop):
Private Sub Command1_Click()
For i = 1 To 4
For j = 3 To 1 Step -1
Debug.Print i, j, i * j * 10
Next j
Next i
End Sub
.
) For i = 1 To 4 i 4 (
1 4), i = 1 = 1.
) For j = 3 To 1 Step 1 j
3 ( 3 1), j = 3 = -1.
) Debug.Print i, j, i * j * 10
i, j, i
* j * 10
) Next j j 1 .
j 0 (<1)
) Next i i 1 .
i 5 (>4) (
) .
VB 6.0 v1.0 / e- / / -
110
i
1
j
3
2
1
3
2
1
3
2
1
3
2
1
i , j, i * j * 10
1
1
1
2
2
2
3
3
3
4
4
4
3
2
1
3
2
1
3
2
1
3
2
1
30
20
10
60
40
20
90
60
30
120
80
40
O ( j)
i, .
ForNext.
Block IfEnd If .
,
.
300 ,
,
= 100, =200 = 45.
25 ,
. ,
Exit For.
,
ForNext
.
, .
Private Sub Command1_Click()
Dim Cords(100, 2) As Single
Dim j As Integer, k As Integer
For j = 1 To 100
For k = 1 To 2
Randomize Timer
Cords(j, k) = Rnd * 200 - 100
Next k
Next j
End Sub
VB 6.0 v1.0 / e- / / -
111
100 2 .
(-100...100).
;
.
, , 200
200 !!!
2 (
(n,1) (n,2) 0 20.
1
.
( )
.
Next j
.
For j = 1 To 100
If Cords(j, 1) >= 0 And Cords(j, 1) <= 20 Then
If Cords(j, 2) >= 0 And Cords(j, 2) <= 20 Then
MsgBox " ! " & j
Exit For
End If
End If
Next j
;
> 100 .
>> .
( 20)
>>> .
) j.
) , .
<<< Block .
<< Block .
< , j .
Next j ( ).
VB 6.0 v1.0 / e- / / -
112
ForNext
.
Private Sub Command1_Click()
Dim Gend As Integer, Gstep As Integer, Counter As Integer
Gend = 20
Gstep = 1
For Counter = 1 To Gend Step Gstep
Gend = 5
Gstep = 2
Debug.Print Counter
Next Counter
End Sub
Gend = 20
Gstep = 1.
Gend Gstep .
.
Counter: 1, 2, ,19, 20.
( ).
.
.
VB 6.0 v1.0 / e- / / -
113
WhileWend
.
:
While
Wend
.
:
Private Sub Command1_Click()
Dim x As Single
x = 10
While x >= 0 x 0
Debug.Print x x
x = x 1
x 1
Wend
End Sub
( ). x 1
.
,
(!) :
Private Sub Command1_Click()
Dim iRand As Integer, iUser As Integer
Randomize Timer
iRand = Int(Rnd * 20) + 1
iUser = 0
While iRand <> iUser
iUser = InputBox(" [1...20]", " ")
Wend
MsgBox "! " & iUser, vbExclamation, "!"
End Sub
[1...20].
0, .
VB 6.0 v1.0 / e- / / -
114
. ,
Wend.
!
( ForNext Exit For).
( )
.
,
, .
j = 1
While Cords(j, 1) < 0 Or Cords(j, 1) > 20 Or Cords(j, 2) < 0 Or Cords(j, 2) > 20
j = j + 1
Wend
MsgBox ", " & j
, ! (
).
j .
.
While
Wend. , Microsoft
.
VB 6.0 v1.0 / e- / / -
115
Loop).
[Exit Do]
WhileWend.
Exit Do
Loop
Do Until
[Exit Do]
Loop
(
Exit For).
While Until,
.
Do UntilLoop
Private Sub Command1_Click()
q = 10
Do Until q >= 30
Debug.Print q
q = q + 1
Loop
End Sub
H q 30.
q .
,
( ) .
ForNext Next
.
Loop Wend ( )
.
DoLoop :
VB 6.0 v1.0 / e- / / -
116
Do
[Exit Do]
Loop While
Do
[Exit Do]
Loop Until
H
.
DoLoop ,
, o
.
. ,
,
.
Ta !!!
:
VB 6.0 v1.0 / e- / / -
117
Ar
= 15. ,
Ar .
DoLoop Until,
.
, UBound. H Ubound
( 15).
(Ar) .
,
1.
Loop,
, (
Do.
Ubound, ,
LBound
. Uound.
; 1,
2 ;
.
. ,
UBound, LBound.
Dim ...
MyAr(-6 22)
MyAr(-6 22, -3 8)
22
UBound
LBound
22
-6
22-(-6)=28
28
11
-6
-3
VB 6.0 v1.0 / e- / / -
118
:
-6 22, -3 8.
,
.
.
VB 6.0 v1.0 / e- / / -
119
;
1. ForNext .
Exit
For.
2. WhileWend, Do While
Loop, Do UntilLoop DoLoop While,
DoLoop Until. DoLoop
xit Do.
3. ForNext
Next, (Step).
4. WhileWend, Do WhileLoop, Do UntilLoop
,
. , DoLoop While,
DoLoop Until ,
.
5. ForNext m
, ForNext
k ,
m * k.
1.
;
2.
;
;
3.
10
, ,
10 ,
10
;
4. ForNext
m ;
5.
: Dim MyAr(-10 To 10) ;
6.
3 ;
VB 6.0 v1.0 / e- / / -
120
1. project 10
[20...40],
. .
2. project 2 10
,
[0...25].
.
( )
,
.
2 (
).
3. project 20
[0...20].
1, 2, 3,,19,20 .
.
4. project
(m,n) + B(m,n) = C(m,n).
[1...10].
5. project
(m,n) * B(n,k) = C(m,k).
[1...10].
VB 6.0 v1.0 / e- / / -
121
()
/. .. Microsoft Word
,
, .
.
, ,
.
() .
( )
.
2 : ( /
sequential) (direct, / random)
.
VB 6.0 v1.0 / e- / / -
122
( / Sequential
files):
,
, , .
. , .
30 ,
29. ,
,
, .
;
,
Text Editor,
NotePad () Windows. ,
. .
.
:
Open ( )
:
(1) Open TheFileName For Input As #n
(2) Open TheFileName For Output As #n
(3) Open TheFileName For Append As #n
:
Open D:\MyProgs\Texts\MyText.txt For Input As #1
H TheFileName
Variant String, (
full path name).
n [1...255] ( )
()
Visual Basic .
.
For Input: .
,
, .
For Output: .
, .
VB 6.0 v1.0 / e- / / -
123
, .
.
For Append:
. ,
.
( ,
For Output). , .
,
.
,
.
, FreeFile. H
FreeFile .
( ) :
Dim FF As Byte
( Integer)
Dim FilNam As Variant
FilNam = D:\MyProgs\Texts\MyText.txt
FF = FreeFile
Open FilNam For Input As #FF
,
.
Open MyFile.txt For Output As #1
MyFile.txt 1
:
1
.
Open MyFile.txt For Input As #1
MyFile.txt 1
:
1
.
MyFile.txt .
Open MyFile.txt For Append As #1
MyFile.txt 1
VB 6.0 v1.0 / e- / / -
124
:
1
.
.
.
Close ( )
:
(1) Close #n
(2) Close
:
Close #1
:
1. Close,
.
.
2. ,
.
.
Print ( )
:
Print #n, 1, 2 , ...
:
Print #1,
Print #1, , MyAr(1,5), MyCounter, j,
Output Append.
. :
Print #n,
[n] .
[n].
,
, .
VB 6.0 v1.0 / e- / / -
125
Input ( )
:
Input #n, 1, 2, ...
:
Input #1, Rec1
Input #1, Rec1, MyVariable, TheDate
,
Input. ,
, ,
.
!!!:
,
Input past end of file,
. !
:
Open MyFile.txt For Input As #6
Input #6, vA1
Input #6, vA2
Close #6
:
MyFile.txt
( 6).
,
.
,
. ,
:
Input #6, vA1, vA2
,
,
.
VB 6.0 v1.0 / e- / / -
126
,
.
Line Input.
Line Input ( )
:
Line Input #n, 1
:
Line Input #1, Rec1
H Line Input
.
, Input (
Line Input),
.
,
.
.
EOF (End Of File )
:
EOF(n)
[n] .
EOF .
.
Private Sub Command1_Click()
Dim MyVar As Variant
Open "Demo.txt" For Input As #3
Wend
Close #3
End Sub
While.
3
. ,
, .
VB 6.0 v1.0 / e- / / -
127
WhileWend.
, Not.
While [While Not EOF(n) /. / Wend]
.
(
bytes) LOF(n).
LOF (Length Of File )
:
LOF(n)
:
LengthOfMyFile = LOF(1)
H ( Bytes)
1 LengthOfMyFile.
, ,
, .
.
VB 6.0 v1.0 / e- / / -
128
(Output)
1
(Myar) 20 ,
( ).
demo1.txt 1.
.
.
.
2
VB 6.0 v1.0 / e- / / -
129
(10 10)
ForNext .
. !
Print #15, Pin(i, j),
, .
. For jNext o
For iNext j i .
,
, ,
!
Print #15, ""
.
.
, .
VB 6.0 v1.0 / e- / / -
130
3
.
Microsoft Common Dialog Control ( )
3 .
ToolBox . CD1.
, (CommandButton)
Command1.
Private Sub Command1_Click()
Dim MyFile As Variant, Pinakas(5, 5) As Single, i As Integer, j As Integer
With CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowSave
End With
MyFile = CD1.FileName
Open MyFile For Output As #1
For i = 1 To 5
For j = 1 To 5
Pinakas(i, j) = i / j
Print #1, Format(Pinakas(i, j), "0.0000"),
Next j
Print #1, ""
Next i
Close #1
End Sub
, ! Common
Dialog ( ShowSave) ()
.
Block WithEnd With. To Block
, .
With Command1
.Default = True
.SetFocus
.Caption = "Press Me!"
.Left = 0
.Top = 100
End With
Command1.Default = True
Command1.SetFocus
Command1.Caption = "Press Me!"
Command1.Left = 0
Command1.Top = 100
VB 6.0 v1.0 / e- / / -
131
.
.
.
2 ForNext
.
,
. , ,
Format . :
, Common Dialog Control
.
VB 6.0 v1.0 / e- / / -
132
(Input)
1
3 .
Dim MyFile As Variant, Pinak(50) As Single, i As Integer, j As Integer
With CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowOpen
End With
MyFile = CD1.FileName
Open MyFile For Input As #1
j = 0
While Not EOF(1)
j = j +1
Input #1, Pinak(j)
Wend
Close #1
,
ShowOpen Common Dialog.
50 .
,
.
While Not EOFWend
.
25 (5 * 5),
.
,
format ( ) .
(5 5),
ForNext :
VB 6.0 v1.0 / e- / / -
133
2
,
Line Input.
Dim MyFile As Variant, Pinak(50) As Single, i As Integer, j As Integer
With CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowOpen
End With
MyFile = CD1.FileName
Open MyFile For Input As #1
j = 0
While Not EOF(1)
j = j +1
Line Input #1, Pinak(j)
Wend
Close #1
.
Pinak
. 5
!
VB 6.0 v1.0 / e- / / -
134
3
, Format
:
[0...1], (1...2], (2...3], (3...5]
Private Sub Command1_Click()
Dim ByCase(4) As Integer
Dim MyFile As Variant, Pinak(50) As Single, i As Integer, j As Integer
With CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowOpen
End With
MyFile = CD1.FileName
Open MyFile For Input As #1
j = 0
While Not EOF(1)
j = j + 1
Input #1, Pinak(j)
Select Case Pinak(j)
Case 0 To 1
ByCase(1) = ByCase(1)
Case 1 To 2
ByCase(2) = ByCase(2)
Case 2 To 3
ByCase(3) = ByCase(3)
Case 3 To 5
ByCase(4) = ByCase(4)
End Select
+ 1
+ 1
+ 1
+ 1
Wend
Debug.Print ByCase(1), ByCase(2), ByCase(3), ByCase(4)
Close #1
End Sub
VB 6.0 v1.0 / e- / / -
135
.
Select Case. , ,
.
[0...1], (1...2], (2...3], (3...5]. 1 ; ( 2
3); ( 1 Case
). 2 ; !
Select Case,
, Case .
Case, End Select
.
VB 6.0 v1.0 / e- / / -
136
(Append)
1
,
, .
Private Sub Command1_Click()
Dim MyFile As Variant
Dim NameAndLastName As Variant
With CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowOpen
End With
MyFile = CD1.FileName
Open MyFile For Append As #4
Do
NameAndLastName = InputBox(" ", _
" ")
Loop Until NameAndLastName <> ""
Print #4, Now
Print #4, NameAndLastName
Close #4
MsgBox " " & NameAndLastName & " !",
vbInformation, " "
End Sub
.
DoLoop Until
.
VB 6.0 v1.0 / e- / / -
137
_ (UnderScore). H
.
,
, _
[Enter]. H Visual Basic
. ,
.
,
,
.
:
George Newcomer .
& MsgBox
,
.
.
(Random Access Files).
VB 6.0 v1.0 / e- / / -
138
( / Direct,
/ Random access files):
,
5
4 .
. :
1.
, .
.
,
.
2. ,
,
,
. .
3.
,
/ .
4.
Text Editor. .
.
5.
.
Format
.
,
Format .
.
;
Visual Basic,
Type. ,
Type Module
(
) .
VB 6.0 v1.0 / e- / / -
139
Visual Basic
Module :
Menu
, () [Project]
[Add Module].
Menu [Project]
.
Open. Module Module1
project , () .
Module;
Module .
( ). .
Module
( project ),
.
(
projects),
. ,
. ,
-
.
VB 6.0 v1.0 / e- / / -
140
, Module (
Module1). Module1 modDiloseis (
).
Type:
:
[Public] Type
1 As
2 As
....
N As
End Type
Type (
) (Integer, Single, String ).
,
.
:
Public Type Points
ID As Variant
X As Double
Y As Double
Z As Double
End Type
modDiloseis Points.
.
Command6 Points!
, MyPoints
Points. ,
ID, X, Y, Z.
. ,
!
MyPoints ( Points)
!
VB 6.0 v1.0 / e- / / -
141
.
Private Sub Command6_Click()
Dim MyPointAr(50) As Points
For i = 1 To 50
Randomize Timer
MyPointAr(i).ID = i
MyPointAr(i).X = Rnd * 500
MyPointAr(i).Y = Rnd * 850
MyPointAr(i).Z = 150 + Rnd * 50
Next i
End Sub
;
Points, ForNext
1. 1,2,3,....,49,50
2. , ,
Type .
, .
Module,
, :
Public (n,m) As
Module.
,
.
Type , Format ,
.
:
Open _ For Random As #1 Len = _
_
_
.
:
: Put
VB 6.0 v1.0 / e- / / -
142
VB 6.0 v1.0 / e- / / -
143
, NewPnt
Cords ( Module)
ForNext i ,
, , NewPnt.
, bytes
NewPnt.
.
Put,
(NewPnt.PointID),
NewPnt.
.
:
Private Sub Command7_Click()
Dim GivePoint As Cords, TheCode As Integer
With CD1
.DialogTitle = " "
.Filter = *.* (*.*)|*.*| *.dat (*.dat)|*.dat"
.FileName = "Myfile.dat"
.ShowOpen
End With
MyFile = CD1.FileName
Open MyFile For Random As #1 Len = Len(GivePoint)
TheCode = InputBox(" ; [1...50]", _
" ")
Get #1, TheCode, GivePoint
MsgBox "X = " & GivePoint.X & " Y = " & GivePoint.Y & _
" Z = " & GivePoint.Z, vbInformation, " " & TheCode & " "
Close #1
End Sub
MsgBox.
,
,
.
( ).
VB 6.0 v1.0 / e- / / -
144
;
1. ,
.
, .
2. ,
n- ,
.
3.
.
.
4.
format ,
, format
.
5. Print # Input #
Put #
Get #.
6. [Public] TypeEnd Type
Module.
1.
;
2. ;
3.
;
4. ;
5. ;
6.
;
7. TypeEnd Type;
8. Modules;
9. ;
10.
Text Editor;
11. _ & ;
12. EOF(n) LOF(n);
13. Line Input # ; ;
14. Close
;
VB 6.0 v1.0 / e- / / -
145
1. project 30
[0...100] . .
,
50.
2. project 30
[0...100] . .
,
,
.
3. 40 [1...40]
, 25 [1...25]
. .
.
10 (
[1...20].
4. 50 (, ,
, ). .
.
20 .
5. Customer ID, Name,
LastName, Tel. 5
.
Label (
) ID .
6. 100
Human ID, Age,
Weight, Height, Sex. .
,
.
VB 6.0 v1.0 / e- / / -
146
! ,
, ,
, ,
, (,
, ) . -
.
:
With CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowOpen
End With
MyFile = CD1.FileName
,
; !
;
, .
, .
. ,
.
VB 6.0 v1.0 / e- / / -
147
(Sub-Routines)
.
Module.
,
.
,
Module.
.
,
Module. ;
Module, project.
Menu [Project] >> [Add Module] [Existing]
Module
project project .
VB 6.0 v1.0 / e- / / -
148
, .
Module .
:
Private Sub DoThis()
'
End Sub
DoThis
DoThat . DoThis
Module DoThat (
, Module ).
Module Module1,
. Module1
MyFile .
Public MyFile As Variant
Public Sub OpFile()
With Form1.CD1
.DialogTitle = " "
.Filter = " *.txt (*.txt)|*.txt| *.dat (*.dat)|*.dat"
.FileName = "Myfile.txt"
.ShowOpen
MyFile = .FileName
End With
End Sub
VB 6.0 v1.0 / e- / / -
149
Module ,
.
:
With CD1
.DialogTitle = "
"
.Filter = *.* (*.*)|*.*|
*.dat (*.dat)|*.dat"
.FileName = "Myfile.dat"
.ShowOpen
End With
Module1.OpFile
MyFile = CD1.FileName
Open MyFile For Random As #1 Len =
Len(NewPnt)
For i = 1 To 50
Randomize Timer
NewPnt.PointID = i
NewPnt.X = Rnd * 1000
NewPnt.Y = Rnd * 1000 - 500
NewPnt.Z = 245 + Rnd * 25
Put #1, NewPnt.PointID, NewPnt
Next i
Close #1
End Sub
,
Module1.OpFile .
(
) Module
,
.
OpFile
Module1,
VB 6.0 v1.0 / e- / / -
150
MyFile, Module1 (
Common Dialog
Module1).
O .
,
.
2 .
Module1.
Public Sum As Double
Public Sub DoSum(num1 As Double, num2 As Double)
Sum = num1 + num2
End Sub
Module1.
,
.
Command9 :
Private Sub Command9_Click()
Module1.DoSum 23.346, 66.55
Debug.Print Sum
End Sub
,
2 ( ).
.
( ).
,
.
(Function)
VB 6.0 v1.0 / e- / / -
151
.
y = F(x) = x2 6*x +23
x
y.
. (
, Module) , .
: Function
,
( ).
,
.
, .
3 :
( Module1)
Public Function Multiply(num1 As Double, num2 As Double, num3 As Integer) _
As Double
Multiply = num1 * num2 * num3
End Function
.
Command10.
Private Sub Command10_Click()
Dim MyNum As Double
MyNum = Multiply(23.4545, 12.66, 3)
Debug.Print MyNum
End Sub
) MyNum
Double,
Double.
) (
) Module .
:
VB 6.0 v1.0 / e- / / -
152
MyNum = Module1.Multiply(23.4545, 12.66, 3)
.
:
Dim vResult As Double
VResult = 45 * Log(Multiply(12.11, 3.6543, 7))
()
:
Public Type Cords2D
X As Double
Y As Double
End Type
Public Function AThem(BasePoint As Cords2D, Distance As Double, _
G_Rad As Double) As Cords2D
AThem.X = BasePoint.X + Distance * Sin(G_Rad)
AThem.Y = BasePoint.Y + Distance * Cos(G_Rad)
End Function
H
, ,
.
( ).
Command11, :
VB 6.0 v1.0 / e- / / -
153
. .
Module,
modTopoFunctions .
Module
,
.
Module :
1.
.
2. () .
3.
.
VB 6.0 v1.0 / e- / / -
154
;
1. Modules ,
, .
2.
( , Integer, Double ).
3.
.
4.
.
, .
5. Modules ,
.
Module.
1.
, .
( )
;
2. a Module;
3. Module,
;
4.
;
1. project, Module
, 2
.
2. project, Module
.
.
3. project, Module
N
.
4. project, Module
(/),
5 .
.
VB 6.0 v1.0 / e- / / -
155
VISUAL BASIC for APPLICATIONS
VB 6.0 v1.0 / e- / / -
156
1. VBA MsExcel
VBA Excel
Alt+F11 Menu [Tools] [Macro] [Visual Basic
Editor]
Project
Explorer
, Properties Window
.
project .
Immediate Window
Ctrl+G menu [View] [Immediate Window].
: menu [Insert] [UserForm]
UserForm1
ToolBox. ; VBA
3 . project interface
(buttons, textboxes ). module.
project. interface
.
Class module
.
: Userform1
form1.
(: name caption),
Userform1.
:
Private Sub UserForm_Click()
End Sub
Click.
Visual Basic.
(project explorer View
object).
VB 6.0 v1.0 / e- / / -
157
, ,
, (option button).
.
.
.
Text1
Label1
Command1
Check1
Option1
VB 6.0 v1.0 / e- / / -
158
VB 6.0 v1.0 / e- / / -
159
2. .
(bold &
red)
VB 6.0 v1.0 / e- / / -
160
3. seq
Excel. O :
, , ,
Private Sub CommandButton1_Click()
' :
' .
Textbox1
NamOfFile = TextBox1.Text
'
Worksheets("Sheet1").Range("A1").Value
Worksheets("Sheet1").Range("B1").Value
Worksheets("Sheet1").Range("C1").Value
Worksheets("Sheet1").Range("D1").Value
A,B,C,D
=
=
=
=
""
"X (m)"
"Y (m)"
"H (m)"
' Excel
MyLine = 1
' 1 buffer
Open NamOfFile For Input As #1
' : Loop
While Not EOF(1)
' ,,,
Input #1, COD, XX, YY, HH
' .
MyLine = MyLine + 1
' .
,
.
POS1 = "A" & MyLine
POS2 = "B" & MyLineCreated by K K
POS3 = "C" & MyLine
POS4 = "D" & MyLine
' . , C D
Worksheets("Sheet1").Range(POS1).Value = COD
Worksheets("Sheet1").Range(POS2).Value = XX
Worksheets("Sheet1").Range(POS3).Value = YY
Worksheets("Sheet1").Range(POS4).Value = HH
' Loop -
VB 6.0 v1.0 / e- / / -
161
Wend
' ( )
Close #1
End Sub
VB 6.0 v1.0 / e- / / -
162
4.
AutoCad.
.
Private Sub CommandButton1_Click()
'
Dim pcords(0 To 2) As Double
Dim tcords(0 To 2) As Double
' 2
Dim apo As AcadPoint
Dim ate As AcadText
' AutoCad
Dim activeDoc As AcadDocument
Dim mspace As AcadModelSpace
'
' : ___._.__
'___.__
Set activeDoc = ThisDrawing.Application.ActiveDocument
Set mspace = ThisDrawing.ModelSpace
' 500
For i = 1 To 500
Randomize Timer
' 0
pcords(0) = Rnd * 1000 + 1000
Randomize Timer
' 1
pcords(1) = Rnd * 1000 + 1000
Randomize Timer
' 2
pcords(2) = Rnd * 100 + 100
' ""
'
tcords(0) = pcords(0) + 0.2
tcords(1) = pcords(1) + 0.2
' 0.000
tcords(2) = 0
' pcords
Set apo = mspace.AddPoint(pcords)
VB 6.0 v1.0 / e- / / -
163
VB 6.0 v1.0 / e- / / -
164
1 : (n x m) .
VB 6.0 v1.0 / e- / / -
165
1 :
1. Form1 .
.
, Print ,
Move , Cls
..
.
Click , DblClick ( ) , Resize (
) , Unload () ..
. Caption
() , Font ( ) , ForeColor ( ) ,
BackColor ( ) , Left ( ) ,
Top ( ) , Width () , Height() ..
2.
Me .
Me.Print Form1.Print.
.
VB 6.0 v1.0 / e- / / -
166
3.
1 .
FreeFile ,
.. ff :
ff = FreeFile
Open aaa.txt For Input As ff
FreeFile.
[1 255]
VB 6.0 v1.0 / e- / / -
167
2 : (Sqr) , (Sin),
(Cos), (Tan).
45.
(=3,14159)
VB 6.0 v1.0 / e- / / -
168
2 :
1. H Visual Basic
.
.
Double,
.
.
2.
.
.
( ).
. /
, \
. 8/3 = 2.6666667 8\3 = 2 .
3. .
.
VB 6.0 v1.0 / e- / / -
169
3 : Label TextBox,
ForNext
VB 6.0 v1.0 / e- / / -
170
3 :
1. Label Textbox
, .
. Label
Caption, .
:
Label1 = My name is Q
Label1.Caption = My name is Q
.
TextBox. TextBox
Text.
Text1 = Hi!
Text1.Text = Hi!
.
.
2. ForNext [Step]
.
:
For = ( ) To ( ) [Step ]
Next
:
For i = 10 To 100 Step 10
Next i
Step .
i.
VB 6.0 v1.0 / e- / / -
171
VB 6.0 v1.0 / e- / / -
172
VB 6.0 v1.0 / e- / / -
173
' .
' :
'Inputbox( , , )
' (
) : "
; (1- 0-)"
' Windows
InputBox
'H ( "1")
reply = InputBox(" ; (1- 0-)","","1")
'
If (reply = 1) Then
'
' initial_value 10
initial_value = initial_value + 10
'
Else
'
Exit Sub
'
End If
VB 6.0 v1.0 / e- / / -
174
4 :
1. Do While / Loop While / Wend
.
If..Then..Else..End If Exit Sub
:
initial_value = 10000
10000 initial_value
While
.
2. Do While / Loop
:
While initial_value < 10000
Wend
.
3. If/Then//Else/End If If Block.
. :
If Then
Else
End If
VB 6.0 v1.0 / e- / / -
175
4. InputBox ,
Input Basic
.
.
VB 6.0 v1.0 / e- / / -
176
5 : . 1
.
' dx,dy.
': x0,y0,s,g,pi .
"=" (
" "). x0,y0.
= 0.
dx = x0 + 13.434
VB 6.0 v1.0 / e- / / -
177
dx = x0 + s * Sin(g * pi / 200)
dy = y0 + s * Cos(g * pi / 200)
'
Close #1
Close #2
' . .
"" "" .
End Sub
5 :
1. ascii
Editor (.. Notepad).
5
.
.
2. EOF
.
. LOF (Length Of File)
bytes. LOF
()= 0 . LOC
bytes. 128.
3. : ..
VB 6.0 v1.0 / e- / / -
178
Pl1 = K2
Text1.Text = 57.983
K3 = Text2.Text
=
. :
Mul1 = Mul1 * 2
Sum = Sum + Cop1
.
.
VB 6.0 v1.0 / e- / / -
179
'---------------------------------------------------'---------------------------------------------------' .
' General [Declarations]
' Code. ( )
' . "xyz"
3 : x,y,z
'T
Private Type xyz
x As Double
y As Double
z As Double
End Type
'
VB 6.0 v1.0 / e- / / -
180
' "randomfile7"
1 ( ) 24 (bytes)
Open "randomfile7" For Random As #1 Len = length
' ( = 100)
For k = 1 To 100
'
xyz1
xyz1.x =
xyz1.y =
xyz1.z =
' . k For/Next
' ""
VB 6.0 v1.0 / e- / / -
181
Close #11
' -
End Sub
6 :
1.
. :
a. editor
.
b.
.
c.
.
d.
.
:
Open For Random As Len =
..:
Open DATA1.dat For Random As #3 Len = 36
.
e. Input Print
Put Get .
. Put
Get :
Put , ,
Get , ,
..:
Put #12, iKey , X , Y
VB 6.0 v1.0 / e- / / -
182
2. Type/End Type
.
. ,
.
:
Private Type New_Line
Xstart As Double
Ystart As Double
Zstart As Double
Xend As Double
Yend As Double
Zend As Double
Line_Type As Variant
Visibility As Boolean
Line_Drawn As Boolean
End Type
- .
.
.
,
.
:
Dim MyLine(3000) As New_Line
3000 New_Line
1 :
VB 6.0 v1.0 / e- / / -
183
MyLine
New_Line .
,
. :
MyLine(1).LineDrawn = False
MyLine(1).Xstart = 500.45
MyLine(1).Ystart = 300.16
MyLine(1).Zstart = 800.99
3
1
.
.
Boolean
,
True False. ,
.. Pos1 > 0 MyLine(1).Visibility = True
3. Len:
( bytes).
Len(Fanis) 5 (5 )
VB 6.0 v1.0 / e- / / -
184
1. : 2 x, y
.
a. .
G() S(A<>B)
b.
: = 3,14159 ,( ) (: )
c. :
i.
ii. ( InputBox)
iii.
.
iv.
.
v. .
i)
:
Dim Xa, Ya, Xb, Yb, Sab, Gab As Double
Dim Pi As Double
Pi = 4 * Atn(1)
ii)
:
Open MyFile.txt For Input As #1
Input #1, Xa, Ya, Xb, Yb
Close #1
iii)
:
Dx = Xb Xa
Dy = Yb - Ya
VB 6.0 v1.0 / e- / / -
185
iv)
:
If Dx > 0 And Dy > 0 Then G = G
If Dx > 0 And Dy < 0 Then G = 200 - G
If Dx < 0 And Dy < 0 Then G = 200 + G
If Dx < 0 And Dy > 0 Then G = 400 - G
Dx / Dy = 0
If Dy > 0 And Dx = 0 Then
G=0
End If
If Dy < 0 And Dx = 0 Then
G = 200
End If
If Dx > 0 And Dy = 0 Then
G = 100
End If
If Dx < 0 And Dy = 0 Then
G = 300
End If
v)
:
Msgbox H S(,) & Format(Sab,0.000) & (m) &
VbCrLf & VbCrLf & G(A,B) & Format
(Gab,0.0000) & (grad) , vbInformation, " 2
"
VB 6.0 v1.0 / e- / / -
186
MsgBox.
,
.
Format:
Format ( , Format )
..
Met1 = 345.212345
Met2 = Format ( Met1 , 0.00)
H Met2 345.21
VbCrLf
H VbCrLf (2 )
.
:
Chr(13) + Chr(10)
:
NeLi = Chr(13) + Chr(10)
MsgBox
:
Msgbox H S(,) & Format(Sab,0.000) & (m) & NeLi
& G(A,B) & Format(Gab,0.0000) & (grad) ,
vbInformation, " 2 "
VB 6.0 v1.0 / e- / / -
187
2.
a.
b. /
c.
(a)
:
1)
T = (a + b + c) / 2
= Sqr( T * (T-a) * (T-b) * (T-c) )
2)
= 0.5 * b * c * Sin(A)
3)
= 0.5 * base * height
base , height
.
(b)
:
= pi * R^2
R :
pi = 3,14159 pi = 4 * Atn(1)
:
= pi * R^2 * m / 400
m :
(c)
:
For I = 1 To Vertices 1
Vertices
() ,()
adxi = X(I) + X(I + 1)
adxi:
adyi = Y(I) - Y(I + 1)
adyi: Y
Emb_plus = 0.5 * (adxi * adyi)
E = E + Emb_plus
Next I
= Abs (E)
VB 6.0 v1.0 / e- / / -
188
DLL
VB 6.0 v1.0 / e- / / -
189
,
DLL .
DLL.
Visual Basic project
Standard EXE , ActiveX DLL.
Class Module ( ),
Module,
.
Class Module Class1.
, ,
.
1: (Class Module).
.
clMat ( Name).
VB 6.0 v1.0 / e- / / -
190
2: 2 .
Module.
Public Function Rand(FromNumber As Double, ToNumber As Double, IntegerType _
As Boolean) As Double
Dim TheSpace As Double
TheSpace = ToNumber - FromNumber
If TheSpace <= 0 Then
MsgBox " !", vbCritical, "!"
Exit Function
Else
Randomize Timer
If IntegerType = True Then
Rand = Int((Rnd * TheSpace) + FromNumber)
Else
Rand = Rnd * TheSpace + FromNumber
End If
End If
End Function
,
.
,
IntegerType ,
.
:
Public Function Add2(num1 As Double, num2 As Double) As Double
Add2 = num1 + num2
End Function
Add2
.
.
3: Menu Visual Basic
[Project] [Project1 Properties].
,
( MathFunc). .
VB 6.0 v1.0 / e- / / -
191
VB 6.0 v1.0 / e- / / -
192
.
(DLL). Visual Basic.
.
1: Visual Basic,
Standard EXE project. .
2: Menu [Project]
[References]. ,
Browse
MathFunc.dll.
, Open. To DLL
, ().
project .
!
3: ,
:
VB 6.0 v1.0 / e- / / -
193
.
, MyRand clMat o
.
.
Set MyRand = New clMat.
Visual Basic MyRand
( clMat)
clMat
.
.
Rand
DLL , MyRand
clMat.
, VB
,
.
, :
VB 6.0 v1.0 / e- / / -
194
Command1,
, .
MsgBox:
Command2:
Private Sub Command2_Click()
Dim MyAdded As clMat, Sum As Double
Set MyAdded = New clMat
Sum = MyAdded.Add2(12.455, 34.6565)
MsgBox " " & Sum, vbInformation, " Add2"
End Sub
Command1. 2 ,
, Sum. :
Dll , ,
. , DLL
, o
Windows. :
System32 Windows, Regsvr32.exe
(Regsvr32.exe MyDll.DLL).
VB 6.0 v1.0 / e- / / -
195
DLL
project.
1. DLL
3 .
2. DLL ,
2 .
3. DLL
.
VB 6.0 v1.0 / e- / / -
196
, ..
.
,
( )
.
End:
End
.
[X]
(ControlBox).
,
.
: QueryUnload. (
). :
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox(" ;", _
vbCritical + vbYesNo, " ") = vbNo Then
Cancel = 1
End If
End Sub
[X] :
VB 6.0 v1.0 / e- / / -
197
Yes . No
.
Cancel (Boolean) End.
.
, MsgBox ,
IfEnd If,
.
End
:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If MsgBox(" ;", _
vbCritical + vbYesNo, " ") = vbYes Then
End
Else
Cancel = 1
End If
End Sub
End Menu
Cancel .
DoEvents:
,
. , Visual Basic
( )
Interface .
.
,
.
DoEvents .
Interface .
. DoEvents.
: (
Module)
Public iPress As Integer
Module
VB 6.0 v1.0 / e- / / -
198
(Command1).
Immediate Window i (
WhileWend.
iPress 1. Command2.
! ; Command2
!
[Ctrl] + [Scroll Lock]
{Stop} Visual Basic
Command1 ( DoEvents)
:
Private Sub Command1_Click()
iPress = 0
While iPress <> 1
DoEvents
i = i + 1
Debug.Print i
Wend
End Sub
VB 6.0 v1.0 / e- / / -
199
Command1.
Command2. ; Command2
!
DoEvents ,
.
Stop:
H Stop
,
. .
[Ctrl] + [Scroll Lock]
.
Stop
[F5] [Continue] Menu [Run] Visual Basic.
,
.
:
.
i
.
Enum:
VB 6.0 v1.0 / e- / / -
200
Enum , MyColors
Red, Green Visual Basic
( , vb).
MyColors.Yellow:
Enum
. .
Def:
.
( ... ).
,
.
Module.
VB 6.0 v1.0 / e- / / -
201
DefBool
( Boolean)
DefByte
( Byte)
DefInt
( Integer)
DefLng
( Long)
DefSng
( Single)
DefDbl
( Double)
DefDate
( Date)
DefStr
( String)
DefVar
( Variant)
DefBool LetterRange
[,LetterRange]
DefByte LetterRange
[,LetterRange]
DefInt LetterRange
[,LetterRange]
DefLng LetterRange
[,LetterRange]
DefSng LetterRange
[,LetterRange]
DefDbl LetterRange
[,LetterRange]
DefDate LetterRange
[,LetterRange]
DefStr LetterRange
[,LetterRange]
DefVar LetterRange
[,LetterRange]
DefBool B-C
DefByte A, Y - Z
DefInt I K
DefLng L N
DefSng S - U
DefDbl D - H
DefDate W
DefStr O - R
(
1 2),
.
:
DefInt I K
i, j, k
.
DefVar V
Dim,
bAsked True/False
b, b Boolean ().
(error trapping):
H (bugs)
.
.
,
.
,
. , ,
( )
! ( Murphy!).
, Testers
VB 6.0 v1.0 / e- / / -
202
, .
:
1. .
, .
2.
.
3. .
, ,
.
:
, .
4. o .
, .
,
(..
).
,
.
: MsgBox
, .
.
!
. TextBox.
Private Sub Command1_Click()
Dim anum As Double, bnum As Variant
bnum = Text1.Text
On Error GoTo ErrorTrap
anum = bnum * 1
MsgBox " ", vbInformation, ""
Exit Sub
ErrorTrap:
Err.Clear
MsgBox " ", vbExclamation, " "
Text1.SetFocus
VB 6.0 v1.0 / e- / / -
203
End Sub
.
:
On Error GoTo ErrorTrap:
ErrorTrap. set
, Basic
(GwBasic ..).
anum = bnum * 1 : ;
,
TextBox 1.
bnum, .
, !
! On Error
GoTo (
:).
Err.Clear ,
, VB
TextBox.
,
Exit Sub
End Sub. H
.
Err.Clear,
,
:
Err.Description :
: Debug.Print Err.Description
:
Err.Number :
: Debug.Print Err.Number
: ,
Microsoft.
Err.Source :
: Debug.Print Err.Source
:
.
Err.Raise :
VB 6.0 v1.0 / e- / / -
204
: Err.Raise Err.Number
: Visual Basic.
.
.
.
; ,
FreeFile.
;
,
. , .
:
project Common
Dialog .
,
, .
. :
VB 6.0 v1.0 / e- / / -