If you can't read please download the document
Upload
-
View
409
Download
20
Embed Size (px)
Citation preview
1
..
______________________________________________________________________
2001
2
.0 ...............................................................................................................................................80.1. ?...........................................................................................................................................8 0.2. , ...........................................................................................................................................................................9 0.3. Visual Basic?.............................................................................................................................................................9 0.4. Visual Basic?.............................................................................................10 0.5. ...........................................................................................................................10
I. ______________12 .0 ............................................................................................................................................130.1. ?.........................................................................................................................................................13 0.2. , .......................................................................................................................................................14 0.3. - .......................................................................................................................................................14 Visual Basic...............................................................................................................................................14 ................................................................................................................................16 ......................................................................................................................................................16 , , , ..........................................................................................17 Visual Basic ......................................................................................18
.1 - "".......................................................................................................................201.1. ................................................................................................................................................................20 1.2. ........................................................................................................................................................................20 1.3. ...........................................................................................................................21 1.4. ..................................................................................................................................................................21 1.5. . ...........................................................................................................................................22 1.6. - .................................................................................................................................23 1.7. ........................................................................................................................................24 1.8. ...............................................................................................................................................................24 .......................................................................................................................................................25 ......................................................................................................................................26 ....................................................................................................................................26 1.9. ..............................................................................................................................................................27 1.10. - MsgBox ............................................................................................................................................28 1.11. ...........................................................................................................................................................28 1.12. ...................................................................................................................................................................30 1.13. - ....................................................................................................................................30 .............................................................................................................................................................30 ............................................................................................31 ......................................................................................................31 ....................................................................................31 ..................................................................................................31
.2 Visual Basic.....................................................................................................................322.1. , .........................................................................................32 2.2. Visual Basic...................................................................................................................................................32 2.3. Visual Basic...................................................................................................................33 2.4. Visual Basic ...............................................................................................................................33 2.5. . ................................................................................................33 2.6. Visual Basic......................................................................................................................................................35 2.7. Visual Basic.................................................................................................................................................36 ...............................................................................................................................................37 2.8. .............................................................................................................37
II. Visual Basic _____40 .0 ..........................................................................................................................410.1. . .............................................................................................................41 0.2. .....................................................................................................................................43 InputBox.......................................................................................................................................................................43 ...............................................................................................................................................................45 ..............................................................................................................................45
3
...................................................................................................46 . ........................................................................47 0.3. .....................................................................................................................................................................48 0.4. . ...........................................................................................................49 0.5. ...............................................................................................................................50 Integer Long - ......................................................................................................................................50 Single Double - .........................................................................................................................50 ? Currency..............................................................................51 ........................................................................................51 ..................................................................................................................................51 0.6. ...................................................................................................53 0.7. .......................................................................................................................................................54 0.8. Print .................................................................................................................55 0.9. ........................................................................................................................................................57 0.10. .................................................................................................................57 0.11. ..............................................................................................................................................................58
.1 ..............................................................................................................591.1. ()..............................................................................................................................................59 1.2. If ..............................................................................................59 1.3. If....................................................................................................................61 1.4. ..........................................................................................................................................................63 1.5. If................................................................................................................................................................64 1.6. .........................................................................................................................................65 1.7. If. ......................................................................................66 If ........................................................................................................................................66 .................................................................................................................................................66 ............................................................................................................................................67 1.8. Select Case...........................................................................................................................................68 1.9. .......................................................................................................................................................70 .................................................................................................................70 .............................................................................................................................................71 ...............................................................................................................................71 1.10. MsgBox...............................................................................................................................................................71
.2 ......................................................................................................................732.1. GoTo. . ............................................................................................................................73 .................................................................................................................................75 2.2. If............................................................................................................................................75 2.3. Do..........................................................................................................................................................76 Do . Loop...............................................................................................................................................76 Do . Loop While.....................................................................................................................................77 Do . Loop Until......................................................................................................................................77 Do While . Loop ....................................................................................................................................78 Do Until . Loop .....................................................................................................................................78 Do.........................................................................................................79 Exit Do.......................................................................................................................................................79 ...................................................................................................................................80 2.4. For.............................................................................................................................................................80 Exit For......................................................................................................................................................82 2.5. ................................................................................................................................................................82
.3 ...............................................................................................................................833.1. . .............................................................................................................................83 3.2. . . ....................................................................................................83
.4 .......................................................................................................874.1. .........................................................................................................................87 4.2. .........................................................................................................................................................................87 4.3. ...............................................................................................................................................................................88 4.4. ...........................................................................................................................................................................89 4.5. ..................................................................................................................90 4.6. ...............................................................................................................................................................90 4.7. ..........................................................................................................................................92
.5 ....................................................................................................................................................935.1. . , , ................................................................................................................93 5.2. ..........................................................................................................................................................94
4
5.3. - Visual Basic ....................................................................................95 .........................................................................................................................................95 ........................................................................................................................95 5.4. - Line Shape.............................................................................................................................96 5.5. . ZOrder ..............................................................................................................97 5.6. Visual Basic...............................................................................................................................................................98 5.7. 3 - .....................................................................................................99 Pset................................................................................................................................................................100 Line...............................................................................................................................................................101 Circle.............................................................................................................................................................101 CurrentX, CurrentY, Step.........................................................................................................................................102 Cls.................................................................................................................................................................102 Point..............................................................................................................................................................102 PaintPicture..................................................................................................................................................103 5.8. ...........................................................................................................103 5.9. .....................................................................................................104
.6 ..............................................................................................................................................1066.1. ...........................................................................................................................106 6.2. Stop, End Exit Sub...............................................................................................................................109 6.3. ................................................................................................................................................110 6.4. ..........................................................................................................................................................................111 6.5. ................................................................................................................................................112 ....................................................................................................................................................113
.7 , , ...............................................................................................1157.1. Date................................................................................................................................................................115 ...............................................................................................116 7.2. ................................................................................................................................................................................117 ..........................................................................................................................................................117 7.3. "-".....................................................................................................................................118 Boolean..................................................................................................................................122 .....................................................................................................................................................122 ........................................................................................................125 .........................................................................................................................................127 7.4. ...........................................................................................................................................................................127 .......................................................................................................128 .....................................................................................................................................................128 "" ...............................................................................................................................129 .............................................................................................................................................................129 ................................................................................................................................................130
.8 .........................................................................................................1318.1. .................................................................................................................................................................131 MouseDown MouseUp...........................................................................................................................131 MouseMove...............................................................................................................................................132 ...........................................................................................................................................................133 8.2. ........................................................................................................................................................133 KeyDown KeyUp....................................................................................................................................133 8.3. - ()........................................................................................................................................................134 8.4. ...................................................................................................................................141
III. Visual Basic - ____143 .0 .................................................................................................................................................1440.1. ..................................................................................................................................................144 0.2. ..................................................................................................................144 0.3. ..........................................................................................................................................................146 0.4. .....................................................................................................................................................147 0.5. ..................................................................................................147 0.6. ......................................................................................................................................149
.1 ............................................................................................................1521.1. Variant.........................................................................................................................................................................152 1.2. .........................................................................................................................................152 1.3. ..........................................................................................................................................................................154 ..........................................................................................................................................154
5
..................................................................................................................................................................155 1.4. (Frame).....................................................................................................................................................................156
.2 ..........................................................................................................................1572.1. (CheckBox) ......................................................................................................................................................157 2.2. (OptionButton) ....................................................................................................................................158 2.3. (HScrollBar VScrollBar)..............................................................................................................159 2.4. Slider, ProgressBar .............................................................................................................................................................159 2.5. (ListBox) (ComboBox)..........................................................................................................160 (ListBox).......................................................................................................................................................160 ComboBox ( " ").................................................................................................161 ComboBox ( " Combo")................................................................................................................161 ComboBox ( " Combo").................................................................................................161 , ListBox ComboBox......................................................161 2.6. .............................................................................................................162 MonthView DTPicker...........................................................................................................................162 UpDown.....................................................................................................................................................................163 DriveListBox, DirListBox, FileListBox....................................................................................................163 RichTextBox...............................................................................................................................................................164 ListView TreeView...................................................................................................................................................164 (TabStrip) (StatusBar)............................................................................................164 MSChart.....................................................................................................................................................................164 PictureClip.................................................................................................................................................................164 ImageCombo..............................................................................................................................................................164 MSComm....................................................................................................................................................................165
.3 , , ....................................................................................................1663.1. .................................................................................................................................................................................166 ASCII...........................................................................................................................................................167 3.2. .................................................................................................................................................................................167 3.3. Shell....................................................................................................................................................................171 3.4. . On Error...........................................................................................................................171
.4 . .....................................................................................1734.1. . ........................................................................................................................................173 4.2. ....................................................................................................................................................174 ......................................................................................................................................176 4.3. ...................................................................................................................................................176 4.4. ............................................................................................................177 4.5. . ..........................................................................................................................................................178 4.6. .........................................................................................................................................................................179 4.7. , ..................................................................................................................................181
.5 , .................................................................................................1825.1. "" Windows...........................................................................................................182 5.2. CommonDialog...............................................................................................................................182 Common Dialog..............................................183 5.3. Toolbar..........................................................................................................................................184 5.4. - " "...................................................................................................................................186
.6 ..........................................................................................1896.1. .......................................................................................................................................189 6.2. .......................................................................................................................................................................190 6.3. . Project Explorer......................................................................................................................190 ...........................................................................................................................190 .........................................................................................................................191 6.4. .................................................................................................................................................................191 .................................................................................................................................191 ......................................................................................................................................192 ......................................................................................................................193 6.5. ............................................................................................................................................................................193 6.6. ..................................................................................................................................................................194 6.7. ?...............................................................................................................................................194
.7 .........................................................................................................................1977.1. - " "................................................................................................................................197 7.2. "". ....................................................................................................................................198 7.3. .....................................................................................................................199 7.4. ........................................................................................................................................................199
6
7.5. ..............................................................................................................................................199 7.6. ...................................................................................................................................................................200 - ...................................................................................................................200 .........................................................................................................................201 7.7. . ......................................................................................................................................204 7.8. ................................................................................................................................................................206 ...................................................................................................................................................207 .................................................................................................................................207 , ..................................................................................................................................207
.8 Visual Basic ........................................................................................................................2098.1. , Web- HTML....................................................................................................209 8.2. Web-...................................................................................................................................................209 8.3. Web-..............................................................................................................................................210 8.4. ..............................................................................................................................................212 8.5. ........................................................................................................................................................214
.9 Visual Basic ..................................................................................................................2159.1. ....................................................................................................................................................215 9.2. Visual Data Manager.............................................................................216 9.3. . Data DBGrid. SQL...............................................................217
.10 ..........................................................................................................................................22010.1. Visual Basic...............................................................................................................220 ActiveX.......................................................................................................................................................................220 Windows API..............................................................................................................................................................220 - MDI..................................................................................................................220 OLE............................................................................................................................................................................220 10.2. ..................................................................................................................................220
1. _____________________________________________________________223 .0 .........................................................................2240.1. . .........................................................................................224 0.2. ............................................................................................................................225
.1 .......................................................................................................2261.1. . ..................................................................................................226 1.2. ...........................................................................................................................................227 1.3. . ?........................................................................................................227 1.4. ..........................................................................................................228 1.5. .................................................................................................................................................229 1.6. ..................................................................................230 1.7. .........................................................................................231 1.8. ............................................................................................................................231
.2 ......................................................................................................2342.1. .................................................................................................................................234 .................................................................................................................................................................234 .................................................................234 2.2. ...................................................................................................................235 2.3. ...............................................................................................................................236 2.4. ....................................................................................................................................236 ...................................................................................................................................................237 2.5. .......................................................................................................................239
2. Windows. ________________241 Windows....................................................................................................................................................................241 . ..........................................................................................241 Windows ......................................................................................................................................241 .........................................................................................................................................................................243 .............................................................................................................................................243 .................................................................................................................................................................243 . (, )..................................................................................244 .......................................................245
7
...........................................................................................................................245 ...........................................................................................................................246 - ...................................................................................247 , ................................................................................247 ................................................................................................................248
____________________________________________249 _________________________________________276 ______________________________________278
8
.0 - Visual Basic! , . : , . , : . . , . . . , . , , ! , , , , . Visual Basic . , . " " , . Visual Basic , . . , , , . Visual Basic . Visual Basic , , Delphi ( Object Pascal), Visual C++ . , , . , , , . , Visual Basic , , .
0.1. ? . , , , Visual Basic . , . . ( 132). , . , , , , . , , , , ! , , . , , -, ( ), , . , , 0.2. , , Visual Basic, . , , . , , Visual Basic. ?. Visual Basic , . , : , , , . , , ? , ? , Visual Basic, , . Visual Basic . Visual Basic . , , , (Help). , . , , . , Visual Basic, - . , . , . , , , , . Windows, Visual Basic, . , . , , . , Visual Basic .
9
0.2. , . , . : , , , . . , , . , , , , , , . , . . - , - . , . , . , : "" "", : , , , : ( - , , ) - . . ( , , , -, , ) : ( ) : ( ) , , " " , : : - - " " - ( ) ( ),
, , . (3D) Quake Unreal. , , , . (, Direct X), , . - , 3D-. , Visual Basic, Delphi C++, , . , , , C++, : , ! , , 3D, . . , , - . , , , . , . , 3D-. , ( ) (). . , , , , , , , . , , -.
0.3. Visual Basic? Visual Basic? , , . .
10 , , , . , , . , - , . , , . . . , , , () . . , , . , . . , . , , . Visual Basic, Delphi, Visual C++ ( , ) - . , , , , , . , . . Delphi Visual Basic Visual C++. Visual Basic. , , . . , , Visual Basic , .
0.4. Visual Basic? , Windows. , , Visual Basic 6.0, - . , . . Visual Basic ( - ). . , Visual Basic 5.0 Visual Basic 6.0 , . , , . Visual Basic, Visual Basic.NET, . , , , . , .
0.5. : I. . : Visual Basic. , Visual Basic . - "", , Windows. II. Visual Basic . . . Visual Basic - , , . , , , . -. , , , , , , Visual Basic. III. Visual Basic . . , , , , Visual Basic. , , , . , , . 1. . , , . 2. . , . , , Windows, , , Visual Basic.
11
, Visual Basic . .
, . .
. e-mail: [email protected]. www.learncomp.narod.ru.
12
I. , , , : " Visual Basic , ". , , . , . - . 1 Visual Basic. 2 , , . Visual Basic. 3 " Visual Basic", Visual Basic.
13
.0 Visual Basic. .
0.1. ? , , . 1 . , "" , , . Visual Basic, . , , , , . , . , . , "" "" "" , , , 1 , .. "" .. ... .. .. ... , .. , , - .. ...
14
, - . - . " , ", - "". 9 . , "", . , " " " ". " ", , " ". . ""? " " , , " " " "? , , . ? , , , , , . , , . . , . , , . , . , , , - . , (, , , ), . , " , " , . Visual Basic . , , . . .
0.2. , , Visual Basic , . : , , , , , , .. , 3 : 1. , , .. 2. 2 , , ( , , ) . - . , : " - ", - - " - ". 3. , . - , , : . . , . , . . , , . 1 , , 2 , 3 . , , , - 1 - , . . , , . , , .
0.3. - Visual Basic - - , , , , Visual Basic. . . . , , , , . , . : " - " " - -". , , . , , - , . ! . , .
Visual Basic , , , Visual Basic. Visual Basic , 2.2, , , , 2.4. Visual Basic, - (. ). , File, Add
15
Project - .( - FileAdd project).
, . . New Standard EXE, Open. , , ( ):
, , . . - ? . , - , , . , Windows. . , . . 1 . , : , .. , - Visual Basic . Visual Basic . Toolbox ( ), , Visual Basic. , , , . - , , . Toolbox , . : "" Visual Basic , , , .
16
, . (CommandButton) . , "". ""? - , , , "" . "". . Command1. 8 - . , , - . . - . , , . , Delete. . , , . (TextBox). .
[design] () Visual Basic. , Visual Basic , (1 ) (2 ). . . , 2 ( ) 3 , . Start ( ). . ? , , Visual Basic , . Visual Basic. . , , Windows. . , . . . . . - , , . . . , . . Visual Basic , , . - Windows . [run] (, ) Visual Basic. , Visual Basic , (3 ), (1 ), (2 ) . , , . End . Visual Basic [run] [design]. - . .
. - . - ! , Visual Basic , , , , . . , - , . , . . () :
Form1.BackColor = vbRed
, . Form1 - ( Visual Basic ) BackColor - " ", , ( ) vbRed - (Red - , vb - Visual Basic) , : Form1. = : , - , . . . = 140 . =
17 Visual Basic . , , - ? . , [design]. Command1. - . , (Code).
. , ( ). , - . Private Sub Command1_Click() " , (- - Click) Command1". Private "" . Sub "". , : " , , , Command1". , . . End Sub, " ". , , , Command1. Form1.BackColor = vbRed. , 2. . . , Visual Basic . , ( BackColor) . . , . . : ViewCode. , - , : ViewObject. . :
. , - , . , . . , . Start. . - . ! . . . . End. , , " Visual Basic ".
, , , . -, , , . , Visual Basic, 2.5. Windows, File Save Project, , , , . Visual Basic . . , Visual Basic, , . , Visual Basic () File Open Project. , File New Project. . , Visual Basic, . , : Visual Basic ( , ) - File Remove Project. Visual Basic Project Explorer . Project Explorer
18 : Project - No Open Projects. File Open Project File New Project. , , Visual Basic . File Open Project File New Project File Add project, Visual Basic . , Project Explorer. , , . , File Remove Project, , Visual Basic . , , , , . . . . , 2.5.
Visual Basic - , Visual Basic - (, ) . , . . , :
Form1.BackColor = vbReddVisual Basic . .
Private Sub Command1_Clictk() Visual Basic . .
Form1.BackColo = vbRedVisual Basic , . , , , , . Help Visual Basic , . . OK Visual Basic . .
Foorm1.BackColor = vbRed Visual Basic , . Debug, Visual Basic . .
Form1.BackColor = = vbRed Visual Basic , . . . , , , . , , . Visual Basic . . , . , , , . , End Sub? , ? , .
, . - FileRemove Project. , . . - , . , . :
Text1.FontSize = 16 Text1 - , FontSize - . : Text1 16. : Private Sub Command1_Click() Form1.BackColor = vbRed Text1.FontSize = 16 End Sub Visual Basic Private Sub Command1_Click() End Sub. Start. , . , , . : , . . " ". : Text1.Text = " " Text1 - , Text , . ( Text1 Text) . : Text1 - " ". :
19 Private Sub Command1_Click() Form1.BackColor = vbRed Text1.FontSize = 16 Text1.Text = " " End Sub , . . :
- Command2. (vbYellow), 12, " " , Command1, Command2 . - , , - , Command2. . :
. . , 0.1. , . , Form1. , . - : , . ("..", " , "). - " , ". - " ", "", - .
?, . ? , - , , . . , . . Toolbox Image () - , , , .. . - . , , . , . , , , , . Visual Basic . , Timer, " ". Toolbox . . , Microsoft Multimedia Control 6.0, , . Visual Basic.
20
.1 "" Visual Basic. , Visual Basic. . Visual Basic. . -, , . , , , " " , .
1.1. 0 , Visual Basic. - . , Windows. , Windows ( Visual Basic), : . - Microsoft ? , , , , , "". , ( ):
- , .
1.2. . :
21
, .
1.3. , BackColor, FontSize, Text. . [run] , (, Form1.BackColor = vbRed). , [design]. , ( , !). [design]? . Command1. . , , . (. 0.3). , , . : . ( alphabetic) ( categorized). - Command1. Width (), - . , , 200. , . [run], Command1.Width = 200. - . , . - . - . , - . . .
1.4. (Name). (Caption). . , . , Visual Basic ( - ) , , , , . . . (Name) - . , - Form1. , , . . ? . , , , , . ( ), (). . (Caption). - - Form1. - . . , . ? , ,
.Width=6000 Form1.Width=6000
- , . Command1 _. ! , , . ,
22
.
. 0.3. +. + . . , Font . - . - , (Size), (Font Style), (Font) - . (Regular), (Italic), (Bold) (Bold Italic). (Font) . . . . : _, _, _. . . : 1, 2, . (Caption) . Text. , , Text . ( , , ). - Label (), . Label Toolbox . :
. , Visual Basic (Label1, Label2, Label3). , , , , , , , , , . . Toolbox Line () . , BorderWidth. , ! , . .
1.5. . . 3, 2. . . . . . , . : 3 2 , Text 1 2. -, 1.Text 2.Text. , .Text . :
.Text = 1.Text + 2.Text
- . : Private Sub __Click() .Text = 1.Text + 2.Text End Sub . 3 2. . . , . 5 32. ? , Visual Basic + , "". . 3 2 , . , . , 1 2, , Visual Basic , - . ? Visual Basic ,
23 . - 1.Text 2.Text, Val(1.Text) Val(2.Text). Val - Value - , . :
.Text = Val(1.Text) + Val(2.Text)
, Visual Basic , . . . , . . : Private Sub __Click() .Text = Val(1.Text) + Val(2.Text) End Sub __________________________________________________ Private Sub __Click() .Text = Val(1.Text) - Val(2.Text) End Sub __________________________________________________ Private Sub __Click() .Text = Val(1.Text) * Val(2.Text) End Sub __________________________________________________ Private Sub __Click() .Text = Val(1.Text) / Val(2.Text) End Sub :
*, - /.
. .
, ! : (, -), , . Visual Basic . 1.9.
1 . : . 2 , . . : 1.Text = "". . , .
1.6. - . , . , - -. , , , , [run]. : . " " , , - . - . , - . - . - ", !" BackColor ( ) - . . . - . Palette () . ForeColor ( , ). Appearance ( ) - 3D () Flat (). BorderStyle ( ). 6 , , , [run]. ToolTipText ( ). , , , Windows, Word, - , , , . ToolTipText. . . . . MouseIcon, MousePointer ( , ). . MousePointer 2 (). .
24 . . , , . MousePointer 16 . MouseIcon . MousePointer 99. MouseIcon Windows\Cursors Cursors Icons, Graphics, , Visual Basic. ? , . - . . . MaxButton ( - ). - True (). False (), . MinButton ( - ). - True (). False (), . Moveable ( ). False , [run] . . WindowState , : 0 - , 1 - ( Windows) 2 - ( ). Visible (). - True (). False (), . . Enabled ( ). - True. False, , . . Alignment. , . MultiLine. True, , . ScrollBars, .
1.7. , - . , . , , - , , Paint. . Picture. . . Open - . (.5.3). Microsoft Office, Clipart . , - PictureBox Image - . ( Style Graphical).
1.8. , . , ( - ). -. MID, WAV, MP3 . , - MP3. , , , , WAV. , , C:\Windows\Media. - Canyon.mid. . Windows . () Wave ( WAV- MP3-) MIDI ( MID RMI-). , , . , Microsoft Multimedia Control 6.0. Toolbox. . : Projects Components OK. Toolbox. . . (, ). , .
25 [run], , : Properties Controls . , , Visual Basic : .DeviceType = "Sequencer" .FileName = "c:\Windows\Media\Canyon.mid" .Command = "Open" .Command = "Play" : (DeviceType) , . mid, rmi Sequencer. wav, mp3 WaveAudio. , . (Command) (Open) . . (Play) . , , , . , , , - - . , 4 ? - , ? , (, ). , Visual Basic . - (Form_Load) - (, ) . - . . : Private Sub Form_Load() End Sub : " , ", " , ". , 4 . . . , , , "Close". , - . Form_Terminate. : Private Sub Form_Terminate() .Command = "Close" End Sub , Form_Terminate , , , End . , , .
- , - , . C:\Windows\Media. , wav. Chime.wav, Notify.wav, Tada.wav Logoff.wav. Microsoft Multimedia Control 6.0. . , . , . Visible False. Wav- WaveAudio. , . .
.DeviceType = "WaveAudio"
, - Form_Load. :
.FileName = "c:\Windows\Media\.wav" .Command = "Open" .Command = "Sound" .Command = "Close" : "Sound" , "Play", ,
, . , . "Play" Canyon.mid, , . "Sound" Chimes.wav, "". : , Canyon.mid Wav-. , :
26 Private Sub __Click() .FileName = "c:\Windows\Media\Chimes.wav" .Command = "Open" .Command = "Sound" .Command = "Close" .Text = Val(1.Text) + Val(2.Text) End Sub Private Sub __Click() .FileName = "c:\Windows\Media\Notify.wav" .Command = "Open" .Command = "Sound" .Command = "Close" .Text = Val(1.Text) - Val(2.Text) End Sub Private Sub Form_Load() .DeviceType = "WaveAudio" .DeviceType = "Sequencer" .FileName = "c:\Windows\Media\Canyon.mid" .Command = "Open" .Command = "Play" End Sub Private Sub Form_Terminate() .Command = "Close" End Sub
Microsoft Multimedia Control 6.0 --. , "CDPlayer". CD-ROM . : CDPlayer.DeviceType = "CDAudio" CDPlayer.Command = "Open" CDPlayer.Command = "Play" - Visual Basic. . Visual Basic . Microsoft Multimedia Control 6.0 , .
5-6 , - , 5-6 . . , . , "", . LoadPicture . . , . , , , . (Label)
Form1.Picture = LoadPicture("C:\Program Files\Microsoft Office\Clipart\Popular\Agree.wmf")
Label1.Caption = " - . 1970 ."
- ? , .
.Command = "Play" .Command = "Close"
, , . : .Command = "Close" .FileName = "c:\Windows\Media\Canyon.mid" .Command = "Open" .Command = "Play" "Close" , . "Open" .
27
3: - " ". 4 " -":
- : , , . " " . . , . . - CD-RW, -, . , . - , , , 2.8, . .
1.9. , , , , , . . , , , . :
y x
:
x
y , . . , Visual Basic . , , .
Top.
? Left Left - . Top - .
, . - , Left Top. : Visual Basic .
28 . . Left, Top, Width ( ) Height ( ). , Width Height. , . Left Top , . :
Form1.Left = 2000 "" : 5: - " " " - !". , , .
1.10. - MsgBox - . , :
:
, Form_Terminate. , . 1.10. , , , ?
MsgBox (" !")
1.11. ! , , , , , . :
: " ", . "" , , "" - . " ", . , . . , Visual Basic ToolsMenu Editor. :
29
. Caption " ". , . , . , , ___, Name. . , , Shortcut. Next "", __. Next "", __. Next " ", ___. 4 :
, "" "" " ". . :
- , , , . , Delete , Insert . - . . , . . , . , , , . . "" . : Private Sub ___Click() End Sub
30 , , "". :
Form1.Picture = LoadPicture() Form1.BackColor = vbBlue , , ( 3 1.8). "".
MsgBox (" 2000 ")
, . Visual Basic , , . Visual Basic ( , 2.5). , .
1.12. - , , , . . ! ! . ProjectComponentsMicrosoft Windows Common Controls-2 6.0. Toolbox . Animation - . - Animation1. AVI. , - Videos, , Visual Studio. : "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Videos". , , "". , "" FILECOPY.AVI: Private Sub _Click() Animation1.Open "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Videos\FILECOPY.AVI" Animation1.Play End Sub , 1.8 , . . "" , Animation1.Stop, - Animation1.Close. 3 5 12, . - - Microsoft Multimedia Control 6.0, AVI. , , "". , : .DeviceType = "AVIVideo" .FileName = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Videos\ FILECOPY.AVI" .Command = "Open" .Command = "Play" , , . , .
Animation1.Play 3, 5, 12
1.13. - - . ? , , ( ): Private Sub __Click() .FileName = "c:\Windows\Media\Chimes.wav" .Command = "Open" .Command = "Sound" .Command = "Close" .Text = Val(1.Text) + Val(2.Text) End Sub , . , ? , , , ( ), , , !
31 . - . - . , . : ', , , ' , : 'Chimes.wav , . Private Sub __Click() .FileName = "c:\Windows\Media\Chimes.wav" ' . .Command = "Open" ' . .Command = "Sound" ' . .Command = "Close" ' . .Text = Val(1.Text) + Val(2.Text) ' , Val End Sub , , , . . , , . Visual Basic, , , , .
, . - , , . , . . ,
.Text = Val(1.Text) + Val(2.Text) .Text = Val(1.Text) _ + Val(2.Text) .Text = _ Val(1.Text) _ + Val(2.Text)
, - .
Visual Basic , , : .Command = "Open" : .Command = "Sound" : .Command = "Close" .
Windows : Windows ( ) . Visual Basic, , , . , , , , Visual Basic. - FileMake Project1.exe. , , (, ). - .exe . c:\Windows\ , Windows, ( ) c:\Windows\ \\, Windows ( , ). , .exe , . , (. 2.8).
1.9). , 1.5. , , , ( . (. 0.5 " ").
.
32
.2 Visual Basic , . Visual Basic, Visual Basic, , Visual Basic .. , . , , . Visual Basic . , , Visual Basic, , . : 0.2 - 2.1 - 3 - 5.1 - . , , 1.4 - (Frame) 6.3 - . Project Explorer. 2. Windows. , , .
2.1. , , Visual Basic , . , : , , , Windows. , , . , , Visual Basic .
2.2. Visual Basic-, - . , , . , , . Visual Basic, (). , 2.8. , Visual Basic , , 2.4. , . Windows, , , . Visual Basic, -. Visual Basic - , Microsoft Visual Studio, Visual Basic Visual C++ Visual FoxPro. , - ( -) Visual Basic Visual Studio. Visual Basic - -. , , . : 1. ( 1 ) CD-ROM. , . . . . , . . , 4. , . 2. Setup.exe -. Windows CD-ROM. "". -. 3. Setup.exe . 4. . . - . Visual Basic Visual Studio 6.0. Visual Basic , .
33 . . Next. , Visual Studio. , I accept the agreement. Next. - . . . . . Next. Custom. , . . Next. Continue. OK. Visual Studio . , : Microsoft Visual Basic Active X Data Access Graphics Tools . Continue. - , , . , . ( Windows Restart). , , , . Visual Studio. . . -.
5. 6. 7.
8. 9. 10. 11. 12.
13. 14. 15. 16.
2.3. Visual Basic(1) Visual Basic (2) , . (3) (4) ( Start F5). , 6 (5) ( . 3) 3 (6) . 3 .
2.4. Visual Basic Visual Basic . "" . Microsoft Visual Studio Microsoft Visual Basic. Visual Basic , Windows - Visual Basic File Exit.
2.5. . , . Visual Basic . , , Visual Basic . Visual Basic "" - Ctrl-Alt-Del. , Visual Basic . , () . File Save. , :
34
Save in , . , ( VB98). , Visual Basic. , , , , , , . , Save in. , . , , Save as type All Files. frm, Form Files (*.frm). . Save in, . , . ? . , Save in, , . - . , (Desktop), . , . Save in, , Windows. . , Save in, . , . .
Windows . , - , , , , . , . . ! . Cut () Delete (). , Copy (). , , Save in, . Paste (). , , Save in . , , , Copy Cut (). , Rename (). , , VB98 , , -, , " ". . . File Name - Form1.frm. - , - . Save. Visual Basic . Project1.vbp. . , . : File Save. . Visual Basic, , ( , ) , , . ( , .) .
35
. , , . , Visual Basic, - File Open. , , . : , . , . . , , , . Windows, Visual Basic.
2.6. Visual Basic Visual Basic 6.0. , , . . . Visual Basic , , Windows: , , - . , . Windows, 2. , . 0.3. -: Object - , Project1 - Form1 (Form). - . , . Toolbox - . Code - . Visual Basic . , Command1, Command1_Click. , . ? : , Command1 Text1. , , , . (DblClick) Text1. Text1, , , , Text1. DblClick - : Private Sub Text1_DblClick() End Sub : , ( ) - . . Properties - . Project Explorer - . , . , . Project Explorer . . Project Explorer 6.3. - , View , , . , , Window , . , Windows. : Form Layout - . Object Browser - . () Visual Basic. - , , TextBox, , , , (. 5.1), . , , , , , [run]. , SelText TextBox, , . Object Browser - , "" . Object Browser 5.1. Color Palette - . , "" ""
36 Visual Basic. , , . , Tools Options Docking . "" . , , , Windows, - Visual Basic. , Windows.
2.7. Visual Basic . , . , , 6.3.
FileNew Project. . Open Project. , . Add Project. , ( Existing Recent) , . , , New Project Open Project. Remove Project. , , , , Project Explorer. Save Project. . Save Project As. . Print. . Print Setup. . Make Project1.exe. (. 1.13). , . Exit. Visual Basic.
EditUndo. . Redo. . Cut, Copy, Paste, Delete. , , . , . , 2. . , , - Toolbox, , . : Copy Paste. Copy Paste . Cut ( ) Delete (). Find, Find Next, Replace. .
ViewCode, Object, Object Browser, Project Explorer, PropertiesWindow, Form Layout Window, Toolbox, Color Palette - Visual Basic, . . Immediate, Locals, Watch - , (. 3). Add Form- . - [ run]. , . , [run] . , - , , . . 6.1. Remove Form - . Components. Controls, Toolbox . Insertable Objects, Windows. , Word, Microsoft Word Document . Toolbox Word. . Word , Visual Basic, Word , [run]. , .
Project
FormatAlign, Make Same Size - , , , . , , . , Ctrl . Order. , . , .
37 - , . , Bring to Front ( ) Send to Back ( ) Lock Controls. . , . . , .
Debug (. 3).
Run, Query, Diagram . Menu Editor, (. 1.11). , Options, Visual Basic: : Editor - , . Require Variable Declaration, . Tab Width Tab. Editor Format - , , . General - , , . Align Controls to Grid , . Show Grid, . , . Docking - , Visual Basic , "" "" Visual Basic. , . Environment - When Visual Basic starts , Visual Basic (Prompt for project) (Create default project). When a program starts , Visual Basic (Save Changes), (Prompt To Save Changes) (Don't Save Changes). . . Advanced - . Visual Data Manager, . - 9.2. Windows. . Split , , , .
Tools
Add-Ins
Window Help
Visual Basic, , -, , , -, . Visual Basic , , . . - Help , . , , . - , , BackColor, F1. Contents . Index , , (, FileName). Visual Basic 6.0 MSDN (MSDN Library), - Visual Studio.
. - . - . Left, Top, Width Height . Visual Basic . : View Toolbars. , , Form Editor, , Format , . , , Edit . .
2.8. , , , , , . - Visual Basic. ( .exe)
38 . ( , 1.13.) . Visual Basic . , - ! , - Visual Basic Windows, Windows -. - - , . - ( ) ( Microsoft Office). , - ( install ). , Microsoft Office, Microsoft Office, , Microsoft Office. ( - Setup.exe) . . . , , Microsoft Office. Microsoft Office . Windows Microsoft Office. Microsoft Office "" Windows. , , , , , , - , . "". - - ( CD-RW - -) , .
-
.FileName = "c:\Windows\Media\Canyon.mid"
Form1.Picture = LoadPicture("C:\Program Files\Microsoft Office\Clipart\Popular\Agree.wmf") , - . , , -, , , ? . , . : , , Project1.vbp Form1.frm. " ". . "c:\\". :
.FileName = " c:\\\Canyon.mid" Form1.Picture = LoadPicture("c:\\\Agree.wmf")
. - , . . Visual Basic . , Canyon.mid Agree.wmf . :
App, - - , , Path "c:\\". , , , . , Windows, Icon . Project1.vbp, , , .vbp.
.FileName = App.Path & "\Canyon.mid" Form1.Picture = LoadPicture (App.Path & "\Agree.wmf")
- Make Project (.exe) , , , 1.13. : FileMake Project1.exe . , ( ) . , . Make Project Options Compile , Compile to Native Code. Advanced Optimizatons , .
- Visual Basic Windows. ( ) Package & Deployment Wizard, Visual Ba-
39 sic. Windows. Visual Basic. , . , . Next. Back. Package & Deployment Wizard. Browse .vbp Package. Package Type. Package Type. . . . Next. - Package
Folder. Package Folder. , . , Package . , New Folder. , Next. , Package. Yes. : Included Files. , . , , . Add. , Files of type All Files. Open. . . Next. Cab Options. CAB-. , , - (Multiple cabs) (Single cab). , Multiple cabs . CAB- , . CAB-, Single cab. Next. Installation Title. , . Next. Start Menu Items. Windows - . . Next. Install Locations. Next. Shared Files. Next. Finished!. Finish. . , . . . Windows, . Package. . CAB-, , , . CAB- Setup.exe SETUP.LST. , Support, Package. Support . , Package Support! .
- . . Setup.exe. , Setup.exe , . OK. Directory , . , Change Directory . Directory, . Windows. Continue. . . . , , , . , Setup.exe. , , (, Setup.exe) . , .
40
II. Visual Basic " !" - , . . . . , . , . - . - ""? , . , , - , , . - -, . ? , , . . - , , , , . , - . , ! , , . , : , , , , , " " "". - , ?! , , , , - , , , - , !
41
.0 Visual Basic - , , Visual Basic. - . , . ?
0.1. . . 130 . : r=130. 160 , r=160. , r . . 130 160 r. . . . , , - . , Visual Basic? , . , . , , 6, =6. =6 . , 6. =6 , . :
Let a = 6 " a = 6". I. ,
Form1.BackColor = vbRed "" "". , , , . , . a=2*3+4 b=a y=a+b+1 , a 10, b 10, y 21. , . , , , . Visual Basic , . , , . 2*3+4, a, a+b+1. . . . - . , , . ,
Y = a + b + Form1.Width. , . ,
Form1.Width = a + b + y . : v = -2+10 : h = 10*v : s = v+h+0.01 t = 0 : n = 2*t+40 : z = -n v - 8 h - 80 s - 88.01 t - 0 n - 40 z - -40
6:
, t : k=1+2 : s=2*k : t=6-s ?
42 , , Visual Basic " ". , , . ? : t = 0 : n = 2*t+40 : z = -n : Text1.Text=z z, -40, . , Debug.Print.
Debug.Print
t, n, z
. , Immediate. . . , . , : Private Sub Command1_Click() a=2*3+4 b=a y=a+b+1 Debug.Print a, b, y, b + y End Sub . Command1 - Immediate 4 : 10 10 21 31 Immediate? , - ViewImmediate Window.
? , . , : a=27018, b=3954. (, - ). . : Private Sub Command1_Click() a = 27018 b = 3954 S=a*b ' p=2*a+2*b ' Debug.Print S, p End Sub Immediate : 106829172 61944 - , - . : S = 27018 * 3954 ' p = 2 * 27018 + 2 * 3954 ' . , .
, . =34, 34=. z=f-v+990 , f-v+990=z. . , , , , . , , , , . . . (, d+2d), . , , ( 3d). , , , , , . ( d). , (, y=a+b+1), , , ( a b). . : . . . =10 : y=a+b+1 . . . , b . , a+b+1 , b. -. "" , "" - b - ( , ), Visual Basic , b . . Visual Basic a = 27018. , , Visual Basic , :
43 'a = 27018 : 0 7908 , , a .
0.2. N M, : " M!", , , - , . , . , . . , : ", , - !", ! - . - . - . . Visual Basic , , , . . , Visual Basic:
InputBox - ? - . , - . - InputBox. - . a=27018 b=3954 . . , . . . : Private Sub Command1_Click() a = InputBox(" ") b = InputBox(" ") S=a*b p=2*a+2*b Debug.Print S, p End Sub , : a=27018 b=3954.
a = InputBox(" ")
:
. a , . , . Project1 , , :
a = InputBox(" ", " ")
:
44
, Visual Basic , . : . . . : : Private Sub Command1_Click() a = InputBox(" ") b = InputBox(" ") c = InputBox(" ") p=a+b+c Debug.Print p End Sub , - 2, 3, 4 ? 9 234! ? , , , Val. ? : Visual Basic InputBox ( , ) , , . , a, b, c, , , . - ! : Visual Basic , + , . , , . , , . , , , . : , , . - . ? . Visual Basic , * . ( Visual Basic) - , a, b, c . ! : - Visual Basic . Visual Basic , . , Val? , . ? , ? , Visual Basic , !
, , . : : Dim a As Integer Dim b As Integer Dim c As Integer Dim p As Integer Private Sub Command1_Click() a = InputBox(" ") b = InputBox(" ") c = InputBox(" ") p=a+b+c Debug.Print a, b, c, p End Sub Dim a As Integer : a Visual Basic a . , " a Integer". b, c, p. . , , 4.2. . . Dim a As Integer Dim b As Integer Dim c As Integer Dim p As Integer : Dim a As Integer, b As Integer, c As Integer, p As Integer :
45 Dim a, b, c, p As Integer Visual Basic .
Integer? . - 2,3. - , . . Visual Basic a 2. - 2,6. Visual Basic a 3. . , , . , . , . ! . : Dim a As Single Dim b As Single Dim c As Single Dim p As Single Private Sub Command1_Click() a = InputBox(" ") b = InputBox(" ") c = InputBox(" ") p=a+b+c Debug.Print a, b, c, p End Sub Dim a As Single : a Visual Basic a . - , (, 27,3908), . . , " a Single ". : Integer, Single " "? : , . - 0.5. Visual Basic , Visual Basic -. . - ! . - , , Visual Basic . - ToolsOptionsEditorRequire Variable Declaration. Option Explicit, . , " !" , , " - !" - Option Explicit. , , , " " . ! , Option Explicit. , : x=2 Debug.Print , 2, . . "", "". . "" ( , , ""). Visual Basic . Option Explicit . : Integer, Single Long, Double, Currency String Date Boolean Variant -0.2 -0.5 -0.7 -7.1 -7.3 -7.3 -0 -1.1 -1.2 -1.3 -1.3, 7
, ,
46 . , , . ( )? . - + , . . ? , . . . . 5 . . 1. ( ). . "" : , - , , , . , , . , , . , . . . , . , . Single , Integer. : Integer 2 , Single - 4 . , Single 4 , , .
, , " ", " ". , " ". : Dim a As Integer Dim b As Integer Dim y As Integer Private Sub Command1_Click() a = 10 : b = 6 : y = a + b + 1 Debug.Print y + 200 End Sub , . . : (, y=a+b+1), (a+b+1). ( a b ), ( 10 6, =10 b = 6), . (17) , , (y). , " , 2", " , , 2". , a,b,y . . =10. a 10. b= 6 b . y= a+b+1. , a b, 10 6, a+b+1, 17 y. Debug.Print y + 200. y, 17, 17+200 217 Immediate. : Immediate a b y a= 10 10 0 0 b= 6 10 6 0 y= a+b+1 10 6 17 Debug.Print y + 200 10 6 17 217 Debug.Print : Debug.Print , Visual Basic , , . .
47
7: , , b= 6
y= a+b+1?
. . - . , . , ( ), . , - , . . Start, , F8 . DebugStep Into. . , , Command1. . , , , , Private Sub Command1_Click(), . , - , , F8 . " ". , ? , , . , " ". F8. , . a = 10. F8. Visual Basic a = 10, . , a, b, y . F8. Visual Basic b = 6, . , a, b, y . , F8 Visual Basic , . , Visual Basic. : [design] [run]. Visual Basic [break]. , Visual Basic . , - . , . , , 3. F8, . . F8. Visual Basic y= a+b+1, . , a, b, y . F8. Visual Basic Debug.Print y + 200, . Immediate 217. F8. , . Command1. : , Immediate . F8 , , . , Immediate , , Visual Basic . . Visual Basic . , , Start, . F8 Start, Continue, .
, . : Dim k As Integer Private Sub Command1_Click() k = 10: Debug.Print k: k = 25: Debug.Print k: k = 4: Debug.Print k End Sub k: k k=10 10 Debug.Print k 10 k=25 25 Debug.Print k 25 k=4 4 Debug.Print k 4 Immediate 10 25 4
, k . , k=25 10 25. ? , . :
48 - , , , , - . 10 k 25, Debug.Print k 25. ( "" "Print" , , , . , , , .) k=4 25 , Debug.Print k . . ? Dim f As Integer Private Sub Command1_Click() f = 30: f = f + 4: Debug.Print f End Sub f=30 f 30. f=f+4 ? , - . , , f+4 , f , , 34. 34 , , , f. 30 . Debug.Print f 34. , f=f+4 f , , f 4. ? . .
8: , : a=100 : a=10*a+1 : Debug.Print a a=100 : a= -a : Debug.Print a a=10 : b=25 : a=b-a : b=a-b : Debug.Print a, b
0.3. , 1.4. (a, s, d ... ). , Visual Basic, . : a=3; Summa=3; b=4-a; ROBBY=4-Summa; Debug.Print a, b+50 Debug.Print Summa, ROBBY+50 3 51. , , , , Summa , 3. , , . . : , , , -. : a polnaja_Summmma tri_plus_dva s25 a1b88qqQQQQQQQQQQQQ oshibka __ : polnaja summa - (), , - (), , 2as - Domby&Son - & , , Visual Basic . , Summa sUmmA - . , ( ).
49
0.4. . , , - . . - , , , . , . Visual Basic : 2
+ 3 4 - 1 2 * 3 10 / 2 17 \ 52^3
5 3 6 5 3 2 8
(17 5, 3, 2) 2 3 ( ) -
17 Mod 5
ab+cd , : a b c d. Visual Basic : a*b+c*d. , , ab, , cd. , . , a * (b+c). . , , , a+1 b+ 1 . . Visual Basic : (a+1)/(b+1). , a+1/b+1, , , , , 1 b , a 1. : ? : , . . : Visual Basic :
1+ :
a 2 + ab b 3+ a
(1 + a / (2+a*b)) / (3+a) * b . . , . . , . " ", ( 3+a 2+a*b). , 1 + a / (2+a*b) , .. ? , , Visual Basic (1 + a / (2+a*b)) (3+a) (3+a) b. . : ((1 + a / (2+a*b)) / (3+a)) * b . . . , , Visual Basic, . : 62.8 - . , , InputBox Visual Basic , . ? Visual Basic, Windows, . . " " - , Visual Basic - , . . Visual Basic , , . , Visual Basic - Sqr. , 25 - Sqr(25), a+b Sqr(a+b). Sqr - Square root - . , , . Visual Basic:
50 Sqr (25) Round (5.82716) Round (5.82716, 3) Abs ( -20) Fix (3.98) Fix (-3.98) Int (3.98) Int (-3.98) Rnd . 1.4, 5.9. (2+1)^2 1+ (2+8)^3 1+Abs(5-8) 2^4+Sqr(35+1) Sqr (8+Int(41.5)) 21 \ (Round (2.54+1)) : 9 1001 4 22 7 5 5 6 5.827 20 3 -3 3 -4 0.73088 () ( ) , (0 - 1)
,
Sin, Cos, Tan ( ), Atn ( ), Exp, Log
9:
, : a = (2^2+1) * (20- (2^2)^2) - 11 : b=11 \ (a-4) : Debug.Print a^2 + b - 1
0.5. , , . . , . .
Integer Long - : Dim a As Integer Dim b As Integer Private Sub Command1_Click() a = 100 b=1 Debug.Print a, b, a + b End Sub . , . b=1 b=40000. Visual Basic "Overflow", " ". ? , Visual Basic , , Integer, . Integer . , b . - , - -32768 32767. , , Integer, Long ( ). Long 4 -2147483648 2147483647. Integer, Long? , , , .
10: =9000000 . b=1000 . . ? .
Single Double - : Dim a As Single Dim b As Single Private Sub Command1_Click() a = 100.78656954325 : b = 40000.1234567895 : End Sub . : 100,7866 40000,13 40100,91
Debug.Print a, b, a + b
51 , Visual Basic 7 . , 4 , Single, . , - Double - . Double 8 . Dim a As Double Dim b As Double Private Sub Command1_Click() a = 100.78656954325 : b = 40000.1234567895 : Debug.Print a, b, a + b End Sub . : 100,78656954325 40000,1234567895 40100,9100263327
- 15 . b, , b = 40000.12345678957453457, , Visual Basic , , . Single, Double?