277
1 С.Н.Лукин для начинающих © ______________________________________________________________________ 2001

Диалог-МИФИ - Visual Basic. Самоучитель для начинающих

Embed Size (px)

Citation preview

1

..

______________________________________________________________________

2001

2

0. _______________________________________________________________________ 80.1. ? ____________________________________________________________________ 8 0.2. , .____________________________________________________________________________________ 8 0.3. Visual Basic? _____________________________________________________________________________ 9 0.4. Visual Basic? _____________________________________________ 10 0.5. _____________________________________________________________ 10

I. _____________ 12 1. ______________________________________________________________________ 131.1. ? ___________________________________________________________________________ 13 1.2. , __________________________________________________________________________ 14 1.3. - __________________________________________________________________________ 14 Visual Basic_______________________________________________________________________ 14 _______________________________________________________________ 15 __________________________________________________________________________ 16 , , , ____________________________________________ 17 Visual Basic __________________________________________ 18

2. - "" ____________________________________________________________ 202.1. _______________________________________________________________________________ 20 2.2. ___________________________________________________________________________________ 20 2.3. ____________________________________________________________ 21 2.4. _______________________________________________________________________________ 21 2.5. . ____________________________________________________________________ 22 2.6. - _______________________________________________________________ 23 2.7. ___________________________________________________________________ 24 2.8. _______________________________________________________________________________ 24 ___________________________________________________________________________ 25 ___________________________________________________________________ 26 _________________________________________________________________ 26 2.9. ______________________________________________________________________________ 27 2.10. - MsgBox _____________________________________________________________________ 28 2.11. ____________________________________________________________________________ 28 2.12. ________________________________________________________________________________ 30 2.13. - _________________________________________________________________ 30 ______________________________________________________________________________ 30 ______________________________________________ 31 __________________________________________________ 31 __________________________________________ 31 ________________________________________________ 31

3. Visual Basic __________________________________________________________ 323.1. , ___________________________________________ 32 3.2. Visual Basic ________________________________________________________________________ 32 3.3. Visual Basic ________________________________________________________ 33 3.4. Visual Basic ______________________________________________________________ 33 3.5. . _______________________________________________ 33 3.6. Visual Basic__________________________________________________________________________ 35 3.7. Visual Basic _______________________________________________________________________ 36 _______________________________________________________________________ 37 3.8. _____________________________________________________ 37

II. Visual Basic ___ 40 4. _____________________________________________________________ 414.1. . _____________________________________________________ 41 4.2. _________________________________________________________________ 43 InputBox___________________________________________________________________________________ 43 _______________________________________________________________________________ 44 ______________________________________________________________ 45

3

_________________________________________________ 46 . ___________________________________ 46 4.3. _________________________________________________________________________________ 48 4.4. . ____________________________________________________ 48 4.5. ______________________________________________________________ 50 Integer Long - __________________________________________________________________ 50 Single Double - ____________________________________________________________ 50 ? Currency ______________________________________ 51 ___________________________________________ 51 ________________________________________________________________ 51 4.6. ________________________________________________ 52 4.7. __________________________________________________________________________ 54 4.8. Print ________________________________________________________ 55 4.9. __________________________________________________________________________ 56 4.10. _______________________________________________________ 57 4.11. ______________________________________________________________________________ 57

5. _______________________________________________________ 585.1. () ______________________________________________________________________ 58 5.2. If ______________________________________________ 58 5.3. If _________________________________________________________ 60 5.4. ____________________________________________________________________________ 61 5.5. If ______________________________________________________________________________ 62 5.6. ___________________________________________________________________ 64 5.7. If. __________________________________________ 64 If ____________________________________________________________________ 64 ________________________________________________________________________ 65 ______________________________________________________________________ 65 5.8. Select Case ____________________________________________________________________ 66 5.9. . __________________________________________________________________________ 68 ________________________________________________________ 68 ______________________________________________________________________ 69 _______________________________________________________________ 69 5.10. MsgBox ______________________________________________________________________________ 70

6. ___________________________________________________________ 726.1. GoTo. . _____________________________________________________________ 72 ________________________________________________________________ 74 6.2. If _____________________________________________________________________ 74 6.3. Do ____________________________________________________________________________ 75 Do . Loop _______________________________________________________________________ 75 Do . Loop While __________________________________________________________________ 76 Do . Loop Until __________________________________________________________________ 76 Do While . Loop __________________________________________________________________ 77 Do Until . Loop __________________________________________________________________ 77 Do ____________________________________________________ 78 Exit Do___________________________________________________________________________ 78 _________________________________________________________________ 79 6.4. For _____________________________________________________________________________ 79 Exit For __________________________________________________________________________ 80 6.5. _______________________________________________________________________________ 81

7. _______________________________________________________________ 827.1. . . _____________________________________________________________ 82 7.2. . . . _________________________________________________ 82

8. ___________________________________________________ 868.1. ___________________________________________________________ 86 8.2. ___________________________________________________________________________________ 86 8.3. ______________________________________________________________________________________ 87 8.4. ____________________________________________________________________________________ 88 8.5. ________________________________________________________ 89 8.6. ______________________________________________________________________________ 89 8.7. ____________________________________________________________________ 90

9. __________________________________________________________________________ 929.1. . , , _______________________________________________________ 92 9.2. ____________________________________________________________________________ 93

4

9.3. - Visual Basic _________________________________________ 94 ____________________________________________________________________ 94 ___________________________________________________________ 94 9.4. - Line Shape _____________________________________________________________ 96 9.5. . ZOrder ______________________________________________________ 96 9.6. Visual Basic ______________________________________________________________________________ 97 9.7. 3 - _________________________________________________ 98 Pset _______________________________________________________________________________ 100 Line _______________________________________________________________________________ 100 Circle _____________________________________________________________________________ 101 CurrentX, CurrentY, Step____________________________________________________________________ 101 Cls ________________________________________________________________________________ 102 Point ______________________________________________________________________________ 102 PaintPicture ________________________________________________________________________ 102 9.8. ____________________________________________________ 103 9.9. __________________________________________________ 105

10. ______________________________________________________________________ 10610.1. ___________________________________________________________ 106 10.2. Stop, End Exit Sub _____________________________________________________________ 108 10.3. ______________________________________________________________________ 110 10.4. ___________________________________________________________________________________ 111 10.5. _____________________________________________________________________ 111 __________________________________________________________________________ 113

11. , , ______________________________________________ 11511.1. Date ______________________________________________________________________________ 115 _______________________________________________ 116 11.2. ______________________________________________________________________________________ 117 ____________________________________________________________________________ 117 11.3. "-" ________________________________________________________________ 118 Boolean ________________________________________________________________ 121 __________________________________________________________________________ 121 ____________________________________________________ 124 ____________________________________________________________________ 126 11.4. ___________________________________________________________________________________ 127 ___________________________________________________ 127 __________________________________________________________________________ 127 "" _______________________________________________________________ 128 ______________________________________________________________________________ 128 _______________________________________________________________________ 129

12. ___________________________________________________ 13012.1. ______________________________________________________________________________ 130 MouseDown MouseUp_____________________________________________________________ 130 MouseMove _______________________________________________________________________ 131 _____________________________________________________________________________ 132 12.2. __________________________________________________________________________ 132 KeyDown KeyUp _________________________________________________________________ 132 12.3. - () _________________________________________________________________________ 133 12.4. _______________________________________________________________ 140

III. Visual Basic - __ 141 13. ________________________________________________________________________ 14213.1. ______________________________________________________________________ 142 13.2. _______________________________________________________ 142 13.3. ___________________________________________________________________________ 144 13.4. ________________________________________________________________________ 145 13.5. _______________________________________________ 145 13.6. _________________________________________________________________ 147

14. _____________________________________________________ 14914.1. Variant __________________________________________________________________________________ 149 14.2. __________________________________________________________________ 149 14.3. ___________________________________________________________________________________ 151 ____________________________________________________________________ 151 ________________________________________________________________________________ 152

5

14.4. (Frame) ________________________________________________________________________________ 153

15. ____________________________________________________________ 15415.1. (CheckBox) ___________________________________________________________________________ 154 15.2. (OptionButton) __________________________________________________________________ 155 15.3. (HScrollBar VScrollBar)_____________________________________________________ 156 15.4. Slider, ProgressBar _____________________________________________________________________________ 156 15.5. (ListBox) (ComboBox) ___________________________________________________ 157 (ListBox) ___________________________________________________________________________ 157 ComboBox ( " ") ________________________________________________ 157 ComboBox ( " Combo") _______________________________________________________ 158 ComboBox ( " Combo") ________________________________________________ 158 , ListBox ComboBox. __________________________ 158 15.6. ____________________________________________________ 159 MonthView DTPicker_____________________________________________________________ 159 UpDown __________________________________________________________________________________ 160 DriveListBox, DirListBox, FileListBox _________________________________________________ 160 RichTextBox _______________________________________________________________________________ 161 ListView TreeView ________________________________________________________________________ 161 (TabStrip) (StatusBar) _____________________________________________ 161 MSChart__________________________________________________________________________________ 161 PictureClip________________________________________________________________________________ 161 ImageCombo ______________________________________________________________________________ 161 MSComm _________________________________________________________________________________ 161

16. , , _________________________________________________ 16216.1. ______________________________________________________________________________________ 162 ASCII_____________________________________________________________________________ 163 16.2. ______________________________________________________________________________________ 163 16.3. Shell ________________________________________________________________________________ 167 16.4. . On Error ___________________________________________________________ 167

17. . _________________________________________ 16917.1. . __________________________________________________________________ 169 17.2. ________________________________________________________________________ 170 ___________________________________________________________________ 172 17.3. _______________________________________________________________________ 172 17.4. ____________________________________________________ 173 17.5. . ___________________________________________________________________________ 173 17.6. __________________________________________________________________________________ 175 17.7. , _______________________________________________________________ 176

18. , _______________________________________________ 17818.1. "" Windows____________________________________________________ 178 18.2. CommonDialog _____________________________________________________________ 178 Common Dialog ______________________ 179 18.3. Toolbar ___________________________________________________________________ 180 18.4. - " " _______________________________________________________________ 182

19. ____________________________________________ 18519.1. _________________________________________________________________ 185 19.2. _________________________________________________________________________________ 186 19.3. . Project Explorer._________________________________________________________ 186 _____________________________________________________________ 186 ____________________________________________________________ 187 19.4. ______________________________________________________________________________ 187 ________________________________________________________________ 187 __________________________________________________________________ 188 __________________________________________________________ 188 19.5. ___________________________________________________________________________________ 189 19.6. ______________________________________________________________________________ 190 19.7. ? _____________________________________________________________________ 190

20. ___________________________________________________________ 19320.1. - " " ______________________________________________________________ 193 20.2. "". ________________________________________________________________ 194 20.3. ________________________________________________________ 195 20.4. __________________________________________________________________________ 195 20.5. _____________________________________________________________________ 195

6

20.6. _______________________________________________________________________________ 196 - _________________________________________________________ 196 ____________________________________________________________ 196 20.7. . _________________________________________________________________ 199 20.8. ______________________________________________________________________________ 202 _________________________________________________________________________ 202 ________________________________________________________________ 202 , _________________________________________________________________ 203

21. Visual Basic ___________________________________________________________ 20421.1. , Web- HTML ________________________________________________ 204 21.2. Web- _______________________________________________________________________ 204 21.3. Web- _____________________________________________________________________ 205 21.4. _____________________________________________________________________ 207 21.5. __________________________________________________________________________ 209

22. Visual Basic ________________________________________________________ 21022.1. _______________________________________________________________________ 210 22.2. Visual Data Manager ____________________________________ 211 22.3. . Data DBGrid. SQL. _____________________________ 212

23. _____________________________________________________________________ 21523.1. Visual Basic_______________________________________________________ 215 ActiveX ___________________________________________________________________________________ 215 Windows API ______________________________________________________________________________ 215 - MDI ________________________________________________________ 215 OLE _____________________________________________________________________________________ 215 23.2. ________________________________________________________________ 215

1. __________________________________________________________ 218 24. ___________________________________ 21924.1. . . __________________________________________ 219 24.2. ____________________________________________________________ 220

25. __________________________________________________ 22125.1. . _______________________________________________ 221 25.2. ___________________________________________________________________ 222 25.3. . ? __________________________________________________ 222 25.4. ___________________________________________________ 223 25.5. ______________________________________________________________________ 223 25.6. _______________________________________ 225 25.7. ___________________________________________ 226 25.8. ____________________________________________________________ 226

26. __________________________________________________ 22926.1. ______________________________________________________________ 229 26.2. _______________________________________________________ 230 26.3. _____________________________________________________________ 231 26.4. ________________________________________________________________ 231 26.5. _________________________________________________________ 234

2. Windows. ______________ 236 Windows _________________________________________________________________________________ 236 . ____________________________________________ 236 Windows __________________________________________________________________ 236 ____________________________________________________________________________________ 237 ______________________________________________________________________ 238 ________________________________________________________________________________ 238 . (, ) ________________________________________ 239 ___________________________ 239 _____________________________________________________________ 239 _____________________________________________________________ 241 - _________________________________________ 242 , ________________________________________ 242 ________________________________________________________ 243

7

_________________________________________ 244 _______________________________________ 270 ____________________________________ 272

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 .

0.2. , . , . : , ,

9 , . . , , . , , , , , , . , . . - , - . , . , . , : "" "", : , , , : ( - , , ) - . . ( , , , -, , ) : ( ) : ( ) , , " " , : : - - " " - ( ) ( ),

, , . (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. , Visual Basic . .

11 , . .

. e-mail: [email protected]. www.learncomp.narod.ru.

12

I. , , , : " Visual Basic , ". , , . , . - . 1 Visual Basic. 2 , , . - Visual Basic. 3 " Visual Basic", Visual Basic.

13

1. Visual Basic. .

1.1. ? , , . 1 . , "" , , . Visual Basic, . , , , , . , . , .

, 1. 2. 3. "" 4. "" 5. 6. "" 7. 8. 9. 1. 2. , , 3. , 4. 1 5. , 1. 2. 3. .. "" 1. .. 2. ... 1. 2. 3. .. .. ... , 1. 2. .. , 1. , - 2. ..

14

, - . - . " , ", - "". 9 . , "", . , " " " ". " ", , " ". . ""? " " , , " " " "? , , . ? , , , , , . , , . . , . , , . , . , , , - . , (, , , ), . , " , " , . Visual Basic . , , . . .

1.2. , , Visual Basic , . : , , , , , , .. , 3 : 1. , , .. 2. 2 , , ( , , ) . - . , : " - ", - - " - ". 3. , . - , , : . . , . , . . , , . 1 , , 2 , 3 . , , , - 1 - - , . . , , . , , .

1.3. - Visual Basic - - , , , , Visual Basic. . . . , , , , . - , . : " - " " - -". , , . , , - , . ! . , .

Visual Basic , , , Visual Basic. Visual Basic , 3.2, , , , 3.4. Visual Basic, - (. ). , File, Add Project - . ( - FileAdd project).

15

, . . New Standard EXE, Open. , , ( ):

, , . . - ? . , - , , . , Windows. . , . . 1 . , : , .. , - Visual Basic . Visual Basic . Toolbox ( ), , Visual Basic. , , , . - , , . Toolbox , . : "" Visual Basic , , , .

, . (CommandButton) . ,

16 "". ""? - , , , "" . "". . 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 . = Visual Basic . , , - ? . , [design]. Command1. -

17 - . , (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, 3.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 : Project - No Open

Projects. File Open Project File New Project. , , Visual Basic . File Open Project File New Project File Add project, Visual Basic

18 . , Project Explorer. , , . , File Remove Project, , Visual Basic . , , , , . . . . , 3.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 - " ". : Private Sub Command1_Click() Form1.BackColor = vbRed Text1.FontSize = 16 Text1.Text = " " End Sub , . . :

19

- Command2. (vbYellow), 12, " " , Command1, Command2 . , , - , Command2. . :

. . , 1.1. , . , Form1. , . - : , . ("..", " , "). - " , ". - " ", "", - .

?, . ? , - , , . . , . . Toolbox Image () - , , , .. . - . , , . , . , , , , . Visual Basic . , Timer, " ". Toolbox . . , Microsoft Multimedia Control 6.0, , . Visual Basic.

20

2. "" Visual Basic. , Visual Basic. . Visual Basic. . -, , . , , , " " , .

2.1. 1 , Visual Basic. - . , Windows. , Windows ( Visual Basic), : . - Microsoft ? , , , , , "". , ( ):

- , .

2.2. . :

21

, .

2.3. , BackColor, FontSize, Text. . [run] , (, Form1.BackColor = vbRed). , [design]. , ( , !). [design]? . Command1. . , , . (. 1.3). , , . : . ( alphabetic) ( categorized). - Command1. Width (), - . , , 200. , . [run], Command1.Width = 200. - . , . - . - . , - . . .

2.4. (Name). (Caption). . , . , Visual Basic ( - ) , , , , . . . (Name) - . , - Form1. , , . . ? . , , , , . ( ), (). . (Caption). - - Form1. - . . , . ? , ,

.Width=6000- ,

Form1.Width=6000 . Command1 _.

! , , . , .

22 . 4.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. , ! , . .

2.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 , . - 1.Text 2.Text, - Val(1.Text) Val(2.Text). Val - Value - , . :

.Text = Val(1.Text) + Val(2.Text), Visual Basic , . . . , . . : Private Sub __Click()

23 .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 . 5.9. . : . , . . : 1.Text = "". . , .

1 2

2.6. - . , . , -. , , , , [run]. : . " " , , - . - . , - . - . - ", !" BackColor ( ) - . . . - . Palette () . ForeColor ( , ). Appearance ( ) - 3D () Flat (). BorderStyle ( ). 6 , , , [run]. ToolTipText ( ). , , , Windows, Word, - , , , . ToolTipText. . . . . MouseIcon, MousePointer ( , ). . MousePointer 2 (). . . . , , . MousePointer 16 . MouseIcon . MousePointer 99. MouseIcon Windows\Cursors Cursors Icons, Graphics, , Visual Basic. ? , . - . .

24

. MaxButton ( - ). - True (). False (), . MinButton ( - ). - True (). False (), . Moveable ( ). False , [run] . . WindowState , : 0 - , 1 - ( Windows) 2 - ( ). Visible (). - True (). False (), . . Enabled ( ). - True. False, , . - . Alignment. , . MultiLine. True, , . ScrollBars, .

2.7. , - . , . , , - , , Paint. . Picture. . . Open - . (.9.3). Microsoft Office, Clipart . , - PictureBox Image - . ( Style Graphical).

2.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. . . (, ). , . [run], , : Properties Controls . , , Visual Basic : .DeviceType = "Sequencer" .FileName = "c:\Windows\Media\Canyon.mid" .Command = "Open" .Command = "Play" : (DeviceType) , . mid, rmi Sequencer. wav,

25

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-. , : 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"

26 .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 . . , . , "", .

Form1.Picture = LoadPicture("C:\Program Files\Microsoft Office\Clipart\Popular\Agree.wmf") LoadPicture . . , . , , , . (Label)

Label1.Caption = " - . 1970 ." - ? , .

.Command = "Play" .Command = "Close" , , . : .Command = "Close" .FileName = "c:\Windows\Media\Canyon.mid" .Command = "Open" .Command = "Play" "Close" , . "Open" .

- : , , . " " . . , . . - CD-RW, -, . , . - , , , 3.8, . .

3: - " ". 4 " -":

27

2.9. , , , , , . . , , , . :

y x

:

x

y , . . , Visual Basic . , , . ? Left

Top. Left - . Top - . , . - , Left Top. : Visual Basic . . . Left, Top, Width ( ) Height ( ). , Width Height. , . Left Top , . :

Form1.Left = 2000 "" :

5: - " " " - !". , , .

28

2.10. - MsgBox - . , :

:

MsgBox (" !") , Form_Terminate. , . 5.10. , , , ?

2.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 2.8). "".

MsgBox (" 2000 ") , . Visual Basic , , . Visual Basic ( , 3.5). , .

2.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 , 2.8 , . . "" , Animation1.Stop, - Animation1.Close. 3 5 12,

Animation1.Play 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" , , . , .

2.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 , . , (. 3.8).

, 2.5. , , , ( . 5.9). (. 4.5 " ").

.

32

3. Visual Basic , . Visual Basic, Visual Basic, , Visual Basic .. , . , , . Visual Basic . , , Visual Basic, , . : 4.2 - 6.1 - 7 - 9.1 - . , , 14.4 - (Frame) 19.3 - . Project Explorer. 2. Windows. , , .

3.1. , , Visual Basic , . , : , , , Windows. , , . , , Visual Basic .

3.2. Visual Basic-, - . , , . , , . Visual Basic, (). , 3.8. , Visual Basic , , 3.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 5. 6. 7. . 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. . . -.

8. 9. 10. 11. 12.

13. 14. 15. 16.

3.3. Visual Basic(1) Visual Basic (2) , . (3) (4) ( Start F5). , 6 (5) ( . 7) 3 (6) . 3 .

3.4. Visual Basic Visual Basic . "" . Microsoft Visual Studio Microsoft Visual Basic. Visual Basic , Windows - Visual Basic File Exit.

3.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.

3.6. Visual Basic Visual Basic 6.0. , , . . . Visual Basic , , Windows: , , - . , . Windows, 2. , . 1.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 19.3. - , View , , . , , Window , . , Windows. : Form Layout - . Object Browser - . () Visual Basic. - , , TextBox, , , , (. 9.1), . , , , , , [run]. , SelText TextBox, , . Object Browser - , "" . Object Browser 9.1. Color Palette - . , "" "" Visual Basic. , , . , Tools Options Docking . "" . ,

36 , , Windows, - Visual Basic. , Windows.

3.7. Visual Basic . , . , , 19.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. (. 2.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 - , (. 7).

ProjectAdd Form- . - [run]. , . , [run] . , - , , . . 19.1. Remove Form - . Components. Controls, Toolbox . Insertable Objects, Windows. , Word, Microsoft Word Document . Toolbox Word. . Word , Visual Basic, Word , [run]. , .

FormatAlign, Make Same Size - , , , . , , . , Ctrl . Order. , . , . - , . , Bring to Front ( ) Send to Back ( ) Lock Controls. -

37 . , . . , .

Debug (. 7).

Run, Query, Diagram .

Tools Menu Editor, (. 2.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 - .

Add-Ins Visual Data Manager, . - 22.2.

Window Windows. . Split , , , .

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 . .

3.8. , , , , , . - Visual Basic. ( .exe) . ( , 2.13.) . Visual Basic . , - ! , - Visual Basic Windows, Windows -. - - , .

38 - ( ) ( 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 . :

.FileName = App.Path & "\Canyon.mid" Form1.Picture = LoadPicture (App.Path & "\Agree.wmf") App, - - , , Path "c:\\". , , , . , Windows, Icon . Project1.vbp, , , .vbp.

- , 2.13. : FileMake Project1.exe

Make Project (.exe) , , . , ( ) . , . Make Project Options Compile , Compile to Native Code. Advanced Optimizatons , .

- Visual Basic Windows. ( ) Package & Deployment Wizard, Visual Basic. Windows. Visual Basic. , . , . Next. Back. Package & Deployment Wizard. Browse .vbp Package. Package Type.

39 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

4. Visual Basic - , , Visual Basic. - . , . ?

4.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 t - 0 h - 80 n - 40 s - 88.01 z - -40

6:

, t : k=1+2 : s=2*k : t=6-s ?

, , Visual Basic

42 " ". , , . ? : 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 , : 'a = 27018 : 0 7908 , , a .

43

4.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(" ", " "):

, Visual Basic , . : . . . : : Private Sub Command1_Click() a = InputBox(" ") b = InputBox(" ")

44 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. . , , 17.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 : Dim a, b, c, p As Integer Visual Basic .

Integer? . - 2,3. - , . . Visual Basic a 2. 2,6. Visual Basic a 3. . , , . , . , . ! . :

45 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 " "? : , . - 4.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 -4.2 Long, Double, Currency -4.5 String -4.7 Date -11.1 Boolean -11.3 -11.3 - 13 Variant -14.1 -14.2 -14.3 -14.3, 20

, , . , , . ( )? . - + , . . ? , . . . . 5 . . 1. ( ). . "" : , - , , , . , , -

46 . , , . , . . . , . , . 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. : a= 10 b= 6 y= a+b+1 Debug.Print y + 200 a b y 10 10 10 10 0 6 6 6 0 0 17 17 Immediate

217

Debug.Print : Debug.Print , Visual Basic , , . .

7:

, , b= 6 y= a+b+1?

. . - . , . , ( ), . , - , . . Start, , F8 . DebugStep Into. . , , Command1. . , , , , Private Sub Command1_Click(), . , - , , F8 . " ".

47 , ? , , . , " ". 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 . , - . , . , , 7. 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=10 Debug.Print k k=25 Debug.Print k k=4 Debug.Print k k 10 10 25 25 4 4 Immediate 10 25 4

, k . , k=25 10 25. ? , . : - , , , , - . 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.

48 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

4.3. , 2.4. (a, s, d ... ). , Visual Basic, . : a=3; b=4-a; Summa=3; ROBBY=4-Summa; Debug.Print Summa, ROBBY+50

Debug.Print a, b+50

3 51. , , , , Summa , 3. , , . . : , , , -. : a polnaja_Summmma tri_plus_dva s25 a1b88qqQQQQQQQQQQQQ oshibka __ : polnaja summa - (), , - (), , 2as - Domby&Son - & , , Visual Basic . , Summa sUmmA - . , ( ).

4.4. . , , - . . - , , , . , . Visual Basic :

49 5 3 6 5 3 2 8 (17 5, 3, 2) 23

+ 3 4 - 1 2 * 3 10 / 2 17 \ 52 17 Mod 5 2^3

( ) -

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: Sqr (25) Round (5.82716) Round (5.82716, 3) Abs ( -20) Fix (3.98) Fix (-3.98) Int (3.98) Int (-3.98) Rnd 5 6 5.827 20 3 -3 3 -4 0.73088 () ( ) , (0 - 1)

, Sin, Cos, Tan ( ), Atn ( ), Exp, Log . 5.4, 9.9. :

50 (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

9:

, : Debug.Print a^2 + b - 1

a = (2^2+1) * (20- (2^2)^2) - 11 : b=11 \ (a-4) :

4.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 : Debug.Print a, b, a + b End Sub . : 100,7866 40000,13 40100,91 , 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 , , .

51 Single, Double? .

? Currency : Integer Long, Single Double ? . , , 4, , , 4.00000000000381. . , , . Visual Basic , . , . , , Long . Currency. 4 , . -900 000 000 000 000 900 000 000 000 000. : , , , - .

" , " Visual Basic - ? , a a = 123456789012345, a = 123456789012345#. , , Visual Basic , a Double. , ( String ): Integer Long Single Double String Currency

%

&

!

#

$

@

. Dim b As Double, , , b , b# b, , b# = 5 b=5. Visual Basic , . , . , . DefInt I - M, , , I, J, K, L, M, N, Integer. : DefLng, DefSng, DefDbl .

: Dim a As Double Dim b As Double Dim y As Double Private Sub Command1_Click() a = 2457642345034.78 : b = 0.00000000037645 : y = a / b : Debug.Print y End Sub , . , , - . . : 6,52846950467467E+21 ? , Visual Basic, , , , , , , (). . , - 10 21- . +21 1021. -, 21 - , 6528469504674670000000. , . , . , , ? +21 -21, 10-21, 1021, 21 , . , , , -. Debug.Print y Format(y, "0.0000"). Debug.Print Format(y, "0.0000"). , , 4 , Visual Basic . Visual Basic , . : 6528469504674670000000,0000 , -

52 .

.Text = Val(1.Text) / Val(2.Text)

.Text = Format(Val(1.Text) / Val(2.Text), "0.00000000000000000000") - , 20 , , " ", , , , , , .

, , " ". , . . , , " " - . , ,

= 1 + 2

.Text = Val(1.Text) + Val(2.Text), - ( ) . ( ), ( , ). : Dim 1 As Double ', 1 Dim 2 As Double ', 2 Dim As Double '-, _____________________________________________________________________________ Private Sub __Click() 1 = 1.Text ' 2 = 2.Text = 1 + 2 ' .Text = ' End Sub , ( ) , , - - . ! , , : 1. , , , , . , , . 2. , , . , For i=1 To 5, For i=1 To 10. 3. . , , . , , , - . , .

4.6. , , , .

: . , .

:1. . - . , , . , :

53 1. 2. 3. 4. 5. = = = + = = +

, . 2. . . , , , , , , ? ( ) , , Width ( ). ( , , , , - ). : S_ V S_ S_

3. , . , , - Double. : ' , ' ' Dim As Double ' Dim As Double ' Dim As Double ' Dim S_ As Double ' Dim V As Double ' Dim As Double ' Dim S_ As Double ' Dim S_ As Double ' 4. . , - , InputBox (4.2) - -. InputBox. : Private Sub Command1_Click() ' = InputBox(" ") = InputBox(" ") = InputBox(" ") 5. , , . ' S_ = * V = S_ * = 2 * + 2 * S_ = * S_ = 2 * S_ + S_ 6. . , " ". . , , , . 4.10 , . , Print, ( Debug.Print, Immediate): ' Print " ="; S_ Print " ="; V Print " ="; S_ End Sub , Print - , : " =" , - S_. Print. Debug.Print. 4.8.

54 . - ? , . , . - , , , , , - . . , . , . , AutoRedraw True.

11-13: : 11) 3 80 / 2 90 /. ( , ). , Debug.Print . 12) . , . : , , , , . InputBox, . . 13) . . 5 Print.

4.7. . , , . , , , ( ). : Dim a As Integer Dim b As String _____________________________ Private Sub Command1_Click() a = 98 Debug.Print a End Sub _____________________________ Private Sub Command2_Click() b = " !" Debug.Print b End Sub

. Dim a As Integer , a , a=98 a 98. Dim b As String , b () , , , , ! 2(*fD6:u . b =" !" b ! . Debug.Print b, b, ! , , . , . , a="!" : Debug.Print a : a="!" : a=" !" : Debug.Print a a ! ! ! : ! ! : a="" : Debug.Print a : a=a+a : Debug.Print a+a+a +" " + , a+a "" - a. :

55 a+a a+a+a +" " , , , , . , InputBox. . : Dim a As String Private Sub Command1_Click() a = InputBox(" - ") Debug.Print " "; a End Sub Debug.Print. , . , , , , , , Print:

4.8. Print , : Print Print 1 1 Print 1; 66 1 66 Print 1; -2; 3.14 1 -2 3.14 Print 1, -2, 3.14 1 -2 3.14 , , , . , , , , , . : Print 12345, 4, 67824, 240 12345 4 67824 240 Print 345, -94, 67, 240456 345 -94 67 240456 Print 45, 45678, 67, 0 45 45678 67 0 : Print 45; 45678, 67; 0 45 45678 67 0 ? , . ? . : Print 1+2 3 a = 88 : Print a 88 a = 88 : Print a+1 89 a = 88 : Print a+1, -1 89 87 - . . : Print "" Print "", "" , . Print ""; "" , , . . ? - "" : Print ""; " " "" . Visual Basic , , . , , , : Print "??:?()*):%*%;*_?::" ??:?()*):%*%;*_?:: Print "3+2" 3+2 Print "3+2="; 3+2 3+2=5 : a = "" : Print a a = "" : Print a+ , Print , , , . , .

, , - , , , Print 66 Print "". , , -

56 . , .

Print . , Ves. : Print " =" ; Ves ; "" = 35 , . , Mes. , . : Print " " ; Mes ; " ." . ? , : Print "" ; Mes ; " ." . , Print . Print , Print , - . : Print 1; 66, Print 2; 1 66 2 3 Print 3 4 Print 4; , , . . , , Debug.Print. , , Print, , , ( - ): Form1.CurrentX = 1000 99 1000 3000 Form1.CurrentY = 3000 . Print 99 Form1.CurrentX = 1000 Print 99 99 44 . Form1.CurrentX = 1000 . Print 44 Form1.FontSize = 20 Form1.FontName = "Arial" () Form1.FontBold = True (True - , False - ) Form1.FontItalic = True ( ) Form1.ForeColor = vbBlue Form1.FontUnderline = True Form1.FontStrikethru = True FontTransparent False, . Print - , , , .

4.9. , : : : : : : , , ? , . ? 16 ! 16 ! !

InputBox, Print. imya, - vozrast. : Dim imya As String Dim vozrast As Integer Private Sub Command1_Click() Print ", , ?" imya = InputBox(" ") Print " , "; imya; ". ?" vozrast = InputBox(" ") Print "! "; vozrast; "! !" End Sub , Print " , "; imya; ". ?" ? , .

57

, . , : : : : : : , , ? ! , ! . ? 100 ! 100 ! !

, . , . : : : : : : , , ? ! , !. ? -2 ! -2 ! !

4.10. , : Text1.Text = 2001 2001 Text1.Text = 3+2 5 Text1.Text = "" a = "" : Text1.Text = a , , Print, - , , , , . . Text1.Text = "" + " " , , 4.8? . . +. : Text1.Text = " " + Mes + " ." . . : Text1.Text = " =" + Ves + "" "Type mismatch" - . Visual Basic , " ". , , , ( ), . " =" "" , Ves - . , , . , 2.5 Val ( - )? ( - ). Str: Text1.Text = " =" + Str(Ves) + " " = 35 11.3 !!!! .

14: : , ( ) ( ). : 365 , 12 . - : Print . , : , , . 2R, R - .

4.11. , . -. - ? , . , , , . -- ? , : - , . - , .

58

5. () Visual Basic : If If Select Case Visual Basic .

5.1. () : , , , ? , , . . . , . , 3000 3200 . , 3000, , 3200 - . , , . , () , . : 1. 2. 3. 4. . < 3000, . > 3200, . .

2,3 - . , , - . : , , - , , , - .. - < 3000 > 3200. , : 1. ", - , ?" 2. . 3. "" "", " !", " !" 4. " - ?" 5. . 6. . . . . . . . . . . . . . . ............. ( , , ). . , . ? . , ( , ) ().

5.2. If , Visual Basic. : If "" "" Then "" "" Else "" "" :

59

If

a=28

Then

Print f

Else

k=44

:

a=28 f k 44. , , , a=28 , , Print f , k=44 . , , , , ( ). , If , - . , If. If, . 1. - 167 121. 2000, , . . : Dim a As Integer Dim b As Integer Dim y As Integer Private Sub Form_Load() a = 167 b = 121 y=a*b If y > 20000 Then Debug.Print " " _ Else Debug.Print " " Debug.Print y End Sub : 5 , Debug.Print y. 5 , . . , If y > 20000 Then Debug.Print " " , Debug.Print y. a = 167 a = 1 . , If y > 20000 Then Debug.Print " " , Debug.Print y. 2. - . - . a1 - , a2 - , bol - , V - . : 1

2

3

Dim a1 As Double Dim a2 As Double Private Sub Command1_Click() a1 = InputBox(" ") a2 = InputBox(" ") If a1 > a2 Then Debug.Print a1 * a1 * a1 Else Debug.Print a2 * a2 * a2 End Sub Dim a1 As Double Dim a2 As Double Dim V As Double Private Sub Command1_Click() a1 = InputBox(" ") a2 = InputBox(" ") If a1 > a2 Then V = a1 * a1 * a1 Else V = a2 * a2 * a2 Debug.Print V End Sub Dim a1 As Double Dim a2 As Double Dim bol As Double Private Sub Command1_Click() a1 = InputBox(" ") a2 = InputBox(" ") If a1 > a2 Then bol = a1 Else bol = a2 Debug.Print bol * bol * bol End Sub

. , . - . , .

60 , , if , - , . If Else. , If s= = < 6 Then p=p+1 Print p

18-20:18. . , , - . . 19. . , , , . : . : , . 26 5.7. 20. , , 100 - . , N ? , If, , . , , , . : Private Sub Command1_Click() If Form1.BackColor = vbRed Then MsgBox ("") Else MsgBox ("") End Sub

21:

, 200 .

5.4. , , . . : Private Sub Command1_Click() p = Rnd Debug.Print p End Sub : 0,7055475. 0 1. Rnd.

62 . : 0,7055475 0,533424 0,5795186 0,2895625 0,301948 . : 0,7055475 0,533424 0,5795186 0,2895625 0,301948 , , . -, , . ? Randomize: Private Sub Command1_Click() Randomize p = Rnd Debug.Print p End Sub . 0 20? - p = 20 * Rnd. 6 7? - p = 6 + Rnd. 200 210? - p = 200 + 10 * Rnd. 200 210? - p = Int(200 + 11 * Rnd). , 11, 10. , : Private Sub Command1_Click() t = 200 + 11 * Rnd p = Int(t) Debug.Print t, p End Sub , t p, , , .

22: " ". . . , . , 1 . ( , . , . k=k+1.) : , - Left Top. , "" . : , , - Form1.Width * Rnd. , . . 23: " ". . - 0 1. - . - "" " ". , 100 80. ? ! ! : 0 1. , 200 210.

5.5. If : a 4, b=3 Print b, - b=0, a=b+5 =0. If, : If a 4 Then b=3 : Print b Else b=0 : a=b+5 : =0 , Then Else , . , . ( ) If. : If a 4 Then b=3 Print b Else b=0 a=b+5

=0End If End If , If . Else . ,

63 If a 4 Then b=3 Print b End If If , . . : a. a100, " ". , . " ". : Private Sub Command1_Click() a = InputBox(" ") If a < 0 Then MsgBox (" ") ElseIf a = 0 Then MsgBox (" ") ElseIf a > 100 Then MsgBox (" ") Else Print a ^ 2 End If MsgBox (" !") End Sub ElseIf - " ". : a < 0, . a = 0, a > 100, If : (a < 0). , Visual Basic (a = 0) . , , Visual Basic , Then , , . , Visual Basic , Else. If:

If Then . [ ElseIf Then . ] .. [ Else . ] End If

ElseIf . Else, , . , , , If, , :

If Then ElseIf ( ) Then, ElseIf , , :

If Then ElseIf

24: , , : - "", - "", - "Hi", - "". , , . 25: , 4.9. , , . 17, : " ?" , " ". 17, -

64 - " ?" " ". , , : " !".

5.6. - - , . , . - , , . Private Sub Command1_Click() a = InputBox(" ") If a > 4 Then b=3 Print b Else b=0 a=b+5

=0End If b=5 MsgBox (" !") End Sub . , : =, If, b= MsgBox. , , . , ( - If), . , b=0, a=b+5 =0 If , , If. , , , , , , . , , , , . , , . , , , . , . , , : a=0: b=0: c=0: f=4 .

5.7. If. . . .

If If, Then Else Visual Basic, If. : ( - ). 28 30, , - . : . 28, , . ? : 30, , . : Private Sub Command1_Click() a = InputBox(" ") If a < 28 Then MsgBox (" ") Else If a < 30 Then MsgBox ("") Else MsgBox (" ") End If End Sub If a < 30 If a < 28. , . If: Private Sub Command1_Click() a = InputBox(" ") If a < 28 Then MsgBox (" ") ElseIf a < 30 Then MsgBox ("")

65 Else MsgBox (" ") End If End Sub

26: 19 5.3: . , , . : .

If , . Visual Basic , If If. . , . " ". - . . , , , , 140 . . : Dim Tsvet As String ' Dim Rost As Integer: ' Private Sub Command1_Click() Tsvet = InputBox(" ?") Rost = InputBox(" ") If Tsvet = "" And Rost < 140 Then Print " " Else Print " " End Sub , If , , , , And ( ""). If - 140 , , . And, , , . If , , . . , And - . - : Private Sub Command1_Click() a = InputBox(" ") If a > 28 And a < 30 Then MsgBox ("") Else MsgBox (" ") End Sub " ". . : If Tsvet ="" Or Rost0 Then . , c , . 1 , . . , , . , ? . . 2: 200 . , . : Private Sub Command2_Click() c=0 ' For i = 1 To 200 a = InputBox(" ") If a > 0 Then c = c + 1 Next i Debug.Print " -"; c End Sub : , . For 200 , . Debug.Print , ..

50:1) 2) 3) 4) 5)

, c=0 c=10. c=c+1 c=c+2. Next Debug.Print . c=0 For . For InputBox .

. . 3: 200 . , . : Private Sub Command3_Click() c_ = 0 ' c_ = 0 ' For i = 1 To 200 a = InputBox(" ") If a > 0 Then c_ = c_ + 1 If a = 0 Then c_ = c_ + 1 Next i Debug.Print " -"; c_, " -"; c_ End Sub , ""? , , . 4: . "/". , -

88 "W" ":" . : W - W, Dv - , i , "/". : Private Sub Command4_Click() Dim i As Integer, cW As Integer, cDv As Integer Dim procent_W As Integer, procent_Dv As Integer Dim simvol As String i = 0: cW = 0: cDv = 0 ' Do simvol = InputBox(" ") If simvol "/" Then i = i + 1 ' /, "" Select Case simvol Case "W" ' W, cW = cW + 1 ' W Case ":" ' : , cDv = cDv + 1 ' : Case "/" ' /, Exit Do ' End Select Loop procent_W = Round(100 * cW / i) ' W procent_Dv = Round(100 * cDv / i) ' : Debug.Print procent_W, procent_Dv End Sub

51: N . , , 10. 52: . , , 13. .

8.4. - , -. ? , , . , . , : s=0 ' . , m: a = InputBox(" ") s=s+a ' Debug.Print "="; s GoTo m s a, . , 1 c=c+1, - s=s+a. : N . . : Private Sub Command2_Click() N = InputBox(" ?") s=0 For i = 1 To N a = InputBox(" ") s=s+a Next i Debug.Print " "; s End Sub

53:1) 2) 3) 4) 5)

N=2, a=5 3. Visual Basic 8. , : s=0 s=10. s=s+a s=s+a+1. Next Debug.Print . s=0 For . For InputBox .

89 6) 7) s=s+a Next . For i=1 To N For i=2 To N.

54-56: : 54) 40 . . . 55) . 56) N . : , - , (?), .

8.5. Visual Basic , . 6.3, . , . , : Private Sub Command1_Click() For i = 1 To 5 a=9 If i * i = a Then For k = 5 To 8 Debug.Print k; Next k Else Debug.Print 1997 End If Next i End Sub For i = 1 To 5 If i * i = a , For k = 5 To 8. : 1997 1997 5 6 7 8 1997 1997

8.6. - . - . : 1*1= 1 1*2= 2*1= 2 2*2= 3*1= 3 3*2= 4*1= 4 4*2= 5*1= 5 5*2= 6*1= 6 6*2= 7*1= 7 7*2= 8*1= 8 8*2= 9*1= 9 9*2= 10*1= 10 10*2= 2 4 6 8 10 12 14 16 18 20 1*3= 2*3= 3*3= 4*3= 5*3= 6*3= 7*3= 8*3= 9*3= 10*3= 3 6 9 12 15 18 21 24 27 30 1*4= 2*4= 3*4= 4*4= 5*4= 6*4= 7*4= 8*4= 9*4= 10*4= 4 8 12 16 20 24 28 32 36 40 1*5= 2*5= 3*5= 4*5= 5*5= 6*5= 7*5= 8*5= 9*5= 10*5= 5 1*6= 10 2*6= 15 3*6= 20 4*6= 25 5*6= 30 6*6= 35 7*6= 40 8*6= 45 9*6= 50 10*6=1*1=1

6 12 18 24 30 36 42 48 54 60

1*7= 2*7= 3*7= 4*7= 5*7= 6*7= 7*7= 8*7= 9*7= 10*7=

7 14 21 28 35 42 49 56 63 70

1*8= 2*8= 3*8= 4*8= 5*8= 6*8= 7*8= 8*8= 9*8= 10*8=

8 1*9= 16 2*9= 24 3*9= 32 4*9= 40 5*9= 48 6*9= 56 7*9= 64 8*9= 72 9*9= 80 10*9=

9 1*10= 10 18 2*10= 20 27 3*10= 30 36 4*10= 40 45 5*10= 50 54 6*10= 60 63 7*10= 70 72 8*10= 80 81 9*10= 90 90 10*10= 100

- : 1 a=1 b=1 proizv = a * b Print a, "*" ,b, "=" ,proizv Print 5 : * a, * "*", * b, * "=",

90 * proizv

. :1*1= 1 1*2= 2 1*3= 3 1*4= 4 1*5= 5 1*6= 6 1*7= 7 1*8= 8 1*9= 9 1*10= 10

, 9 , 1. . , 9 1, b=1 . For: 2 a=1 For b = 1 To 10 proizv = a * b Print a; "*"; b; "="; proizv; Next b . - - , . 2 9 , - a. , 2 For , 1. 3 For a = 1 To 10 For b = 1 To 10 proizv = a * b Print a; "*"; b; "="; proizv; Next b Next a , 9 4. , , . Print, : 4 For a = 1 To 10 For b = 1 To 10 proizv = a * b Print a; "*"; b; "="; proizv; Next b Print Next a . , Print , . 4 . . . Print , . 14 . ( Font) Courier, . , , , , . 10 , - 100 , 10 .

57:1) 2) 3) 4) - 3 8, - 0 7. , 36, 44, 80. , 1,2,3. , 2123, 3312, 1111. . , , - 1123, 1223, 2222 .., 3322. .

8.7. : . : . : . -

91 . , . , , , , . : , , max. . ( chislo) max. , max . 10 : Private Sub Command1_Click() Max = InputBox(" ") ' - For i = 2 To 10 ' : chislo = InputBox(" ") ' If chislo > Max Then Max = chislo ' , , Next i Debug.Print Max ' End Sub

58: N . ? : . 59: . , , 40 .?

92

9. , . Visual Basic