untitled



Similar documents
VB程序设计教程

《Visual Basic程序设计》实验课

四川省普通高等学校

2010年3月计算机等级考试四级网络工程师笔试

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>

Microsoft PowerPoint - OPVB1基本VB.ppt

untitled

Microsoft Word - 小心翼翼的二十一點N.doc

2

FY.DOC

untitled

穨ac3-3.PDF

SMM667.mps

MVB-1001.DOC

untitled

基于UML建模的管理管理信息系统项目案例导航——VB篇

untitled

VB控件教程大全

INTRODUCTION TO COM.DOC

Visual Basic D 3D

epub 94-3

Microsoft PowerPoint - Chapter5

ThreeDtunnel.doc

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

TwinCAT 1. TwinCAT TwinCAT PLC PLC IEC TwinCAT TwinCAT Masc

CC213

IsPostBack 2

2009年3月二级VB语言笔试真题

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

untitled

多層次傳銷與獎金系統

数据结构与算法 - Python基础

Microsoft Word - 第3章.doc

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

高 职 计 算 机 类 优 秀 教 材 书 目 * 序 号 书 号 (ISBN) 书 名 作 者 定 价 出 版 / 印 刷 日 期 ** 配 套 资 源 页 码 计 算 机 基 础 课 计 算 机 应 用 基 础 刘 升 贵 年 8 月

Microsoft Word - 01.DOC

Microsoft Word htm

C/C++ - 函数

概述

CHAPTER VC#

C/C++ - 字符输入输出和字符确认

epub83-1

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

科学计算的语言-FORTRAN95

<4D F736F F D DA5BFA6A1C476C1C92DBEC7ACECB8D5A8F728B57BB35D292E646F63>

全 国 高 等 职 业 教 育 规 划 教 材 21 世 纪 高 职 高 专 规 划 教 材 系 列 高 等 职 业 教 育 计 算 机 专 业 规 划 教 材 选 题 征 集 通 知 一 选 题 范 围 ( 不 仅 限 于 此 ) 选 题 方 向 选 题 名 计 算 机 基 础 计 算 机 应 用

untitled

全国计算机技术与软件专业技术资格(水平)考试

WinMDI 28

Microsoft Word - 專題製作研究報告書.doc

3 Driver do Microsoft Access (*.mdb) hisdata IFIX 1.4

untitled

SYSMAC-SCS Version 2


优合会计考点直击卷子之财经法规答案——第八套

untitled

Excel VBA Excel Visual Basic for Application

05 CHAPTER Information.IsNumeric ( ) Information.IsDate ( ) True False Date Date True False Y Y Information.IsArray ( ) True False Y Information.IsErr

coverage2.ppt

C/C++程序设计 - 字符串与格式化输入/输出

C/C++ - 文件IO

Ps22Pdf

Windows XP

提问袁小兵:

User’s Manual

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

單元5

Java

2 WF 1 T I P WF WF WF WF WF WF WF WF 2.1 WF WF WF WF WF WF

第三节 软件测试的过程与策略

Serial ATA ( Silicon Image SiI3114)...2 (1) SATA... 2 (2) B I O S S A T A... 3 (3) RAID BIOS RAID... 5 (4) S A T A... 8 (5) S A T A... 10

Microsoft Word 軟體設計第二部份範例試題_C++_ _1_.doc


ebook43-11

广西民族学院(下)

C/C++语言 - 运算符、表达式和语句

Microsoft Word - 13院21号.doc

Transcription:

Visual Basic

Visual Basic 7 Visual Basic Visual Basic CIP Visual Basic/. 2003 ISBN 7-302-07899-8... BASIC. TP312 44 CIP 2003 124777 http://www.tup.com.cn 100084 010-62770175 010-62776969 185 260 24.25 536 2004 1 1 2004 1 1 ISBN 7-302-07899-8/TP 5737 1 5000 35.00 1

2002 B Windows C QBasic FoxBASE+ Fortran Visual Basic Visual FoxPro PC

Visual Basic Fortran 2003 12 IV

1 2 3 4 5 6 7 8 2 5 6 10 10 9 DOS Windows OS/2 Macintosh Unix Linux 10 11 PC 12 CD-ROM (E-mail th_press@263.net) Visual Basic 100084 010 62791976/77 221 010 62788903 www.thjd.com.cn 15%

1994 1 2 3 4 Visual Basic 2003 12

1 Visual Basic...1 1.1 Visual Basic...1 1.1.1...1 1.1.2...3 1.2...4 1.2.1...4 1.2.2...6 1.3...6 1.3.1...6 1.3.2...8 1.4...10 1.4.1...10 1.4.2...12 1.5...13 1.6...13 2 Visual Basic...16 2.1...16 2.1.1...16 2.1.2...22 2.1.3...25 2.2...29 2.2.1...29 2.2.2...42 2.2.3...46 2.3...51 2.3.1...51 2.3.2...56 2.3.3...57 2.4...59

Visual Basic 2.5...59 3 Visual Basic...64 3.1 Visual Basic...64 3.1.1...64 3.1.2...66 3.1.3...69 3.2...70 3.2.1...70 3.2.2...73 3.2.3...75 3.3...81 3.3.1...81 3.3.2...86 3.3.3...87 3.4...89 3.4.1...89 3.4.2...94 3.4.3...99 3.5...104 3.5.1...104 3.5.2...113 3.5.3...116 3.6...127 3.6.1...127 3.6.2...132 3.6.3...135 3.7...142 3.8...144 4...151 4.1...151 4.1.1...151 4.1.2...153 4.1.3...158 4.2...161 4.2.1...161 4.2.2...163 VIII

4.2.3...166 4.3...169 4.3.1...169 4.3.2...174 4.3.3...175 4.4...176 4.5...177 5...184 5.1 Sub...184 5.1.1...184 5.1.2...190 5.1.3...192 5.2 Function...196 5.2.1...196 5.2.2...197 5.2.3...198 5.3...203 5.3.1...203 5.3.2...209 5.3.3...210 5.4...212 5.4.1...212 5.4.2...219 5.4.3...220 5.5...222 5.6...224 6...231 6.1...231 6.1.1...231 6.1.2...237 6.1.3...238 6.2...239 6.2.1...239 6.2.2...242 6.2.3...243 6.3 Visual Basic...243 IX

Visual Basic 6.3.1...243 6.3.2...246 6.3.3...247 6.4...248 6.5...249 7...252 7.1...252 7.1.1...252 7.1.2...253 7.1.3...254 7.2...255 7.2.1...255 7.2.2...257 7.2.3...257 7.3...258 7.3.1...258 7.3.2...262 7.3.3...264 7.4...267 7.4.1...267 7.4.2...269 7.4.3...270 7.5...274 7.5.1...274 7.5.2...278 7.5.3...280 7.6...281 7.6.1...281 7.6.2...283 7.6.3...284 7.7...285 7.8...286 A...290 B...295 X

C...306 D...311 E...342 F...368 XI

1 Visual Basic 1 Visual Basic 2 Visual Basic 3 1.1 Visual Basic 1.1.1 Visual Basic Microsoft MS-Windows BASIC BASIC Windows API DLL DDEOLE ODBC Visual Basic 1.0 Microsoft 1991 1992 1995 2.0 3.0 4.0 16 DOS MS-Windows 3.x 1997 5.0 1998 6.0 32 MS-Windows 9x/NT/2000 32 5.0 Microsoft Visual Basic Visual Basic Visual Basic 6.0 Microsoft Microsoft Visual Studio Visual Basic Windows Tab ActiveX Internet Crystal Report Writer

Visual Basic / Internet/Intranet Microsoft Visual Source Safe Visual Basic 1. Visual Basic Visual Basic 2. Visual Basic 4.0 OOP Visual Basic 3. Visual Basic Visual Basic Visual Basic 4. Visual Basic Visual Basic 5. Visual Basic MS-Access.mdb dbase FoxPro Paradox ODBC SQL Server Oracle SQL Visual Basic ActiveX ADO RDO Visual Basic 2

1 Visual Basic 1.1.2 1 Visual Basic 1 2 Visual Basic Visual Basic 1 2 2 Visual Basic 1 2 MS-Windows Visual Basic Microsoft MS-Windows Visual Basic 1 Microsoft 2 3 Visual Basic 1 MS-Access dbase FoxPro Paradox 2 SQL Server Oracle / MS-Access dbase FoxPro Visual Basic / SQL Server Oracle Visual Basic ODBC 1 2 ODBC 4 A Visual Basic B C++ C Java D Pascal Visual Basic C++ Java Pascal 3

Visual Basic D 5 4 A B C D D 6 GUI A C B D GUI Graphical User Interface B 1.2 1.2.1 Visual Basic 6.0 Microsoft Visual Basic 6.0 Microsoft Visual Basic 6.0 Microsoft Visual Basic 6.0 Visual Basic 6.0 Visual Basic vb60 vb6.exe Visual Basic 1-1 EXE Visual Basic IDE 1-2 Visual Basic MDI 1-2 SDI Visual Basic Visual Basic Visual Basic 4

1 Visual Basic 1-1 1-2 Visual Basic IDE Visual Basic Alt+Q Windows 5

Visual Basic 1.2.2 1 Visual Basic SDI Visual Basic MDI SDI Multiple Document Interface MDI MDI 2 Visual Basic 1 2 1 2 3 Visual Basic A Alt+Q B Del C Ctrl+Q D Ctrl+P Del Ctrl+P Ctrl+Q Alt+Q Visual Basic A 1.3 1.3.1 Visual Basic 1. 1-3 6

1 Visual Basic 1-Microsft Visual Basic 1 Visual Basic 3 Windows Word 13 / MS-Office 1 2 N Ctrl+N Ctrl N 3 F10 Alt 4 F10 Alt F 5<Alt+ > <Alt+F> 7

Visual Basic 6 Esc Alt 2. Visual Basic 4 1-4 1-5 1-4 1-5 / twip 1 inch=1440 twip 1.3.2 1 1-Microsft Visual Basic 8

1 Visual Basic 1 2 Visual Basic Visual Basic Standard EXE 3 1 2 3 Visual Basic Visual Basic 1 2 3 4 1 2 1 Esc 2 Alt 5 Visual Basic A F1 C F9 B F5 D F10 F1 F5 F9 F10 D 6 Visual Basic A B C D Visual Basic 3 Visual Basic D 9

Visual Basic 1.4 1.4.1 Visual Basic 1. 1-6 Form 1-6 1-7 / Name 1.vbp 2.vbg 3.frm 10

1 Visual Basic 4.bas 5.cls 6.res 1-7 2. 1-8 1-9 1-8 1-9 11

Visual Basic 1.4.2 1 Visual Basic 1 2 Visual Basic 1 2 2 1 2 Visual Basic Visual Basic 1 2 3 A Ctrl+D B Ctrl+E C Ctrl+F D Ctrl+G Ctrl+D Ctrl+E Ctrl+F Ctrl+G D 4 A B C Ctrl+T D F4 Ctrl+T Visual Basic C 5 / A Ctrl+T B Shift+F4 12

1 Visual Basic C Ctrl+J D F4 Ctrl+T Visual Basic Shift+F4 Ctrl+J / F4 D 1.5 Visual Basic Microsoft MS-Windows 1 Visual Basic 2 Visual Basic 3 Visual Basic IDE 1.6 1 Visual Basic A B C D 2 MSDN A Help B F10 C Esc D F1 3 ODBC A B C D 4 A Alt+Q B Shift+F4 13

Visual Basic C F4 D Ctrl+R 5 A F4 B Alt+Q C Shift+F4 D Ctrl+R 6 Dim vb vb="visual Basic 6.0" Debug. Print vb A True B False C Visual Basic 6.0 D "Visual Basic 6.0" 7 A inch B twip C cm D pixel 8 API A B C D 9 Visual Basic A B C D 10 Visual Basic A B C D 11 A F2 B Ctrl+F2 C F4 D Ctrl+F4 12 Visual Basic A ADO B DAO C DRO D RDO 13 4 A B C D 1 Visual Basic 1 2 4 3 14

1 Visual Basic 2 Visual Basic 1 2 3 1 2 4 4 Visual Basic 6.0 ActiveX 5 Visual Basic 6 Visual Basic 7 Visual Basic 1 2 8 1-Microsft Visual Basic 9 Visual Basic 1 2 3 15

2 Visual Basic 1 2 3 4 2.1 2.1.1 1. Visual Basic Visual Basic Visual Basic 1 2 3 F4 4 5 <Ctrl+PgDn> <Ctrl+PgUp>

2 Visual Basic 3 Caption Text Enable Alt+ Visual Basic print. 2. Windows 1 AutoRedraw True False BackColor ForeColor & BorderStyle 0-None 1-Fixed Single 2-Sizeable 3-Fixed Dialog 4-Fixed Tool Window 5-Sizeable ToolWindow 2 17

Visual Basic Caption ControlBox True False BorderStyle 0-None ControlBox True Enabled True False Font Height Width twip Icon.ICO MaxButton MinButton True False BorderStyle 0-None Name Visual Basic Picture Top Left Top Left Visible True False WindowState 0 1 2 2 Click DbClick Load UnLoad Activate Deactivate 18

2 Visual Basic Paint AutoRedraw True( 1) 3. Visual Basic 3 ActiveX OLE ActiveX Name Form1 Text1 Command1 4. 2 1 + 2-1 2-2 1 Ctrl 2 3 19

Visual Basic 2-1 2-2 2 2 1 8 2-2 20

2 Visual Basic Width Height Top Left twip Top Left Visual Basic Del 2 1 Shift 8 Shift 2 2-3 2-3 21

Visual Basic 5. Visual Basic Visual Basic 1 Paint AutoDraw True( 1) Resize 2 GotFocus LostFocus 3 Click DbClick MouseDown MouseUp MouseMove DragDrop DragOver 4 KeyDown KeyUp KeyPress 5 Change DropDown PathChange 6 Timer 2.1.2 1 Visual Basic 1 2 Visual Basic 22

2 Visual Basic 1 2 2 Visual Basic 3 1 2 3 Visual Basic ActiveX 3 ActiveX 1 ActiveX 2 3 3 Name 1 Visual Basic Name Name Form1 Name Text4 N Name CommandN Command1 4 A B ActiveX C D OLE OLE B 5 Visual Basic A Show B Hide C Load D UnLoand Show Hide Load UnLoad B 6 Visual Basic 23

Visual Basic A Name C Text B Caption D Enabled Name Caption Text Enabled A 7 A DragDrop B MouseDown C DbClick D Change DragDrop MouseDown DbClick Change D 8 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button=2 Then Print "AAAAA" End If Private Sub Form_MouseUp(Button As Integer,Shift As Integer,X As Single,Y As Single) Print "BBBBB" A AAAAA B BBBBB BBBBB AAAAA BBBBB BBBBB C AAAAA D BBBBB BBBBB BBBBB MouseDown MouseUp MouseDown MouseUp Button Button 1 Button 2 Form_MouseDown Button 2 IF AAAAA Form_MouseUp 24

2 Visual Basic BBBBB Button 1 IF BBBBB A 9 Option Base 1 Private Sub Form_KeyPress(KeyAscii As Integer) a = Array(237, 126, 87, 48, 498) t1 = a(1) t2 = 1 If KeyAscii = 13 Then For i = 2 To 5 If a(i) > t1 Then t1 = a(i) t2 = i End If Next i End If Print t1 Print t2 A 48 B 237 C 498 D 498 4 1 5 4 Option Base 1 1 KeyAscii = 13 13 KeyAscii = 13 a t1 t2 IF KeyAscii = 13 For a(2) a(3) a(4) a(5) t1 t1 t2 a() t1 t2 t1 t2 C 2.1.3 1 25

Visual Basic A F4 B Ctrl+PgDn C F5 D Ctrl+PgUp 2 Visible A True B False C 0 D 1 3 Visual Basic A Name B Caption C Text D Enabled 4 A Name B Visible C Text D Caption 5 A AutoRedraw B Enabled C MaxButton D BorderStyle 6 A Deactivate B Activate C Load D Click 7 A B C ActiveX D OLE 8 A DragOver B Change C DbClick D MouseDown 9 A B C D 10 Visual Basic A Show B Hide C Load D Unload 11 A Contro1Box False B Contro1Box True BorderStyle 1~5 C Contro1Box False BorderStyle 0 D Contro1Box True BoderStyle 0 26

2 Visual Basic 12 Visual Basic A Show B Load C Hide D Unload 13 A Unload B OnFocus C GetFocus D QueryUnload 14 Visual Basic A B ActiveX C D 15 Visual Basic A Shift+Ctrl B Shift+ C Ctrl+ D Ctrl+ 16 A Load B Unload C Resize D Paint 17 a=1:b=2:c=3 a=b:b=c:c=a Print a;b;c A 1 2 3 B 2 3 1 C 2 3 2 D 2 2 3 18 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Print "****" Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Print "####" 27

Visual Basic A **** B #### C **** D #### #### **** **** #### **** #### #### **** 19 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) FillColor = QBColor(Int(Rnd * 15)) FillStyle = Int(Rnd * 8) Circle (X, Y), 250 A B C D 20 A DragDrop C DbClick B MouseDown D DropDown 1 2 1 2 3 3 4 Visual Basic 1 2 5 Dim Msg As Integer Form1. 1 MsgBox "Form1 " Form1. 2 28

2 Visual Basic 2.2 2.2.1 1. 2-4 2-5 2-5 2-4 2-5 1 Caption Name Font Height Width Left Top Visible Enabled Alignment 0 1 2 AutoSize True BorderStyle 0 1 BackStyle 0 1 WordWrap AutoSize True WordWrap True WordWrap False 29

Visual Basic Click DbClick 2 MaxLength 0 32 768 MultiLine False True PasswordChar * ScrollBars 0 1 2 3 MultiLine True ScrollBars Text SelText SelLength SelStart 0 1 Locked True Click DbClick Change GotFocus LostFocus SetFocus Change Text GotFocus LostFocus SetFocus 2. 4 30

2 Visual Basic 1 2-6 2-7 Print 2-6 2-7 Name Enabled Visible Font AutoRedraw Top Left Height Width Picture none Visual Basic BitmapIconMetafile( ) JPEG GIF CurrentX CurrentY Stretch False Click DbClick Cls Print 2 1 Picture 31

Visual Basic Picture Picture 2 Windows.Picture=LoadPicture(" ") 3 2-8 2-8 Name Visible Height Width Top Left BorderColor BorderStyle 0~6 7 2-9 1~6 0 1 Solid 2 Dash 3 Dot 4 Dash-Dot 5 Dash-Dot-Dot 6 Inside Solid 7 Transparent 2-9 BorderStyle BorderWidth BorderStyle 6 32

2 Visual Basic BackStyle 0 1 BackColor FillStyle 0 Solid 1 Transparent 2 Horizontal Line 3 Vertical Line 4 Upward Diagonal 5 Downward Diagnoal 6 Cross 7 Diagnoal Cross FillColor FillStyle Shape 2-10 0~5 0 Rectangle 1 Square 2 Oval 3 Circle 4 Rounded Rectangle 5 Rounded Square 2-10 Shape X1 Y1 X2 Y2 X1 Y1 X2 Y2 33

Visual Basic 3. 2-11 Caption Name Enable Visible Font Height Width Top Left 2-11 Cancel True Esc Cancel True Default True Default True Style 0 1 Picture Style 1 DownPicture Style 1 Picture DisablePicture Enabled False Style 1 Click DbClick 4. Visual Basic 4 2-12 2-13 34 2-12

2 Visual Basic 2-13 Value True False 0 1 2 Alignment 0 1 Style 0 1 1 2-14 Picture DownPicture DisablePicture 35

Visual Basic 2-14 Click Click Click Columns 0 1 2-15 2-15 Columns List 0 n n 1 ListCount 36

2 Visual Basic ListIndex List 0 n n 1 1 MultiSelect 0-None 1-Simple 2-Extended Shift Ctrl ListIndex Text Selected List True False SelCount Sorted True False Style 0 1 Text AddItem.AddItem [, ] 0 Clear.RemoveItem.Clear RemoveItem.RemoveItem Click DbClick Click DbClick Text 37

Visual Basic Style 0 1 2 2-16 2-16 Style=0 Style=1 Style=2 0 1 2 Text Text Text Click DropDown Change Click DbClick Change Click DropDown AddItem RemoveItem Clear 5. 2-17 38

2 Visual Basic 2-18 2-18 Min Max Min Max 32 768 32 767 Min Max Min Max Value Min Max SmallChange Value LargeChange Value Scroll Change Scroll Value Change 6. 2-19 39

Visual Basic Visual Basic Enable True True False Interval 1/1000 65 535 56 Interval Timer Timer 7. 2-20 Enable False 2-20 2-21 40

2 Visual Basic Ctrl Caption Click DbClick 8. Tab SetFocus GetFocus LostFocus Enable Visible True Form_Load Show Tab Tab Tab Tab Tab Tab Tab TabStop TabIndex TabStop False Tab TabStop True TabStop False TabIndex Tab TabIndex TabIndex Tab Tab Tab Tab Tab Tab Tab 41

Visual Basic 2.2.2 1 1 2 3 Visual Basic Print 1 2 3 2 A Alignment B BorderStyle C Caption D Text Alignment BorderStyle Caption Text D 3 A GotFocus B LostFocus C SetFocus D Click GotFocus LostFocus Click SetFocus C 4 Visual Basic A Image C Frame B TextBox D CheckBox Frame TextBox Image CheckBox TextBox Image CheckBox C 42

2 Visual Basic 5 Text A Text1.Alignment=1 B Text1.Alignment=2 Text1.BorderStyle=0 Text1.BorderStyle=1 C Text1.Alignment=1 D Text1.Alignment=2 Text1.BorderStyle=1 Text1.BorderStyle=0 Alignment 0 1 2 BorderStyle 0 1 A 6 ComboBox A List B ListIndex C AddItem D Move ComboBox List ListIndex AddItem ComboBox ComboBox Move C 7 A Activate B Deactivate C LostFocus D Initialize Activate Deactivate LostFocus Initialize Form MDIForm User Property Page Webclass DHIML PageDesigner C 8Name Form1 Name Text1 Text2 Name Command1, m = Text1.Text + Text2.Text Print m Private Sub Form_Load() 43

Visual Basic Text1.Text = "" Text2.Text = "" Text1 Text2 123 456 A 579 B 123 456 C 123 456 D 456 123 Form_Load Command1_Click Text 123 456 123 456 + Text1.Text+Text2.Text 123 456 123 456 C 9 True A Value B Enabled C Cancel D Default Value Variant / Enabled Cancel Default B 10 Label1 A Label1.BackStyle=0 B Label1.BackStyle=1 Label1.BorderStyle=0 Label1.BorderStyle=1 C Label1.BackStyle=True D Label1.BackStyle=False Label1.BorderStyle=True Label1,BorderkStyle=False BackStyle 0 1 BorderStyle 0 1 True False A 11 Combo1 Command1 Combo1 44

2 Visual Basic m = InputBox(" 0 2 ") a = Combo1.List(m) Print a Private Sub Form_Load() Combo1.AddItem "12" Combo1.AddItem "34" Combo1.AddItem "56" 2 A 12 B 34 C 56 D 0 Combo1 Command1 Command1_Click Form_Load Combo1 AddItem Combo1.AddItem [ ] 0 Form_Load Combo1 AddItem Command1_Click InputBox 2 a=combo1.list(m) 2 0 2 3 a Print a 56 C 12 False A Enabled B Timer C Visible D Interval TimerEnable True Interval Interval 45

Visual Basic Timer Timer Visible A 13 picturefile.jpg Picture1 LoadPicture LoadPicture Picture1 Picture Picture1. Picture = LoadPrcture("picturefile.jpg") 2.2.3 1 A ScrollBars B BorderStyle C MaxLength D MultiLine 2 A Click B GotFocus C Change D LostFocus 3 A ScrollBars B SelText C PasswordChar D Text 4 A BackStyle B FillStyle C BorderStyle D Shape 5 A Shape B ScrollBars C BorderStyle D BackStyle 6 Esc A Enable B Visible C Cancel D Style 7 A Click B KeyUp 46

2 Visual Basic C DbClick D GotFocus 8 Picture DownPicture DisablePicture A B C D 9 A Click B DropDown C DbClick D Change 10 A B C D 11 A Scroll B MouseMove C Change D DragOver 12 A B C D 13 A B C D 14 A F4 B F3 C Tab D Alt+Tab 15 A SetFocus B Visible C Refresh D GetFocus 16 Command1 Label1 Command1 Click Dim a(3) As Single Dim p As String For n = 0 To 3 a(n) = Val(InputBox(" " & (n + 1) & " ")) Next p = a(0) & ";" & a(1) & ";" & a(2) & ";" & a(3) Label1.Caption = p 47

Visual Basic InputBox 1 2 3 4 A 1 2 3 4 B 1234 C 1 2 3 4 D 1;2;3;4 17 Name Text1 Tex12 Name Command1 x = 0 Do While x < 10 x = (x + 2) * (x + 3) n = n + 1 Loop Text1.Text = Str(n) Text2.Text = Str(x) A 1 0 B 2 72 C 3 50 D 4 168 18 Visual Basic A Show B Hide C Load D UnLoad 19 OptionButton Index 1 2 CommonDialog Private Sub Form_Load() Static FlagFormPainted As Integer If FlagFormPainted <> True Then Option1(1).Caption = "Color" Option1(2).Caption = "Font" Command1.Caption = "Show Dialog" FlagFormPainted = True End If If Option1(1).Value Then 48

2 Visual Basic CommonDialog1.ShowColor ElseIf Option1(2).Value Then CommonDialog1.Flags = cdlcfboth CommonDialog1.ShowFont End If A Color Font B Color Font C Color Font D Color 256 Font 20 Private Sub Form_Load() List1.AddItem "357" List1.AddItem "246" List1.AddItem "123" List1.AddItem "456" Text1.Text = "" Private Sub List1_DblClick() a = List1.Text Print a + Text1.Text 789 456 A 456 B 456 789 C 789 456 D 789 21 Name Combo1 Private Sub Form_Load() Combo1.Text = "1" For I = 1 To 10 Sum = Sum + I 49

Visual Basic Next I Combo1.Text = Sum A B Combo1 55 C Combo1 1 D Combo1 1 1 Visual Basic 1 2 2 Visual Basic 3 Visual Basic Value 1 2 3 4 Visual Basic 5 Timer1 Timer Timer1.lnterval=900 900 6 Name Command1 Command2 Command1 Command2 Command2 Command1 Private Sub Command2_Click() 1 Private Sub Form_Load() 2 7 Command1 ListBox 50 Dim n As Long

2 Visual Basic Dim L1 As Boolean, L2 As Boolean, L3 As Boolean List1.Clear For n = 1 To 100 L1 = n = n ^ 2 Mod 10 L2 = n = n ^ 2 Mod 100 L3 = n = n ^ 2 Mod 1000 If L1 Or L2 Or L3 Then List1.AddItem n End If Next ListBox1 2.3 2.3.1 Visual Basic 2 1. Visual Basic 6 Visual Basic Ctrl+E 51

Visual Basic 2-22 2-22 1 - & Alt+ Visual Basic Caption Name ID 0-None 1-Left 2-Middle 52

2 Visual Basic 3-Right 2 3. 4. 6 4 2-23 53

Visual Basic 2. 2-24 1.Enabled = True.Enabled = False 2 MS-Word \ MS-Word.Checked = True 54

2 Visual Basic.Checked = False 3 Visual Basic Alt+ & Copy o C&opy 3. MS-Word 4. Windows Visual Basic.PopupMenu [ Flags X Y BoldCommand] PopupMenu X Y Flags X Y 55

Visual Basic Flags=0 X Y Flags=4 X Y Flags=8 X Y BoldCommand Flags vbpopupmenuleftalign 0 X Y vbpopupmenucenteralign 4 X Y vbpopupmenurightalign 8 X Y Flags vbpopupmenuleftbutton 0 vbpopupmenurightbutton 8 Flags Or MouseDown If Button=2 Then PopupMenu 2.3.2 1 A Ctrl+E B C D Shift+Alt+M 3 Shift+Alt+M D 2 A % B * C & D # & & Alt Alt+S &S S & & && & 56

2 Visual Basic C 3 MenuItem A MenuItem. Enabled=False B MenuItem. Enabled=True C MenuItem. Visible=True D MenuItem. Visible=False Enabled True Visible True A 4 Visual Basic 1 Caption 2 Name Visual Basic Caption Name 1 2 5 Visual Basic Visual Basic - - 2.3.3 1 Menu1 A Menu1.Enabled =True B Menu1.Enabled = False C Menu1.Visible = True D Menu1.Visible = False 2 Menu1 A Menu1.Enabled =True B Menu1.Enabled = False C Menu1.Visible = True D Menu1.Visible = False 3 A Click B LostFocus C Change D GetFocus 4 A MouseDown B DragDrop C KeyDown D KeyPress 57

Visual Basic 5 Visual Basic A 4 B 6 C 8 D 10 6 A B C D 7 Menu1 A Menu1.Enabled =True B Menu1.Enabled = False C Menu1.Checked = True D Menu1. Checked = False 8 A B C D 9 A Enabled B Checked C PopupMenu D Menu 1 1 2 2 2 Visual Basic 3 1 2 4 Visual Basic 5 Visual Basic 6 Visual Basic 7 Visual Basic 58

2 Visual Basic 2.4 Visual Basic 1 Visual Basic Visual Basic 2 3 Visual Basic 3 Visual Basic Name Caption BorderStyle Enabled Visible AutoRedraw BackColor ForeColor Click DbClick Load UnLoad Activate Deactivate 4 Visual Basic 3 ActiveX ActiveX 5 6 7 8 9SetFocusGetFocus LostFocus 10 Tab Tab Tab 11 Visual Basic 2.5 1 Visual Basic BorderStyle 59

Visual Basic A 0-None B 1-Fixed Single C 2-Sizeable D 3-Fixed Dialog 2 Visual Basic A B Shift C Ctrl D Alt 3 Visual Basic A Click Show B Show C LostFocus D GotFocus 4 Visual Basic A Load B Unload C Show D Hide 5 A B C ActiveX D OLE 6 Visual Basic A KeyDown B KeyUp C KeyPress D Click 7 A SetFocus B LostFocus C GotFocus D Click 8 Text A Text1.Alignment=1 B Text1.Alignment=2 Text1.BorderStyle=0 Text1.BorderStyle=1 C Text1.Alignment=1 D Text1.Alignment=2 Text1.BorderStyle=1 Text1.BorderStyle=0 9 A Move B Change C Scroll D Getfocus 10 Label1 A Label1.BackStyle=0 B Label1.BackStyle=1 Label1.BorderStyle=0 Label1.BorderStyle=1 C Label1.BackStyle=0 D Label1.BackStyle=1 Label1.BorderStyle=1 Label1,BorderkStyle=0 11 Combo1 Command1 60

2 Visual Basic a = Combo1.List(1) Print a Private Sub Form_Load() Combo1.AddItem "12" Combo1.AddItem "34" Combo1.AddItem "56" A 12 B 34 C 56 D 0 12 A LostFocus B OutFocus C Lost D Fause 13 ListBox1 Dim a, i, msg msg = "Choose OK to add 100 items to your listbox." MsgBox msg For i = 1 To 100 a = "a: " & i List1.AddItem a Next i A AddItem 100 B AddItem 100 1~100 C AddItem 1~100 D AddItem 100 14 Label1 A Label1.Enabled = False B Label1.Enabled = True C Label1.Visible = True D Label1.Visible = False 15 Visual Basic ( ) A Shift+Ctrl B Shift+ C Ctrl+ D Ctrl+ 61

Visual Basic 16 Txt1 A Txt1.MultiLine=True B Txt1.MultiLine=True Txt1.ScrollBars=0 Txt1.ScrollBars=3 C Txt1.MultiLine=False D Txt1.MultiLine=False Txt1.ScrollBars=0 Txt1.ScrollBars=3 17 Value A Move B Change C Scroll D GotFocus 18 Form1 A Load Form1 B Form1.Show C Form1.Hide D Unload Form1 19 3 Command1 Command2 Command3 Command2.Enabled = False Command3.Visible = False A Command1 Command2 Command3 B Command1 Command2 Command3 C Command1 Command2 Command3 D Command1 Command2 Command3 20 Combo1 Chardonnay Fun_ Blanc Gewrztraminer Zinfandel Combo1 Private Sub Form_Load() Combo1.AddItem "Chardonnay" Combo1.AddItem "Fun_ Blanc" Combo1.AddItem "Gewrztraminer" Combo1.AddItem "Zinfandel" text1 A Text1.Text = Combo1.List(0) B Text1.Text = Combo1.List(1) C Text1.Text = Combo1.List(2) D Text1.Text = Combo1.List(3) 62

2 Visual Basic 21 PictureBox A Set Picture1.Picture = LoadPicture("c:\Win1.bmp",vbLPLarge, vblpcolor) B Picture1.Picture = LoadPicture("c:\Win1.bmp",vbLPLarge, vblpcolor) C Set Picture1.Pricture = LoadPicture D Priture1.Picture = LoadPicture 22 Visual Basic A & B * C $ D @ 23 Visual Basic A B C D 1 Visual Basic ActiveX 3 1 ActiveX 2 3 2 Name 3 Visual Basic 4 Visual Basic 1 2 3 5 Visual Basic Text 6 Save v 63

3 Visual Basic 1 Visual Basic 2 3 4 5 6 3.1 Visual Basic 3.1.1 1. Visual Basic Visual Basic 1 255 2 3 Visual Basic 4 Visual Basic 4.frm.bas.cls

3 Visual Basic.vbp 5 Visual Basic.exe 2. Visual Basic 1 2 3 F7 4 3-1 65

Visual Basic 3. Visual Basic Visual Basic 3 4. Visual Basic Visual Basic Visual Basic Visual Basic Visual Basic Windows Visual Basic.exe.EXE Visual Basic 3 Debug.Print 3.1.2 1 Visual Basic 4 1 2 3 4 Visual Basic 4.frm 66

3 Visual Basic.bas.cls.vbp 1.frm 2.bas 3.cls 4.vbp 2 Visual Basic 3 1 2 3 4 Visual Basic 3 1 2 3 4 3 Visual Basic 3 1 2 3 1 2 3 4 A B C Stop D Visual Basic 4 Stop B B 5 a = 10: b = 50 Rem Print a;b 67

Visual Basic ' Print b;a Print a; b A 10 50 50 10 10 50 B 10 50 C 10 50 50 10 D 50 10 REM [ ] ' [ ] Visual Basic REM ' B 6 A B F7 C D 4 F7 A A 7 a = 1: b = 2: c = 3 a = b: b = c: c = a Print c A 0 C 2 B 1 D 3 a = 1 b = 2 c = 3 a = b a = 2 b = 2 c = 3 b = c a = 1 b = 3 c = 3 c = a a = 2 b = 3 c = 2 c 68

3 Visual Basic 2 C 3.1.3 1 Visual Basic A.doc.txt B.com.exe C.vbp.frm D.bat.sys 2 x = "X" y = "Y" z = "Z" x = y: y = z: z = x Print x; y; z A YZY B Y Z Y C YZX D Y Z X 3 A My Documents B VB98 C \ D Windows 4 Visual Basic A.vbp B.bas C.frm D.cls 5.exe.exe A.frm B Visual Basic C D 6 69

Visual Basic a = 1 b = 2 a = b + a b = a b a = (a + b) / 2 b = a b Print "a=";a;";b=";b A a=1;b=2 C a=3;b=1 B a=2;b=1 D a=3;b= 1 1 1 2 2 Visual Basic REM 3 Visual Basic Visual Basic 1 2 Visual Basic 3 4 5 4 Visual Basic 3 1 2 3 4 5 3.2 3.2.1 1. 1 Integer 16 32 768 +32 767 Long 32 2 147 483 648 70

3 Visual Basic +2 147 483 647 Float 1 234.56 1.234 56E+3 1.234 56 10 3 1.234 56 3 32 1 23 8 1 1.401 298e 45 3.402 823e+38 3.402 823e+38 1.401 298e 45 Double 64 1 52 11 1 d e 4.940 65d 324 1.797 693 134 862 316d+308 1.797 693 134 862 316d+308 4.940 65d 324 2 String ASCII Visual Basic ASCII 0 Visual Basic 0 2 16 0 2 31 3Currency 64 4 922 337 203 685 477.5808 +922 337 203 685 477.580 7 4Variant Visual Basic 5Byte 8 0~255 6Boolean 7Date 8 64 100 1 1 9999 12 31 0:00:00 23:59:59 mm/dd/yy hh:mm:ss # 8Object 4 71

Visual Basic 9 Decimal Decimal 12 0 28 10 Decimal 0 +/ 79 228 162 514 264 337 593 543 950 335 28 28 +/ 7.922 816 251 426 433 759 354 395 033 5 10 28 Visual Basic Decimal Decimal 2. Visual Basic Type Type As As End Type Type GuestInfo FirstName As String*10 LastName As String*10 Age As Integer End Type GuestInfo FirstName LastName Age FirstName LastName Age * FirstName As String*10 72

3 Visual Basic Type Public Private Type Private 3. 1~12 ~ [Public Private] Enum [=] [=] End Enum Public Enum Days Sunday = 0 Monday = 1 Tueday = 2 Wednesday = 3 Thursday = 4 Friday = 5 Saturday = 6 End Enum 0 1 2 Long Visual Basic workday = Days.Saturday 1 Enum Public Private 3.2.2 1 Visual Basic ASCII 73

Visual Basic 0 1 2 0 2 16 3 0 2 31 ASCII Visual Basic ASCII 0 Visual Basic 0 2 16 0 2 31 1 2 3 2 Visual Basic A Double B Boolean C Integer D Variant Integer 16 Double 64 Boolean Variant Visual Basic D 3 Double A 2 C 8 B 4 D 16 Double 64 8 C 4 DateTime Date A DateTime="5/12/03" B DateTime=September 1, 2003 C DateTime=#12:15:30 AM# D DateTime=("8/8/99") Visual Basic # B C 5 A B Type Public C Type Public Private D 74

3 Visual Basic Type Public Private Type Private * C 6 Public Enum WeekDays Sunday = 0 Monday Tuesday Wednesday Thursday Friday Saturday Invalid = -1 End Enum Dim myday As WeekDays myday = Saturday Print Val(myday) A Saturday B 6 C false D 1 Monday Saturday WeekDays =[] 1 0 1 2 2 Sunday 0 1 Saturday 6 B 3.2.3 1 75

Visual Basic Dim b As Single b = 2# / 3 Print b A 0.666 666 666 666 667 B 1 C 0 D 0.666 666 7 2 Dim x As Single x = 0.00000055 Print x A 5.5E 7 B 5.5E 07 C 0.00000055 D.00000055 3 Public Enum Number One Two Three Four = 4 Five Six Seven End Enum Dim num1 As Number Dim num2 As Number num1 = Two num2 = Six Print Val(num1),Val(num2) A 1 6 B 2 6 C 1 5 D 2 5 4 76

3 Visual Basic Dim MyString As String Dim MyLen As Integer MyString = "Visual Basic 6.0" MyLen = Len(MyString) MsgBox MyLen A Visual Basic 6.0 B 14 C 16 D 18 5 a$ = "This is a book." b$ = "That is an apple." c$ = Left$(a$, 8) + Right$(b$, 9) Print c$ A This is a book. B This is an apple. C That is an apple. D That is a book. 6 a$ = "AAAAAA" a$ = Mid$(a$, 2, 4) Print a$ Mid$(a$, 2, 2) = "aa" Print a$ A AaaA B AAAA C aaaa D aaaa AAAA AaaA aaaa AAAA 7 A Type B Enum C Public D Dim 8 77

Visual Basic Dim c As Long c = 1111 c& = 6666 Print c; c& A 1 111 6 666 B 1 111 1 111 C 6 666 1 111 D 6 666 6 666 9 Dim Index% A Dim Index As Long B Dim Index As Integer C Dim Index As Single D Dim Index As Double 10 Type Address Street As String * 20 ZipCode As String * 6 Phone As String * 8 End Type Dim MyHome As Address With MyHome Street = " " ZipCode = "100081" Phone = "62000000" End With Print MyHome.Phone A B 100 081 C 62 000 000 D 10 008 162 000 000 11 Type Person no As Integer name As String * 13 brith As Date salary As Single End Type Dim zhao As Person 78

3 Visual Basic A B C D 12 Public Enum StudentNames zhao qian= -1 sun li zhou wu = 10 zheng wang End Enum Dim name1 As StudentNames,name2 As StudentNames name1 = sun name2 = wang Print Val(name1), Val(name2) A 2 8 B 2 7 C 0 12 D 1 10 13 Visual Basic A Double B Variant C Integer D Default 1 Integer 2 Long 3 Visual Basic 89% 4 1 2 3 5 Enum Test num = 0 ab = 5 79

Visual Basic cd End Enum Test. cd 6 books no 40 name 20 score 10 brithdate Type books no As String*40 name As String*20 score1 1 brithdate 2 End Type 7 a = 12: b = 34.5: c$ = "a-b" s$ = c$ + "=" + Str$(a - b) Print s$ 8 name age wage Type student nam As String*12 age As Integer wage As Integer 80

3 Visual Basic 3.3 3.3.1 1. ASCII 65 535 32 768 32 767 &H &H1a &H0 &HFFFF &O &O37 &O0 &O177 777 2 147 483 648 2 147 483 647 &H & &H1a2b& &H0& &HFFFFFFFF& &O & &O3745& &O0& &O37 777 777 777& 10 1.23E4 1.23 10 4 =1230 E E D 4 922 337 203 685 477.580 8 +922 337 203 685 477.580 7 3.141 5 % &! # 81

Visual Basic @ $ Const = Const Visual Basic 2. Visual Basic 255 Visual Basic Visual Basic UserName 1 % 82

3 Visual Basic &! # @ $ 2 Declare As As Declare Dim Static Redim Public Private 1 Dim Dim Declare Dim Var1 As Integer String String * Dim Str1 As String Str1 Dim Str2 As String *10 Str2 10 Visual Basic Dim Var1 Dim Var1$ Dim Var1 As String Dim Dim Var1 As String Var2 As Integer Dim Var1 Var As String Var1 Var2 Static Redim Public Private 2 Static Dim Static Dim Static 3 Public 4 Redim 3 DefType DefType DefType Def Type Def 83

Visual Basic - DefInt A-C A B C Type 3.1 3.1 Type Type Int Lng Sng Dbl Cur Str Byte Bool Date Obj Var As DefType DefInt A Dim AdminName$ AdminName. MyData Type MyData DataID As Integer DataName As String *10 84

3 Visual Basic DataTime As Date End Type LastData MyData Static LastData As MyData LastData.DataID LastData.DataName LastData.DataTime 3. Visual Basic 3. Dim Private Private Public Public Global Dim Private 3.2 3.2 Dim Static Dim Private Public Global Visual Basic 85

Visual Basic IDE Option Explicit 3.3.2 1 Dim sum As Integer sum% = 10 sum = 3.2 Print sum%; sum A 10 3.2 B 10 10 C 3.2 3.2 D 3 3 Dim sum sum % sum sum% sum sum 10 sum 3.2 VB 3 Print sum D 2 Dim Index# A Dim Index As Long B Dim Index As Integer C Dim Index As Single D Dim Index As Double As % &! # @ $ D 3 A Dim B Public 86

3 Visual Basic C Static D Const Visual Basic Const Dim Static Public D 4 Dim Str1,Str2 As String *10 Str1 1 Str2 2 Str1 Str2 Str2 10 Str1 Visual Basic Dim Str1 Str1 1 2 5 Visual Basic 3 1 2 3 4 1 2 3 4 3.3.3 1 a% = 2/3 b% = 32/9 Print a%; b% A 1 4 B 0 3 87

Visual Basic C 1 3 D 0 4 2 A B C D Const 3 Visual Basic A 127 B 255 C 511 D 1 023 4 Visual Basic A B C D 5 A Dim B Public C Static D Const 6 Visual Basic A B C D 7 A Dim B Public C Static D Private 8 A dim B zh_1 C a.b D 12b 9 Dim MyVar MyVar="Hello World!" Debug. Print MyVar A True B False C Hello World! D " Hello World!" 88

3 Visual Basic 10 Visual Basic A Add B AddItem C AddString D AddObject 1 1 2 3 2 3 4 1 2 5 1 2 3 6 Const Const 1 2 3.4 3.4.1 1. Visual Basic 3.3 3.3 Int(x) Fix(x) Hex$(x) Oct$(x) Asc(x$) x x$ ASCII 89

Visual Basic Chr$(x) x ASCII Val(x$) x Str$(x) x Cint(x) x Ccur(x) x 4 Cdbl(x) x Clng(x) x Csng(x) x Cvar(x) x 3.4 3.4 Sin(x) x x Cos(x) x x Tan(x) x x Atn(x) x Abs(x) x Sgn(x) x x 1 0 0 +1 Sqr(x) x Exp(x) e x 3.5 3.5 Day(Now) WeekDay(Now) Month(Now) Year(Now) Hour(Now) 0~23 Minute(Now) Second(Now) 90

3 Visual Basic Now Rnd(x) 0 1 Randomize(x) 3.6 3.6 Ltrim$( ) Rtrim$( ) Trim$( ) Left$(,n) Right$(,n) Mid$(,p,n) Len( ) Sting$(n,ASCII ) Space$(n) Ucase$( ) Lcase$( ) InStr([,] 1 2[,n]) Mid$( [ L])= Tab n n p n n p n ASCII ASCII n 1 2 2 1 0 1 n n=0 n=1 n=2 1 2 0 2 1 2 Null Null L L $ ANSI B StrConv ANSI Unicode = StrConv 91

Visual Basic 64 ANSI Unicode 128 Unicode ANSI 2. Visual Basic 1 ^ x^y + x+y x y * x*y / x/y \ x\y x Mod x Mod y 2 Visual Basic + & A$+B$ A$&B$ B$ A$ 3 = <> >< < 92

3 Visual Basic > <= >= Like Is a<x<b ASCII ASCII Like Is Like SQL Is 4 Not And Or Xor Eqv Imp 3.7 3.7 X Y Not X X And Y X Or Y X Xor Y X Eqv Y X Imp Y Not And Or Xor Eqv Imp 1 0 93

Visual Basic 1 0 2 147 483 648~+2 147 483 647 * [ ]{ } 3.4.2 1 Visual Basic 1 2 3 1 2 3 2 Visual Basic 1 2 ASCII 3 1 Str$(x) 2 Val(x$) 3 Asc(x$) 3 a1 = "123" a2 = "123a" a3 = "12a3" a4 = "a123" Print Val(a1); Val(a2); Val(a3); Val(a4) 1 Visual Basic Val 0 1 123 123 12 0 4 C ASCII 67 94

3 Visual Basic ascii = 67: c = "C" Print Tab(10); c For i = 1 To 2 c = Chr(ascii - i) + c + Chr(ascii + i) Print Tab(10 - i); c Next i A C B A BCB BAB ABCBA CBABC C C D C BCD DCB ABCDE EDCBA Chr() Tab() Chr() ASCII Tab() C ASCII 67 C ASCII 68 69 c ASCII ASCII (ascii i) (ascii+i) c c Tab(10 i) c C 5 x = Sqr(2) + Sgn(2)+ Rnd(2) *10 y = Sqr(3) + Sgn(3) + Rnd(3) *10 If x > y Then Print "x>y" ElseIf x = y Then Print "x=y" Else Print "x<y" End If 95

Visual Basic A x>y C x<y B x=y D If Then Else end If x Sqr() Sgn() Rnd(3) Sqr() x Sgn(x) x Rnd(x) 0 1 y x y If Then Else end If x>y x>y x=y x=y x<y x y x y D 6 x = "12.34": y = "56.78" z = x + y p = Val(z) Print p A 12.34 B 56.78 C 69.12 D 12.345 6 x y z=x+y z 12.3456.78 Val() z pval() 2 D 7 Dim a As Single a = -1.234567 b = Int(a) c = Sgn(a) d = Abs(a) e = Fix(a) If a < b Then Print b; If a < c Then Print c; 96

3 Visual Basic If a < d Then Print d; If a < e Then Print e; Print A 2 1 1.234 567 1 B 2 1.234 567 C 1 1.234 567 1 D 1 1.234 567 1 Int(x) Sgn(x) Abs(x) Fix (x) Int(x) x Fix(x) x Int(x) Fix(x) x Int(x) Fix(x) 1 Abs(x) Sgn(x) a 1.234 567 Int(a) Sgn(a) Abs(a) Fix (a)2 1 1.234 567 1 b c d e IF THEN a b a c a d a e b c d 1 1.234 567 1 C 8 Visual Basic x=8 A B C D Visual Basic = x=8 = x=8 x=8 = x=8 B 9 Visual Basic A x=x+y B x+y>z C x=(x=y) D D 10 Sin30 Visual Basic A Sin30 B Sin(30) C SIN(30 ) D Sin(30*3.14/180) Sin() D 11 S 4 97

Visual Basic A Right(S,4) C RightStr(S) B Left(S,4) D RightStr() Right Rigth(, n) n Left Left(, n) n S 4 Right(S,4) A 12 S 6 4 A Mid(S, 6, 4) B Mid (S, 4, 6) C MidStr(S, 6, 4) D MidStr(S, 4, 6) Mid() Mid(,p,n) p n n p Visual Basic MidStr() S 6 4 Mid(S,6,4) A 13 A Len() B Length() C StrLen() D StrLength() Len()Len( ) Visual Basic B C D A 14 S 4 A Left (S,4) B Left(1,4) C LeftStr (S) D LeftStr (S,4) Left() Left(, n) n Visual Basic LeftStr() A 15 4 + 5 \ 6 * 7 Mod 8 / 9 A 4 B 5 C 6 D 7 98

3 Visual Basic ^ * / \ Mod +& A 3.4.3 1 For i = 1 To 4 x = 1 For j = 1 To 3 x = 2 For k = 1 To 2 x = x + 6 Next k Next j Next i Print x A 2 B 7 C 14 D 37 2 x = 0 Do Until x = -1 a = InputBox(" A ") a = Val(a) x = InputBox(" X ") x = Val(x) a = a * x Loop Print a 99

Visual Basic 12 10 15 1 A 120 C 15 3 x x + B 15 D 120 y + sin 2x Visual Basic y A SQR(x+y)/(x y)+sin(x*2) B SQR(x+y)/(x y)+sin(2x) C SQR((x+y)/(x y))+sin(x*2) D SQR((x+y)/(x y))+sin(2x) 4 a = 1234 b$ = Str(a) c = Len(b$) Print c A 4 B 5 C 6 D 7 5 a = 1.2 b = 345 c = Len(Str$(a) + Str$(b)) Text1.Text = c A 3 B 4 C 6 D 8 6 a = Text1.Text b = Text2.Text c = LCase(a) d = UCase(b) 100

3 Visual Basic Print c; d ABCD efgh A abcdefgh B abcddfgh C ABCDefgh D ABCDEFGH 7 a$ = "123" b$ = "456" c = Val(a) + Val(b) Print c A 123 B 456 C 123 456 D 579 8 0 A Int(5.4) + Int( 5.8) B CInt(5.4) + CInt( 5.8) C Fix(5.4) + Fix( 5.8) D Exp(5.4) + Exp( 5.8) 9 a$ = Text1.Text s$ = "" For k = 1 To Len(a$) s$ = UCase$(Mid$(a$, k, 1)) + s$ Next k fns$ = s$ Text1.Text = s$ A B C D 10 Fix(12) + Fix( 12.8) A 0 B 1 C 1 D True 101

Visual Basic 11 Fix( 45.6) + Int(12.3) A 33 B 33 C 34 D 57 12 a = "aaaaaa" b = Mid(a, 2, 4) Mid(a, 2, 4) = "AAA" Print a, b A aaaa aaaaaa B aaaaa aaaa C aaaaaa aaaa D aaaa aaaa 13 ^ / Mod * A ^ B / C Mod D * 14 Not Xor Or And A Not B Xor C Or D And 15 A B C D 16 Visual Basic A x=sgn(0) B x=sqr(0) C x=log(0) D x=sin(0) 17 a=8 <CR> b=9 <CR print a<b <CR> A 1 C False 18 Int(Rnd(0)*10) A 0,10 B 0 D True B 0,1 102

3 Visual Basic C 1,10 D 1,2 19 x 200 A x < 200 B x < 0 AND x > = 200 C x < 200 AND x > = 0 D 200 > x > = 0 206 <> 4 Or Not 2 * 5 A 0 B 1 C true D false 1 a$ = "1223458764" d$ = Left$(a$, 1) For I = 2 To Len(a$) z$ = Mid$(a$, I, 1) If z$ > d$ Then d$ = z$ Next I Print d$ 2 Int( Sqr(6.4)) 3 7 ^ 2 Mod 5 ^ 2 / 3 4 1/2 2x 3 +ln x 1 Visual Basic 5 (30 Mod 5 * 7 + 8) \ 12 + ll * (5 * 5 \ 12 / 2 ^ 2 + 3) 6 (Fix(32.4) + Int( 32.4) + Sgn(32.4)) 7 a$ = "Good morning!" b$ = "Even" c$ = Left$(a$, 5) + LCase$(b$) + Right$(a$, 4) Print c$ 103

Visual Basic 8 x Visual Basic 9 a B X 7 ASCII 10 2(1+ln3x) Visual Basic 11xyz + 123 + Abc 12 10 > (12 3) / 3 Or Not 6 <> 5 3 * 7 13 a$ = "12.3" b = "45.6" c = Val(a$) + Val(b) Print c 14 (a b)/(1+x*x Exp(x)) 15 a = 1.23 b$ = "1.23" c = Len(Str$(a) + b) Text1.Text = c 3.5 3.5.1 1. Visual Basic 1023 _ 104

3 Visual Basic Visual Basic 2 < > [ ] { }, 3 Visual Basic 3 1 [Let] = Let = 2 105

Visual Basic Rem ' _ 3 Stop Stop 4 End End End End End End Function End If If End Type End Select 4 If If Then 1 [Else 2] 1 2 1 2 Visual Basic 1 2 If If Then Else If Then Else Else If Then 106

3 Visual Basic 1 023 If 1 Then 1 [ElseIf 2 Then 2] [ElseIf 3 Then 3] [Else n] End If 1 1 1 2 2 1 2 3 3 ElseIf n 0 0 Then Visual Basic Then EndIf ElseIf ElseIf Visual Basic IIf IIf IIf(< > < 1> < 2>) IIf 1 IIf 2 IIf 107

Visual Basic 1 2 5 Visual Basic Select Case Select Case Case Select Case Case 1 1 [Case 2 [ 2]] [Case Else [ n]] End Select Select Case Else Select Case [ ] Case 1 2 5 To Case 1 To 5 Is Case Is=5 Case Is>10 And Is<20 Select Case Case Case Else Case Case Case 6 For Visual Basic 3 For Do 108

3 Visual Basic For For = To [Step ] [ ] [If Then Exit For] Next [ ][] Visual Basic Exit For Next For For Int / +1 For For For i = 1 To 5 For j = 1 To 10 Print i Next i Print j Next j For Next Next For Next Next 109

Visual Basic Exit For Exit For 7 While [ ] Wend While Wend Wend While 8 Do Do 1 Do [ ] [If Then Exit Do] Loop [While Until ] 2 Do [While Until ] [ ] [If Then Exit Do] Loop 110

3 Visual Basic Do Loop While Until Exit Do For Exit For While Until Do 1 Do While Until Do 2 While Until Do For 9 For i = 1 to 10 step 2 Text2.Text = i Next Do Counter = Counter +1 For i = 1 to Counter step 2 Text2.Text = i Next Loop Until Counter>100 111

Visual Basic Do Counter = Counter +1 For i = 1 to Counter step 2 Text2.Text = i While i<10 Print Counter Wend Next Loop Until Counter>100 Visual Basic Exit Exit For Exit Do 10 GoTo GoTo GoTo On-GoTo GoTo GoTo GoTo { } GoTo GoTo On-GoTo On GoTo On Counter+Number GoTo 200 50 100 Counter+Number 1 200 2 50 3 100 1 On-GoTo 112

3 Visual Basic GoTo Visual Basic GoTo GoTo On-GoTo 3.5.2 1 1 2 3 1 2 2 Visual Basic A B C D_ Visual Basic 1023 _ C 3 Visual Basic A For B Select Case C While D Do Visual Basic 3 For While Do For While Do Visual Basic Select Case B 4 Name Text1 Tex12 Name Command1 x = 1:n=0 Do While x < 100 x = x * 10 n = n + 1 Loop 113

Visual Basic Text1.Text = Str(n) Text2.Text = Str(x) A 10 0 B 2 100 C 3 50 D 4 168 Do While Loop While x < 100 x < 100 Do While x=10 n=1 Do While x=100 n=2 Str Text1.Text = Str(n) n Text1 B 5 x = 0 Do Until c = -1 a = InputBox(" A ") a = Val(a) b = InputBox(" B ") b = Val(b) c = InputBox(" C ") c = Val(c) a = a + b + c Loop Print a 5 4 3 2 1 1 A 2 B 3 C 14 D 15 Do Until Loop Until c = 1 c = 1 Do Until InputBox 114

3 Visual Basic 3 5 4 3 Val 3 12 a c = 1 2 1 1 a 2c = 1 A 6 For i = 1 To 2 For j = 1 To i For k = j To 6 a = a + 1 Next k Next j Next i Print a a A 6 C 17 B 14 D 32 For i = 1 To 2 j = 1 To ii = 1 i = 2 k = j To 6 j = 1 j = 2 1 i=1,j=1 k 6 a 6 2 i=2,j=1 k 6 a 12 3 i=2,j=2 k 5 a 17 C 7 Dim i For i = 1 To 10 Step 2 i = i + 1 Print i; Next i 115

Visual Basic A 2 4 6 8 10 12 B 1 3 5 7 9 11 C 2 5 8 D 2 5 8 11 For i Step 2 2 Print Print D 8 For Next A Exit B Exit For C Continue D Stop Loop For Next Exit For B 3.5.3 1 A Do While (condition) B Do Statements Statements Loop Loop While(condition) C Do Until(condition) D Do Until(condition) Statements Statements Loop End Do 2 Visual Basic A For Next B For Each Next C With End With D Do Loop 3 Click Cls Print For n = 1 To 6 Print Spc(1); "*"; Next n 116

3 Visual Basic Print A ****** B * * * * * * C * ** ** * D ** ** ** 4 WHILE A B C D 5 Do Until Loop A B C D 6 Private Sub form_click() Static sum As Integer i = 1 While i <= 10 sum = sum + i i = i + 1 Wend Print sum A 45 45 B 45 90 C 55 55 D 55 110 7 a = 0 For m = 1 To 10 a = a + 1 b = 0 For j = 1 To 10 117

Visual Basic a = a + 1 b = b + 2 Next j Next m Print a; b A 10 20 B 20 110 C 110 20 D 200 110 8 Visual Basic A GoTo B While Wend C For Next D On GoTo 9 a = 1 b = 1 For i = 1 To 3 a = a + b b = b + a Next i Print a; b A 2 3 B 5 8 C 13 21 D 34 55 10 A If a=3 And b=2 Then B If a=3 Then c=3 c=3 Else if a=2 Then c=2 End If C If a=3 Then D If a=3 Then c=3 c=2 ElseIf a=2 Then c=3 End If 11 118

3 Visual Basic a = 0 For i = 1 To 6 b = 0 For j = 1 To i a = a + 1 b = b + 2 Next j Next i Print a; b A 12 12 B 12 21 C 21 12 D 21 21 12 Dim a(3, 4) Static n As Integer For i = 1 To 3 For j = 1 To 4 n = n + 1 a(i, j) = n Next j Next i For i = 1 To 3 For j = 1 To 4 Print Tab(4 * j); a(i, j); Next j Print Next i A 1 2 3 4 B 13 14 15 16 5 6 7 8 17 18 19 20 9 10 11 12 21 22 23 24 C 1 2 3 4 D 1 2 3 4 5 6 7 8 5 6 7 8 9 10 11 12 9 10 11 12 119

Visual Basic 13 14 15 16 1 2 3 4 17 18 19 20 5 6 7 8 21 22 23 24 9 10 11 12 13 a = Text1.Text If a Mod 2 = 0 Then MsgBox " " Else MsgBox " " End If 23 A B C D 14 Function fact(n) s = 0 For k = 1 To n s = s + (k + 1) * k Next k fact = s End Function A N B 1 2 2 3 3 N N C 1 2 2 3 3 4 N 1 N D 1 2 3 N 15 Dim i, MyNum Do For i = 1 To 1000 MyNum = Int(Rnd * 1000) 120

3 Visual Basic Select Case MyNum Case 7: Exit For Case 29: Exit Do Case 54: Exit Sub End Select Next i Loop A 7 B DO 1 000 C 1 000 D 54 16 x = InputBox(x) If x Mod 3 = 0 Then y = x Mod 3 If x Mod 3 = 1 Then y = x Mod 3 If x Mod 3 = 2 Then y = x Mod 3 Print y 23 A 0 B 1 C 2 D 17 Sub ABC() Dim Number, MyString Number = InputBox(n) If Number = 1 Then GoTo L1 Else GoTo L2 L1: MyString = "Number = 1" Print MyString GoTo L3 L2: MyString = "Number < > 1" Print MyString L3: Print MyString 121

Visual Basic Call ABC InputBox 35 A Number 1 B Number <> 1 Number 1 Number <> 1 C Number 1 D Number <> 1 Number <> 1 Number 1 18 For j = 8 To 35 Step 3 Print j; Next j A 10 B 9 C 27 D 28 19 For i = 1 To 6 a = a + i Next i Print a A 10 C 21 20 B 15 D 28 s = 0 i = 1 While i <= 100 s = s + 1 122

3 Visual Basic Wend Print s A 125 C 21 B 512 D 100 a = 100 Do s = s + a a = a + 1 Loop While s < 120 Print a A 100 B 120 C 201 D 102 22 Name Text1 Private Sub Form_Load() Text1.Text = "" For i = 1 To 100 Sum = Sum + i Next i Text1.Text = Sum A Text1 5 050 B Text1 0 C Text1 D 23 Name Text1 Tex12 Name Command1 x = 1 Do While x < 50 123

Visual Basic x = x * 5 n = n + 1 Loop Text1.Text = Str(n) Text2.Text = Str(x) A 1 5 B 2 25 C 3 125 D 4 125 24 X 5 ABCDEF SELECT CASE A Select Case X B Select Case X Case 10 To 1 Case Is >15,Is<5 Print "ABCDEF" Case "ABCDEF" End Select End Select C Select Case X D Select Case X Case Is > 5, 1,3 To 10 Case 1,3,Is>5 Print "ABCDEF" Print "ABCDEF" End Select End Select 25 a$ = "*": b$ = "$" + a$ For k = 1 To 3 x$ = String$(Len(a$) + k, b$) Next k Print b$; x$ A $*$$$$ C $*$*$* 26 3 B *$*$*$ D $$$$*$ If x=1 Then y=4 If x=2 Then y=5 If x=3 Then y=6 A If x=1 Then B If x=1 Then 124

3 Visual Basic y=4 y=4 ElseIf x =2 Then ElseIf x =2 Then y=5 y=5 Else: y =6 Else y=6 End If End If C If x=1 Then D If x=1 Then y=4 y=4 ElseIf x =2 Then =5 ElseIf x =2 Then End If y=6 End If 1 c = 1 Do Until c = 10 c = c - 1 Loop Print c 2 x = "A": y = "B": z = "C" For i = 1 To 2 x = y: y = z: z = x Next i Text1.Text = x + y + z 3 For i = 1 To 2 For j = 1 To i For k = j To 6 125

Visual Basic m = m + 1 Next k Next j Next i Print m 4 x = -1 While x < 5 x = x + 1: x = x * x Wend Print x 5 For a = 1 To 5 For b = 1 To 10 y = b For c = 1 To 6 x = x + 1 y = y + 1 Next c Next b Next a Text1.Text = y 6 x = 10: i = 1 z = Int(Rnd(Y) + 2) On z GoTo 10, 20, 30 i = i + 1 126

3 Visual Basic 10: i = i + 10 20: i = i + 20 30: i = i + 30 Print i 7 Sum = 1 For x = 1 To 10 Step 0.4 Sum = Sum + 1 Next x Print Sum Sum 86 + 9 / 3 * 5 Mod (2 / 3) 9 1~6 10 "This"+" is "+"a book." 11 Fix( 123.45) + Int(98.765) 3.6 3.6.1 1 Visual Basic S(n) S n S(1) S 1 m m S(n 1,n 2,,n m ) Visual Basic 127

Visual Basic 2 1 Visual Basic 4 4 4 Dim ReDim Static Public 1 Dim As Dim 1 2 As Dim test(5) As Integer test 6 0~5 Variant 0 Visual Basic 0 0 1 Option Base Option Base 1 1 Option Base 0 0 Option Base Option Base 0 1 2 Dim [ To] [ [ To] ] Dim title( 5 To 3) title 5~3 32 768 32 767 0 128

3 Visual Basic Option Base Lbound [ ] Rbound [ ] Dim Public ReDim Dim test() As Integer ' Dim size Sub Form_Click() Size=InputBox("Enter value:"," data","12") Redim test(size) ' ReDim ReDim [Preserve] As ReDim Preserve ReDim ReDim ReDim 8 ReDim 60 ReDim 2 Erase Erase Erase Erase 0 129

Visual Basic 0 Empty Nothing Erase Redim 3 x(1)=100 For Print Print x(1) 4 For Each Next For Each Next For Each In [Exit For] Next[ ] For Next 130

3 Visual Basic For Each Next For Each Next Exit For 5 Visual Basic Array Array Dim As Variant =Array( ) Array 0 Option Base Dim Days As Variant Days = Array(1 2 3 4 5 6 7) Days(0) Days(6) 1 7 Dim Days(6) As Integer Days(0) = 1 Days(1) = 2 Days(2) = 3 Days(3) = 4 Days(4) = 5 Days(5) = 6 Days(6) = 7 3 131

Visual Basic Option1(1) Option1 1 1 1 2 2 0 1 Index Index 0 3.6.2 1 Visual Basic 4 4 1 2 3 4 1 Dim 2 Public 3 ReDim 4 Static 2 132

3 Visual Basic 1 2 3 1 Variant 2 0 3 3 Visual Basic 1 2 1 Visual Basic 0 0 1 Option Base Option Base 1 1 Option Base 0 0 1 0 2 Option Base 4 Visual Basic Erase 1 2 Visual Basic Erase Redim 1 2 5 2 1 1 2 6 A32 768~32 767 B C Option Base 0 D 32 768~32 767 0 Option Base D 133

Visual Basic 7 A For Each Next B For Next C While Wend D Do Loop For Each Next A 8 Dim A( 3 To 5) as Integer A 6 B 7 C 8 D 9 3~5 9 0 D 9 Dim score(1 To 15)As Double A 16 B 15 C 16 D 15 1~15 15 0 D 10 Static Ar(9,9) As Integer A 9 B 18 C 81 D 100 Array(0, 0) Array(9, 9) 100 D 11 Option Base 1 Dim a a = Array(1, 2, 3, 4) j = 1 For i = 3 To 0 Step -1 s = s + a(i) * j j = j * 10 134

3 Visual Basic Next i Print s A 12 B 123 C 1234 D For 1 i = 3 To 0 a(i) a(3) a(2) a(1) a(0) Option Base 1 1 For a(i) D 3.6.3 1 Dim a(10), b(10) For j = 0 To 10 a(j) = j + 5 b(j) = a(j)/4 Next j Text1.Text = b(j\2) A 2.5 B 5 C 4.5 D 5.5 2 Option Base 1 Dim a1(10), a2(4) As Integer m = 0 For i = 1 To 10 135

Visual Basic a1(i) = i Next i For i = 1 To 4 a2(i) = a1(i * 2) Next i For i = 1 To 4 m = m + a2(i) Next i Print m A 16 B 20 C 25 D 30 3 A ReDim Preserve A(10,Ubound(A,2)+1) B ReDim Preserve A(Ubound(A,1)+1,10) C ReDim Preserve A(Ubound(A)+1) D ReDim A((UBound)(A)+1) 4 Dim a(10) For j = 0 To 10 a(j) = j 5 Next j Text1.Text = a(a(6)/a(10)) A 5 B 1.6 C 0 D 5 Dim a(50) For j = 0 To 10 j = j * j a(j) = j Next j Text1.Text = a(25) 136

3 Visual Basic A 5 B 25 C 45 D 55 6 Dim a(10) For i = 1 To 10 a(i) = i ^ 2 Next i Print a(i 2) A 64 B 81 C 99 D 100 7 Dim a(4, 4), b(4, 4) For i = 1 To 4 For j = 1 To 4 a(i, j) = i + j b(i, j) = a(i, j) + i + j Next j Next i For i = 1 To 4 For j = 1 To 4 Print Tab(4 * j); a(i, j) + b(i, j); Next j Print Next i A 3 9 12 15 B 6 9 12 15 6 9 12 15 9 12 15 18 9 9 12 15 12 15 18 21 9 12 15 18 15 18 21 24 137

Visual Basic C 3 6 12 15 D 6 9 12 15 3 6 12 15 12 15 18 21 3 12 15 18 12 18 21 24 3 15 18 24 12 15 18 24 8 Dim n, s n = 1 If n > 1 Then GoTo l1 Else GoTo l2 l1: s = "n 1" GoTo l3 l2: s = "n 1" l3: MsgBox s An 1 Bn 1 C 1 D 9 Dim n, a n = 66 If n < 10 Then a = 1 ElseIf n < 100 Then a = 2 Else a = 3 End If MsgBox a 138

3 Visual Basic A 1 B 2 C 3 D 0 10 Dim c, a(20) c = 0 While c < 20 c = c + 1 a(c) = c Wend MsgBox a(10) A 10 C 20 11 B 11 D 9 Private Sub Form_KeyPress(KeyAscii As Integer) a = Array(25, 320, 125, 12, 215, 47) c = a(0) t = 1 If KeyAscii = 13 Then For i = 1 To 5 If a(i) > c Then c = a(i) t = i End If Next i End If Print c Print t A 12 B 320 C 25 D 47 3 1 0 5 12 139

Visual Basic AWeek = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat") today = AWeek(2) today = AWeek(6) MsgBox today A Sun B Tue C Sat D Thu 13 A For Next B For Each Next C While Wend D Do Loop 14 Dim A( 1 To 10) as Integer A 9 B 10 C 11 D 12 15 x = 10 Dim a(x) For m = 1 To 6 a(m) = m + 1 Next A a(m) B C m D 1 Dim A(11 to 30) 2 s = 1 For m = 1 To 3 140

3 Visual Basic If m <= 1 Then a = 1 ElseIf m <= 2 Then a = 2 ElseIf m <= 3 Then a = 3 Else a = 4 End If Print a Sum = Sum + a Next m Print Sum; 3 Score = Int(Rnd) + 5 Select Case Score Case 5 a$ = "Good" Case 4 a$ = "OK" Case 3 a$ = "Pass" Case Else a$ = "Bad" End Select MsgBox a$ 4 k = 0 Do While k < 10 k = k + 2 a = a + k * k / 50 141

Visual Basic Loop MsgBox a 5 x = 6 If x > 6 Then Print "x > 6" Else If x < 8 Then Print "x < 8" Else If x = 6 Then Print "x = 6" End If End If End If 3.7 Visual Basic Visual Basic Visual Basic 1 Visual Basic 2 Visual Basic 3 Visual Basic 3 4 Visual Basic Visual Basic Windows.EXE 5 Decimal 142

3 Visual Basic Decimal Decimal 6 ASCII 65535 7 Visual Basic DefType 8 Visual Basic 3 9 Visual Basic 10 Visual Basic 11 Visual Basic 1023 _ 12 3 If Select Case Visual Basic 3 For Do GoTo GoTo On-GoTo 13 143

Visual Basic Visual Basic 14 4 Dim ReDim Static Public 15Erase Erase 16 17 For Each Next 18 Visual Basic Array Array 19 Index 3.8 1 Dim Index& A Dim Index As Long B Dim Index As Integer C Dim Index As Single D Dim Index As Double 2 Type Student no As Integer name As String * 13 144

3 Visual Basic brith As Date score As Integer End Type Dim stu1 As Student A B C D 3 A Dim B Global C Static D Private 4 a=6 x=iif(a>5, 1,0) x A 5 B 6 C 0 D 1 5 x x = 0 For i = 1 To 20 Step 2 x = x + i \ 5 Next i Print x A 16 B 17 C 18 D 19 6 For i = 1 To 4 x = 4 For j = 1 To 3 x = 3 For k = 1 To 2 x = x + 6 Next k Next j Next i Print x 145

Visual Basic A 7 B 15 C 157 D 538 7 A My Documents B Visual Basic98 C \ D Windows 8 S 2 3 A Mid(S, 3, 2) B Mid (S, 2, 3) C MidStr(S, 3, 2) D MidStr(S, 2, 3) 9 Visual Basic A B C D 10 Tan 30 Visual Basic A Tan30 B Tan (30) C Tan (30 ) D Tan (30*3.14/180) 11 For i = 1 To 4 Print Tab(2 * i); 11 * i Next i A 11 B 11 22 22 33 33 44 44 C 11 22 33 44 D 11 223 344 12 a = 4 b = 3 Print b > a A 1 B 0 146

3 Visual Basic C True D False 13 Visual Basic A Abcd B m1234 C 5554tre D x_ y 14 S 6 A Right(S,6) B Left(S,6) C RightStr(S) D Left Str(S) 15 a = 12345678.9 b$ = "12345678.9" c$ = Str(a) b2 = Len(b$) c2 = Len(c$) Print b2, c2 A 10 10 B 10 11 C 9 10 D 9 9 16 a = 123 b = 456 c = Str(a) + Str(b) Print c A 123 B 123 456 C 123 456 D 579 17 x = 5 Do Until x = -1 a = InputBox(" A ") b = InputBox(" B ") 147

Visual Basic If a > b Then x = -1 Loop Print Val(a + b) 3 2 45 15 A 5 B 60 C 32 D 4 515 18 Dim a(5) For m = 1 To 6 a(m) = m + 1 Next A a(m) B C m D 19 Dim a(10), b(10) For j = 0 To 10 a(j) = 3 * j b(j) = a(j) * 3 Next j Text1.Text = b(j / 2-0.1) A 25 B 50 C 45 D 55 20 148 Dim n, s

3 Visual Basic n = InputBox("Input n:") If n > 1 Then GoTo l1 Else GoTo l2 l1: s = "n 1" GoTo l3 l2: s = "n 1" l3: MsgBox s 12 A n 1 B n 1 C 12 D 21 Dim a! A Dim a As Single B Dim a As Double C Dim a As Long D Dim a As Integer 22 A B C Type Public Private D Type Public 1 Dim i As Integer, m As Integer For m = 11 To 19 Step 2 For i = 2 To Int(Sqr(m)) If (m Mod i) = 0 Then GoTo LP Next i Print m; LP: Next m 2 100 200 149

Visual Basic Dim i As Integer, m As Integer For m = 101 To 199 Step 2 For i = 2 To m - 1 If (m Mod i) = 0 Then 1 Next 2 Print m Lp: Next 3 3 1 2 3 4 Visual Basic 1.Print 2 5 Visual Basic 1 2 6 Visual Basic Stop End 1 2 7 Visual Basic 1 2 3 8 Visual Basic ASCII 1 2 3 150

4 1 2 3 4.1 4.1.1 1. Print Print Print Print BASIC Print [ < >. ] Print [ ][, ; ] Form Debug PictureBox Printer [, ; ] 14 Print Print Print Print

Visual Basic 2. Print Visual Basic Print 1 Tab Tab( n ) Tab n Tab n n n n 1 Tab 2 Spc Spc( n ) Spc n 0~32 767 Spc 3 Space$ Space$( n ) Space$ n 3. (Format$) Format$ Format$ (, [ ] ) 1 ## 2 0 # 0 3. 4 5 % 6 $ 7 8 E E E 152

4 4. Visual Basic 1 FontName FontName [ = " " ] 2 FontSize FontSize [ = ] 3 FontBold FontBold [ = Boolean ] Boolean True False 4 FontItalic FontItalic [ = Boolean ] Boolean True False 5 FontUnderline FontUnderline [ = Boolean ] Boolean True False 6 FontStrikethru FontStrikethru [ = Boolean ] Boolean True False 5. Visual Basic Print Printer Printer.Print [ ] 6. PrintForm [.]PrintForm 4.1.2 1 153

Visual Basic Private Sub Form_Activate() Print "aa"; "bb", "cc", "dd"; "ee"; "ff" Print 12; 34; 56, 78, 90; -11; 22; -33 Print Print "xx" & "yy", 36 * 2; Print 7 ^ 2, Print "End" Print Print 4-1 4-1 1 2 Private Sub Form_Activate() Print "1234567890123456789012345678901234567890" Print " "; Tab(10); " "; Tab(20); " "; Print Tab(30); " " Print "001"; Tab(10); " "; Tab(20); " "; Tab(30); 98 Print "012"; Tab(10); " "; Tab(20); " "; Tab(30); 87 Print Print "1234567890123456789012345678901234567890" Print " "; Spc(6); " "; Spc(6); " "; Spc(6); " " Print "021"; Spc(6); " "; Spc(6); " "; Spc(6); 88 154

4 Tab n Tab Spc Tab Spc Tab(n) n Spc (n) n 4-2 4-2 2 3 Private Sub Form_Click() Print Format$(1234.5,"000,000.00") Print Format$(1234.5,"###,###.##") Print Format$(1234.5,"- ###,##0.00") Print Format$(1234.5,"$###,## #.##") Print Format$(0.1234,"0.00%") Print Format$(123456,"0.00E+00") Print Format$(123456,"0.00E-00") Print Format$(0.123456,"0.00E-00") Format$ Format$ 4-3 4 4-4 a = "ABCD" For m = 1 155

Visual Basic Print Tab(5 - m); Next m 2 4-3 3 4-4 4 3 D CD BCD a D a 1 CD a 1 2 BCD a 1 2 3 a Right Right Rightn n m 1~3 For m = 1 To 3 Right(a,m) Tab 5 m Right(a,m) Tab 1 1 To 3 2 Right(a,m) 5 156

4 Private Sub Form_Click() FontName=" " FontSize=24 FontItalic=True FontUnderline=True Print " " FontName=" " FontSize=20 FontItalic = False FontBold = True FontUnderline = False Print " " PrintForm Print PrintForm 4-5 4-5 5 6 Private Sub Form_Click() Printer.FontName=" " Printer.FontSize=24 Printer.FontItalic=True Printer.FontUnderline=True Printer.FontBold=True Printer.Print " " Printer.EndDoc 157

Visual Basic 4.1.3 1 Print Format$(32548.5,"000,000,00") A 32 548.5 C 32,548.5 2 B 023,548.50 D 32,548.50 a = "12345" For m = 3 To 4 Print Tab(6 - m); Right(a, m) Next m A B C D 3 For j = 1 To 10 If j Mod 3 <> 0 Then a = a + j \ 3 Next j 158

4 Print a A 9 C 6 4 B 12.333 D 0 a=sqr(3) Print Format$(a,"000.00") A 001.73 C 17.3E 01 5 B 1.73 D 1.732 s% = 3.14159 Print s% A 3.141 59 B 3.141 6 C 3.14 D 3 6 Print "Visual";"C++","Visual";"Basic" A VisualC++VisualBasic B Visual C++Visual Basic C VisualC++ VisualBasic D Visual C++ Visual Basic 7 Print "Visual"; Print "Basic", Print "6.0" A VisualBasic6.0 B VisualBasic 6.0 C Visual Basic6.0 D Visual Basic 6.0 8 Visual Basic 159

Visual Basic A FontName B FontSize C FontBold D FontItalic 9 Visual Basic A Form1.Show B Form1.Print C Form1.Println D Form1.PrintForm 10 Visual Basic A Print B Printer C Show D Display 11 Visual Basic A FontUnderline B FontStrikethru C FontBold D FontItalic 1 For j = 1 To 3 Print ; 11 * (2 * j - 1); Next j 2 160

4 For j = 1 To 10 If j Mod 3 <> 0 Then a = a + j / 3 Next j Print Format$(a, 1 ) Print Format$(a, 2 ) 3 a = 10 1 b = "abc" Print a 2 b Print a 3 b 4.2 4.2.1 1. InputBox Visual Basic InputBox InputBox InputBox ( prompt [,title] [,default] [,xpos,ypos] [,helpfile,context] ) 1 prompt 1 023 161

Visual Basic 2 title 3 default 4 xpos,ypos x y x y 5 helpfile 6 context 2. MsgBox MsgBox MsgBox MsgBox(msg[,type][,title][,helpfile,context]) MsgBox MsgBox msg$[,type%][,title$][,helpfile,context]) MsgBox MsgBox MsgBox 1 msg 1 023 Chr$(13)+Chr$(10) 2 type 0 4.1 4.1 vbokonly 0 vbokcancel 1 vbabortretryignore 2 vbyesnocancel 3 vbyesno 4 vbretrycancel 5 vbcritical 16 Critical Message vbquestion 32 Warning Query vbexclamation 48 Warning Message vbinformation 64 Information Message vbdefaultbutton1 0 162

4 vbdefaultbutton2 256 vbdefaultbutton3 512 vbdefaultbutton4 768 3 title 4 helpfile 5 context MsgBox 4.2 4.2 MsgBox 1 vbok 2 vbcancel 3 vbabort 4 vbretry 5 vbignore 6 vbyes 7 vbno 4.2.2 1 InputBox Private Sub Form_Click() msgtitle$=" " ch$=chr$(13)+chr$(10) msg0$="[ ] " msg1$=" "+ ch$+ msg0$ msg2$=" "+ ch$+ msg0$ msg3$=""+ ch$+ msg0$ studname$=inputbox(msg1$,msgtitle$) studsex$=inputbox(msg2$,msgtitle$," ") 163

Visual Basic studcard$=inputbox(msg3$,msgtitle$) Cls Print " " ;studname$;" "; studsex$;" ";""; studcard$ InputBox Chr$(13)+Chr$(10) InputBox InputBox default InputBox(msg2$,msgtitle$," ") InputBox 4-6 4-6 1 ImputBox 4-7 4-7 1 2 MsgBox Private Sub Form_Click() msgtitle$=" " msg1$="" w=msgbox(msg1$,37,msgtitle$) Print w MsgBox MsgBox msgtitle$msg1$ 37 164

4 Warning Query 32 5 4-8 4-8 4 4 3x For i = 1 To 5 a = a + i Next i x = Val(i) MsgBox x A 4 C 6 B 5 D 7 Msgbox MsgBox (msg [,type] [,title] [,helpfile, context] ) msgtype 0 Title Helpfile Context context helpfile Val C 4 Msgbox A C B D Msgbox Integer 165

Visual Basic A 4.2.3 1 x = InputBox(x) y = Len(x) Print "The Length Of "; x; " Is "; y Input Box VB A The Length Of Visual Is 2 B The Length Of Visual Is 3 C The Length Of VB Is 2 D The Length Of VB Is 3 2 a = Val(Text1.Text) If a Mod 3 = 0 Then MsgBox " 3 " Else MsgBox " 3 " End If 126 A 3 B 3 C D 3 a=5 b=6 a = InputBox(" " & "a" & " ") b = InputBox(" " & "b" & " ") 166

4 c = a * b + 5 Print c A 6 35 B 30 35 C TAB(6)35 D 35 4 Sub Form_Load() Dim Password, Pword Password = "Visual" Pword = InputBox("Type in your password") If Pword <> Password Then MsgBox "Sorry, incorrect password" End If A Sorry, incorrect Password B Type in your password Sorry, incorrect password C Type in your password Sorry, incorrect password D Type in your password Visual Sorry, incorrect Password 1 S=1 +2 +3 + +n n = Val( 1 (" ")) s = 0 For i = 1 To n GoSub m s = s + 1 Print "t="; t, "s="; s Next i Exit Sub 167

Visual Basic m: t = 1 For j = 1 To i t = 2 Next j Return 2 m = Val ( InputBox ( " " ) ) S = 0 N = 0 Do N = N + 1 S = S + 2 ^ N Loop While S <= m Print "N="; N, "S="; S InputBox 1000 3 X = Val(InputBox(" ")) If X > 0 Then Y = X * X Else Y = -X * X End If Print "Y="; Y InputBox 5 5 2 4 1 Dim X As Integer Dim A(5) As Integer For X = 0 To 4 168

4 A(X) = 5 Next X Dim B(5) As String For X = 0 To 4 B(X) = "hello" Next X Dim arrx(2) As Variant arrx(1) = A() arrx(2) = B() MsgBox arrx(1)(2) MsgBox arrx(2)(3) MsgBox arrx(1)(2) 1 MsgBox arrx(2)(3) 2 4.3 4.3.1 1. Visual Basic ActiveX ActiveX Visual Basic Action Action 4.3 4.3 Action Action 1 ShowOpen 2 ShowSave 3 ShowColor 4 ShowFont 5 ShowPrinter 6 ShowHelp Windows 169

Visual Basic Name CommonDialogx x 1 2 3 2. 1 Properties 4-9 4-9 / 4.4 DialogTitle FileName InitDir Filter Flags DefaultExt Text Files(*.TXT) *.txt MaxFileSize 1~2K 260 FilterIndex ShowOpen.ShowOpen 170

4 2 ShowSave.ShowSave 3. Visual Basic Properties 4-10 4-10 4.5 Color Flags ShowColor.ShowColor 4. Visual Basic 171

Visual Basic Properties 4-11 4-11 4.6 Color FontName FontSize Max Min Flags Style (FontBold) (FontItalic) (FontUnderline) (FontStrikethru) ShowFont.ShowFont 5. Visual Basic Properties 172

4 4-12 4-12 4.7 Copies Flags Orientation Max Min Flags Frompage Topage ShowPrinter.ShowPrinter 6. Visual Basic Windows Properties 4-13 173

Visual Basic 4-13 4.8 HelpContext HelpCommand HelpKey HelpFile ID ShowHelp.ShowHelp 4.3.2 1 CommonDialog A ShowOpen B ShowOpen C ShowOpen D ShowOpen ShowSave ShowClose ShowOut ShowClose ShowColor ShowColor ShowSave ShowFont ShowPrinter ShowPrinter ShowPrinter ShowPrinter ShowHelp ShowHelp ShowHelp ShowHelp ShowFont ShowFont ShowFont ShowColor ShowOpen ShowSave ShowColor ShowFont ShowPrinter ShowHelp Windows A 174

4 2 A Frompage B Topage C Startpage D Endpage Visual Basic Frompage Topage Startpage Endpage A 3 Visual Basic ShowPrinter 4 1 Name 2 x 1 2 3 Action Name CommonDialogx x 1 2 3 1 Action 2 CommonDialogx 4.3.3 1 CommonDialog A ShowOpen B ShowClose C ShowSave D ShowPrinter 2 Action 1 A ShowFont B ShowHelp C ShowOpen D ShowSave 3 A Max B Min C Frompage D Topage 4 A Max B Min C Copies D Pages 5 A CommonDialog1.ShowFont 175

Visual Basic B FileTitle C FileName D 6 A CommonDialog1.Filter=All Files *.* Pictures(*.Bmp) *.Bmp B CommonDialog1.Filter="All Files" "*.*" "Pictures(*.Bmp)" "*.Bmp" C CommonDialog1.Filter="All Files *.* Pictures(*.Bmp) *.Bmp" D CommonDialog1.Filter={All Files *.* Pictures(*.Bmp) *.Bmp} 7 A BorderStyle ControlBox MaxButton MinButton 1 True False B frmabout.show vbmodeless frmmain frmabout frmmain C D frmabout.show frmabout 1 CommonDialog1 CommonDialog1.Action=3 2 3 Microsoft Windows CommonControl 6.0 1 ToolBar StatusBar 2 TreeView ListView ImageList 3 ImageCombo 4.4 Visual Basic 1 Print Print Space$ n Spc Tab n 2 Format$ 3 Visual Basic FontName FontSize FontBold FontItalic FontUnderline FontStrikethru 4 Visual Basic Printer 176

4 Print Visual Basic PrintForm 5 Visual Basic ActiveX ActiveX Action Name CommonDialogx x 1 2 3 4.5 1 InputBox() A B C D 2 X = 0 Do Until X = -1 A = InputBox(" A ") A = Val(A) B = InputBox(" B ") B = Val(B) X = InputBox(" X ") X = Val(X) A = A + B + X Loop Print A 5 4 3 2 1 A 2 B 3 C 14 D 15 3 177

Visual Basic a = Val(Text1.Text) If a Mod 2 = 0 Then MsgBox " " Else MsgBox " " End If 50 A B C D 4 k = 1 For j = 1 To 4 k = k * j Next j MsgBox k \ j A 4.8 B 4 C 5 D 0.8 5 CommonDialog A ShowOpen B ShowClose C ShowColor D ShowPrinter 6 A B C D 1 A = Val(InputBox(" ")) B = Val(InputBox(" ")) X = A + B 178

4 If A > B Then X = A - B Text1.Text = X InputBox 12 45 1 Command1 InputBox 45 12 2 2 k = 1 For j = 1 To 5 k = k * j Next j MsgBox k / j 3 BB$ = "Visual Basic 6.0" m = Len(BB$) For j = 1 To m B$ = Mid$(BB$, j, 1) If B$ = "a" Then X = X + 1 Next j MsgBox X 4 N MsgBox n = InputBox(" ") k = Int(Sqr(n)) i = 2 flag = 0 Do While i <= k And flag = 0 If 1 = 0 Then flag = 1 Else 179

Visual Basic i = i + 1 End If Loop If 2 Then MsgBox " ", vbokonly, " " Else 3 " ", vbokonly, " " End If 5 InputBox n = InputBox(" ") m = Len(n) For j = 1 dec = dec * 2 + Val( 2 (n, j, 1)) Next j Print ""; dec 6 A = -12.3 B = 12.3 c$ = "+" d$ = Str$(A) + c$ + Str(B) MsgBox d$ 7 Sum = 0 For j = 1 To 10 If j = 10 Then Else Sum = Sum + j 180

4 End If Next j MsgBox Sum 8 m$ = "ABC" n$ = "ABC" k$ = LCase$(m$) j$ = UCase$(n$) MsgBox Asc(k$ + j$) 9 s 50 1.00 >=50 100 0.09 >=100 200 0.08 =200 0.07 w s w = InputBox(" ") s = InputBox(" ") p = If s >= 200 Then p = 0.7 ElseIf s >= 100 Then p = 0.8 ElseIf s >= 50 Then p = 0.9 End If Print " ="; p * s * w 181

Visual Basic 10 K = 0 For J = 1 To 2 For I = 1 To 3 K = I + 1 Next I For I = 1 To 7 K = K + 1 Next I Next J MsgBox I,, "I" MsgBox J,, "J" MsgBox K,, "K" I 1 K 3 J 2 11 A = InputBox(A) B = Len(A) Print "The Length Of "; A; " Is "; B Input Box Visual 12 h = InputBox(" ") h = 1 (h) f = InputBox(" ") f = 2 (f) y = (f - 2 * h) / 2 x = (4 * h - f) / 2 Print " "; x; " "; y; " " 182

4 InputBox 71 158 13 CommonDialog1 CommonDialog1.ShowColor 183

5 1 Sub 2 Sub 3 4 Funtion 5 Funtion 6 7 8 Visual Basic Visual Basic Visual Basic Sub Function Visual Basic Sub Click Load Change Visual Basic Visual Basic 5.1 Sub 5.1.1 1. Sub Sub Sub

5 [Static][Private][Public] Sub [( )] [Exit Sub] [ ] [Static][Private][Public] Sub _ [( )] [Exit Sub] [ ] [Static][Private][Public] Sub [Form/MDIForm]_ [( )] [Exit Sub] [ ] Sub Sub Sub 1 Static Sub Static Static 0 Static 2 Private Sub 3 Public Sub Public 4 255 Sub Function _Form/MDIForm _ 185

Visual Basic 5 [Optional][ByVal/ByRef][ParamArray] [()] [As ] [= ] Visual Basic Integer Long Single Double String Currency Variant As Variant OptionalOptional ByVal ByRef Visual Basic ParamArray Variant Optional ByVal ByRef Sub Sub Exit Sub Sub GoTo Sub 2. Sub Sub Sub 1 5-1 5-2 186 5-1

5 5-2 5-3 5-3 vbtest 5-4 Sub EndSub 2 Sub vbtest2( ) 187

Visual Basic Sub vbtest2() 5-4 Sub 5-5 5-5 188

5 3 Sub 5-6 5-6 Sub vbtest3() Sub vbtest3() 3. Sub Sub Sub Sub Call 1 Call Sub Call [ ( ) ] Call Visual Basic Sub Call Sub 189

Visual Basic Call vbtest1(a,b) 2 [ ] Sub Call Sub Call vbtest1 a,b 4. Sub Sub Name _ Form/MDIForm _ Sub ( ) Sub Function 5.1.2 1 Visual Basic Visual Basic 2 1 Visual Basic Visual Basic Sub Function 1 Sub 2 Function 2 Visual Basic Sub 1 2 Visual Basic Sub Click Load Change 190

5 Visual Basic 1 2 3 Visual Basic 1 2 Visual Basic 1 2 4 Sub Visual Basic Sub Call Visual Basic Sub Call Call 5 Sub A Static B Private C Public D Defaut Static Sub Static 0 Private Sub Public Sub A 6 Sub A ByVal B ByRef C ParamArray D Optional ByVal ByRef ParamArray Variant Optional Optional A 191

Visual Basic 5.1.3 1 Visual Basic A B C D 2 A B C D 3 Sub A Show B Select C GoTo D Return 4 Sub A abc 3,5 B abc(3,5) C Call abc(3,5) D Call abc() 5 Sub A ByVal B ByRef C ParamArray D Optional 6 Sub A Sub B Sub C Sub D GoTo Sub 7 Sub Sub S1(x As Single, y As Single) t = x x = t/y y = t Mod y Dim a As Single Dim b As Single a=9 192

5 b=4 Call S1 (a,b) Print a,b A 9 4 B 2 1 C 2.25 1 D 2.25 2 8 Sub subp(b() As Integer) For i = 1 To 4 b(i) = 2 * i Next i Dim a(1 To 4) As Integer a(1) = 5 a(2) = 6 a(3) = 7 a(4) = 8 Call subp(a) For i = 1 To 4 Print a(i) Next i A 2 B 5 C 2 D 4 6 2 6 7 2 8 8 2 9 Private Sub test(p, m, n) p = p + 1: m = m + 1: n = n + 1 Print "sub "; p; m; n a = 1: b = 2: c = 3 193

Visual Basic Call test(a, b + 3, (c)) Print "main:"; a; b; c A sub:2 6 4 B sub:2 6 4 main:2 6 4 main:1 6 4 C sub:2 6 4 D sub:2 6 4 main:1 2 3 main:2 2 3 10 Private Sub f(k, s) s = 1 For j = 1 To k s = s * j Next j Sum = 0 For i = 1 To 3 Call f(i, s) Sum = Sum + s Next i Print Sum A 0 B 3 C 6 D 9 11 Sub test(x,y) y = 1 For i = 1 To x y = y + i Next i m = 0 : n = 4 For i = 1 To n Call test(i,y) m = m + y 194

5 Next i Text1.Text = "m=" & m A m=6 B m=13 C m=24 D m=40 12 Dim a(5) As Integer, b(5) As Integer For i = 1 To 5 a(i) = i * i Next i Call ArrayCopy(a(), b()) Print a(5); b(5) Sub ArrayCopy(oldCopy() As Integer, newcopy() As Integer) Dim i As Integer For i = LBound(oldCopy) To UBound(oldCopy) newcopy(i) = oldcopy(i) Next i A 0 25 B 25 0 C 5 5 D 25 25 1 Sub 1 2 2 Visual Basic Sub 1 2 3 Call test(12.3, 6.7) Sub test(x%, y%) 195

Visual Basic x% = x% * 2 y% = y% \ 2 Print x%; y% 4 Sub f(k, s) s = 1 For m = 1 To k s = s * m Next m total = 0 For k = 2 To 4 Call f(k, s) total = total + s Next k MsgBox total 5.2 Function 5.2.1 Visual Basic Sub Function Sub Function 1. Function 196 [Static] [Private/Public] Function [( )] [As ] [ ]

5 [ = ] [Exit Function] [ ] [ = ] End Function Function Function End Function Sub Static Private Public Sub Exit Function As Function Integer Long Single Double Currency String Variant Function = = 0 2. Function Function Sub Sub Function 3. Function Function Visual Basic = Function 5.2.2 1 Visual Basic Sub Function 1 2 3 1 Sub 2 Function 3 Variant 2 Function A Function Function End Function 197

Visual Basic B Exit C D Visual Basic Function Function End Function Exit Function B 5.2.3 1 Function Function F(a As Integer, b As Integer) Static c c = a + b F = c End Function Dim a As Integer, b As Integer a = 1: b = 10 For i = 1 To 3 a = a + i Print F(a, b); Next i A 11 11 11 B 13 17 23 C 12 14 17 D 13 13 13 2 Function A Function Function End Function B C Function D Function Variant 3 198 Function F(a As Integer) Static c

5 b = b + 1 c = c + 1 F = a + b + c End Function Dim a As Integer a = 2 For I = 1 To 3 Print F(a) Next I A 4 B 4 C 4 D 4 4 5 6 7 4 6 8 9 4 Function A Exit Function B Exit C Return D Resume 5 Text Command1 Click Private Function even(x As Long) As Boolean If x Mod 2 = 0 Then even = True Else even = False End If End Function Dim n As Long n = Val(Text1.Text) p = IIf(even(n), " ", " ") Label1.Caption = n & " " & p Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) 23 A 23 B 23 199

Visual Basic C 23 D 0 6 Private Function fee(x) If x > 1000 Then y = (x - 1000) * 0.05 Else y = 0 End If fee = y End Function x = InputBox("") pay = fee(x) MsgBox " " & pay & " " 1 500 A 0 B 15 C 25 D 50 7 Function A Exit Sub B Exit Function C End D End Function 8 Function FF(n) x = n * n FF = x End Function For k = 8 To 10 y = FF(k) Print y; Next k A 8 9 10 B 16 18 20 C 64 81 100 D 200

5 1 Function F1(a As Integer) Static c c = c + a F1 = c End Function Function F2(a As Integer) Dim c As Integer c = c + a F2 = c End Function Dim a As Integer a = 1 For i = 1 To 3 Print F1(a); F2(a) Next i nd Sub 2 Function fun(n) As Integer If n > 0 Then fun = n * fun(n - 1) Else fun = 1 End If End Function Dim a As Integer For i = 4 To 5 a = fun(i) Print a; Next i 3 201

Visual Basic Function fun(byval num As Long) As Long Dim k As Long k = 1 num = Abs(num) Do While num k = k * (num Mod 10) num = num \ 10 Loop fun = k End Function Dim n As Long Dim r As Long n = CLng(InputBox(" ")) r = fun(n) Print r 25 4 Function Fun(a As Integer) Static c c = c + 1 Fun = a + c End Function Dim a As Integer a = 10 For i = 1 To 3 Print Fun(a); Next i 5 Private Function fun(n) As String If n > 0 Then fun = " 0" ElseIf n = 0 Then 202

5 fun = " 0" Else fun = " 0" End If End Function Dim c As String For i = -1 To 1 c = fun(i) Print i & c & ";"; Next i 5.3 5.3.1 1. Sub Function Sub Function x$ x As String x As String * 6 a() Sub Function Sub Function x As String *6 203

Visual Basic Sub vbtest1(a As Integer, b() As Single, c1 As String, d As Long ) Call vbtest1( 26, aa(), "this", 1 234.5 ) 2. Visual Basic Sub Function Visual Basic ByVal Sub vbtest2(byval x As Integer,ByVal y As Integer) Print " x=";x;" y=";y x=x+y Print " x=";x;" y=";y Sub Form_Click() Dim a As Integer, b As Integer a=5:b=6 Print " a=";a;" b=";b Call vbtest2(a,b) Print " a=";a;" b=";b x y ByVal x y Visual Basic x y a b 5 6 x y x=x+y x 11 a 5-7 204

5 5-7 Sub vbtest2(x As Integer, y As Integer) Print " x=";x;" y=";y x=x+y Print " x=";x;" y=";y Sub Form_Click() Dim a As Integer, b As Integer a=5:b=6 Print " a=";a;" b=";b Call vbtest2((a),(b)) Print " a=";a;" b=";b a b Visual Basic Sub Function Sub vbtest2(x As Integer, y As Integer) Print " x=";x;" y=";y x=x+y Print " x=";x;" y=";y Sub Form_Click() Dim a As Integer, b As Integer 205

Visual Basic a=5:b=6 Print " a=";a;" Call vbtest2(a,b) Print " a=";a;" b=";b b=";b x y ByRef a b x y a x b y x=x+y x 11 a 11 5-8 5-8 3. Visual Basic Sub ArrayTest1(a() As Integer, b() As Integer)... Sub Form_Click()... Dim m() As Integer, n() As Integer... Call ArrayTest1 (m(),n())... Call ArrayTest1 m n a b Visual Basic ArrayTest1 m n a m b n 206

5 LBound UBound LBound UBound 4. Visual Basic 6.0 Visual Basic 6.0 Optional Optional Optional IsMissing IsMissing Optional IsMissing Boolean IsMissing True False Sub vbtest4(x As Integer, y As Integer,Optional z) x=x+y If Not IsMissing(z) Then x=x+z End If Print x Private Sub Form_Click() vbtest4 5,6,10 x y Integer z Variant z Optional vbtest4 x y x Not IsMissing(z) z z x x Form_Click 21 Form_Click vbtest4 5,6,10 207

Visual Basic Private Sub Form_Click() vbtest4 5,6 Not IsMissing(z) z 11 Variant Visual Basic 6.0 ParamArray Sub (ParamArray ) Variant Sub vbtest4(paramarray Numbers()) n=0 For Each x In Numbers n=n+x Next x Print n Private Sub Form_Click() vbtest4 5,6,10 21 5. Visual Basic Sub ( ) [Exit Sub] 208

5 Form Control 5.3.2 1 Visual Basic 1 2 3 Visual Basic 1 2 3 2 Visual Basic 1 2 1 2 3 Visual Basic 1 2 Visual Basic 1 2 4 Visual Basic A LBound B UBound C D Visual Basic LBound UBound LBound UBound D 209

Visual Basic 5 Sub abc(x, y) x = 2 * x y = 3 * y Print "x="; x; ",y="; y Private Sub Form_Click() a = 1: b = 1 1: Print "a="; a; ",b="; b Call abc((a), b) 2: Print "a="; a; ",b="; b Visual Basic Sub Function Form_Click a b 1 1 Print a=1,b=1call abc((a), b)a b a (a) abc (a) b abc x (a) 1 y b x 2 y 3 Print x=2,y=3 abc y b b 3 a 1 2 Print a=1,b=3 a=1,b=1 x=2,y=3 a=1,b=3. 5.3.3 1 Visual Basic 210

5 A B C D 2 Visual Basic A B Visual Basic C ByVal D 3 a Dim a Sub test() a = a + 1: b = b + 1: c = c + 1 Print "Sub"; a; b; c Private Sub Form_Click() a = 2: b = 3: c = 4 Call test Print "main:"; a; b; c A Sub:3 4 5 B Sub:2 3 4 Main:3 4 5 Main:1 2 3 C Sub:4 1 1 D Sub:3 1 1 Main:4 3 4 Main:3 3 4 4 Visual Basic A Sub B Function C Property D Private 1 Visual Basic 1 ByVal 2 211

Visual Basic 2 Sub vbtest2(byval x As Integer,ByVal y As Integer) Print " x=";x;" y=";y x=x+y Print " x=";x;" y=";y Sub Form_Click() Dim a As Integer, b As Integer a=5:b=6 Print " a=";a;" b=";b Call Print " a=";a;" b=";b vbtest2 3 1 2 3 4 4 Visual Basic 6.0 5 Visual Basic 1 2 5.4 5.4.1 1. Visual Basic KeyDown KeyUp KeyPress Sub _KeyDown ( KeyCode As Integer, Shift As Integer) Sub _KeyUp ( KeyCode As Integer, Shift As Integer ) 212

5 Sub _KeyPress ( KeyAscii As Integer) 1 KeyDown KeyUp KeyPress KeyDown KeyPress KeyUp KeyDown KeyUp KeyPress ASCII A KeyDown KeyCode A a KeyCode KeyPress KeyAscii ASCII A ASCII 65 a ASCII 97 KeyAscii KeyDown KeyCode Shift 2 KeyAscii ASCII KeyCode ASCII KeyCode ASCII KeyCode KeyCode ASCII 5.1 KeyCode KeyAscii 5.1 KeyCode KeyAscii KeyCode KeyAscii A &H41 &H41 a &H41 &H61 B &H42 &H42 b &H42 &H62 % &H35 &H25 0 &H30 &H30 9 &H39 &H39 0 &H60 &H30 9 &H69 &H39 213

Visual Basic Shift 3 Shift Ctrl Alt 3 Shift 001 Ctrl 010 Alt 100 Shift Shift 001 1 Ctrl Shift 010 2 Alt Shift 100 4 Shift Shift 8 5.2 5.2 Shift 0 000 1 001 Shift 2 010 Ctrl 3 011 Ctrl +Shift 4 100 Alt 5 101 Alt +Shift 6 110 Alt +Ctrl 7 111 Alt +Ctrl +Shift 3 KeyDown KeyUp KeyPress 4 KeyDown KeyUp KeyPress KeyPreview True False 2. ClickDblClick Visual Basic MouseDown MouseUp MouseMove Sub _MouseDown(Button As Integer,Shift As Integer,x As Single,y As Single) Sub _MouseUp(Button As Integer,Shift As Integer,x As Single,y As Single) Sub _MouseMove(Buaon As Integer,Shift As Integer,x As Single,y As Single) 214

5 1 MouseDown MouseUp MouseMove 2 Button (16 ) 3 1 0 5.3 5.3 Button 0 000 LEFT BUTTON 1 001 RIGHT BUTTON 2 010 3 011 IDDLE BUTTON 4 100 5 101 6 110 7 111 3 MouseDown MouseUp Button 3 001 010 100 MouseMove Button Shift Shift Ctrl Alt Shift x y 3. Windows Visual Basic MousePointer MousePointer 0~15 5.4 215

Visual Basic 5.4 MousePointer vbdefault 0 vbarrow 1 vbcrosshair 2 vbibeam 3 I vbiconpointer 4 vbsizepointer 5 4 vbsizenesw 6 vbsizens 7 vbsizenwse 8 vbsizewe 9 vbuparrow 10 vbhourglass 11 vbnodrop 12 vbarrowhourglass 13 vbarrowquestion 14 vbsizeall 15 vbcustom 99 MouseIcon MousePointer MousePointer MousePointer 5-9 MousePointer 5-9 MousePointer 216

5 MousePointer.MousePointer = MousePointer 0 15 5.4 MousePointer 99 MouseIcon 4. Dragging Dropping Visual Basic 5.5 Visual Basic 5.5 DragMode 0-Manual DragIcon DragMode 1-Automatic DragDown Drag DragIcon DragOver DragOver DragOver DragDrop DragOver DragDrop 1 DragMode 0-Manual DrogMode 1-Automatic DrogMode 5-10.DragMode = 1.DragMode = 0 2 DragIcon DragIcon DragIcon 5-11.DragIcon = LoadPicture ( " ") 217

Visual Basic 5-10 DragMode 3 DragOver DragOver Sub _DragOver ( Source As Control, x As Single, y As Single, State As Integer ) Source Control x y State 3 5.6 5.6 State 0 1 2 4 DragDrop DragDrop Sub _DragDrop ( Source As Control, x As Single, y As Single ) EndSub 218

5 Source Control x y 5 Drag Drag Drag.Drag 0 1 2 5.7 5.7 Drag 0 1 Drag 2 DragDrop 5.4.2 1 Visual Basic ASCII A KeyDown B KeyUp C KeyPress D KeyAscii KeyDown KeyUp KeyPress ASCII KeyAscii C 2 Visual Basic 1 2 3 Visual Basic MouseDown MouseUp MouseMove MouseDown MouseUp MouseMove 1 MouseDown 2 MouseUp 3 MouseMove 3 Visual Basic 1 2 Dragging Dropping Visual Basic 1 2 219

Visual Basic 4 Visual Basic A DragMode B Drag C DragDrop D DragOver DragMode Drag DragDrop DragOver B 5.4.3 1 Visual Basic A KeyDown B KeyUp C KeyPress D KeyAscii 2 Visual Basic A MouseDown B MouseMove C MouseUp D MousePointer 3 Visual Basic 55 KeyCode KeyAscii A B C D 4 A DragMode B Drag C DragDrop D DragOver 5 DrogMode A 1 B 0 C 1 D 2 6 Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button=2 Then Print "AAAAA" End If 220

5 Private Sub Form_MouseUp(Button As Integer,Shift As Integer,X As Single,Y As Single) Print BBBBB A AAAAA B BBBBB BBBBB AAAAA BBBBB BBBBB C AAAAA D BBBBB BBBBB BBBBB 7 Option Base 1 Private Sub Form_KeyPress(KeyAscii As Integer) a = Array(200, 50, 450, 500, 230,800) m1 = a(1) m2 = 1 If KeyAscii = 13 Then For i = 2 To 6 If a(i) > m1 Then m1 = a(i) m2 = i End If Next i End If Print m1 Print m2 A 200 B 200 C 50 D 800 0 1 2 6 1 Private Sub Text1_KeyPress(KeyAscii As Integer) Char = Chr(KeyAscii) 221

Visual Basic KeyAscii = Asc(UCase(Char)) 2 Visual Basic 1 2 3 Visual Basic 1 2 3 4 4 Visual Basic 5.5 Visual Basic 1 Visual Basic 2 Visual Basic Sub Function Sub Function 3 Visual Basic 4 Click Load Change VisualBasic 5 Sub Sub Call 6 Sub Sub Name _ Form/MDIForm _ 7 Sub Function 222

5 8 Function Function End Function Function Visual Basic 9 Visual Basic 10 Visual Basic 6.0 Optional Optional IsMissing ParamArray 11 Visual Basic KeyDown KeyUp KeyPress KeyDown KeyUp KeyPress ASCII 12 Visual Basic MouseDown MouseUp MouseMove MouseDown MouseUp MouseMove 13 Visual Basic MousePointer 14 Dragging Dropping Visual Basic DragMode DragIcon Drag DragDrop DragOver 223

Visual Basic 5.6 1 Visual Basic A LBound B UBound C D 2 Visual Basic A KeyDown B KeyUp C KeyPress D KeyAscii 3 Sub A Static B Private C Public D Defaut 4 Function abc(n) As Integer For i=1 To 3 n = n + i Next i abc= n End Function Dim a As Integer a = 5 Print abc(a*a) A 25 B 28 C 31 D 34 224

5 5 Visual Basic A MouseDown B MouseMove C MouseUp D MousePointer 6 A DragMode B Drag C DragDrop D DragOver 7 Function F1(a As Integer) Static c c = c + a F1 = c End Function Function F2(a As Integer) Dim c As Integer c = c + a F2 = c End Function Dim i As Integer For i = 1 To 3 Print F2(F1(i)) ; Next i A 1 3 6 B 1 3 7 C 1 2 5 D 1 2 6 8 Visual Basic A MouseDown B MouseMove C MouseUp D MousePointer 9 Text1.Text = UCase(Text1.Text) Private Sub Command2_Click() Text1.Text = LCase(Text1.Text) Private Sub Command3_Click() 225

Visual Basic Text1.Text = Text1.Tag Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) Text1.Tag = Text1.Text Abc Command1 Command2 Command3 A ABC abc ABC B ABC abc Abc C abc ABC Abc D abc ABC abc 10 Sub test(x%, y%, z%) z% = x% + y% a% = 12.5: b% = 40.2 Call test(a%, b%, c%) Print c% A 0 B 52 C 53 D 11 Sub Sub test(x As Single, y As Single) t = x x = t + 2 y = t - 2 Dim a As Single Dim b As Single a = 10 b = 4 226

5 Call test(a, b) Print a, b A 12 8 B 10 4 C 8 6 D 12 2 1 Sub test(b() As Integer) For i = 1 To 4 b(i) = 2 * i Next i Private Sub Form_Click() Dim a(1 To 4) As Integer For i = 1 To 4 a(i) = i Print a(i); Next i Print test a For i = 1 To 4 Print a(i); Next i 1 2 2 Function Fee(x) If x <=20 Then y = x Else y = 20 + x End If 227

Visual Basic Fee = y End Function x = InputBox("",, 0) pay = Fee(x) Print pay x 20 1 x 35 2 3 1 +2 +3 + +n Function Fun(t) p = 1 For j = 1 To t p = p * j Next j 1 End Function s = 0: c = "1 " n = Val(InputBox(" :")) For t = 1 To n s = s + 2 Next t For i = 2 To n c = c & "+" & i & " " Next i c = c & "=" Print c; s 4 Dim a(5) As Integer, b(5) As Integer For i = 1 To 5 a(i) = i * i Next i Call ByteCopy(a(), b()) 228

5 Print "a(5)=" & a(5) & ";b(5)=" & b(5) Sub ByteCopy(oldCopy() As Integer, newcopy() As Integer) Dim i As Integer For i = LBound(oldCopy) To UBound(oldCopy) newcopy(i) = oldcopy(i) Next i 5 Function Fun(a As Integer) Static c b = b + 1 c = c + 1.5 Fun = a + b + c End Function Dim a As Integer a = 1 For i = 1 To 3 Print Fun(a); Next i 6 Sub 7 Dim a As Integer, b As Integer, c As Integer a = 10: b = 2: c = 3 Print c; Call sub1 Print c; Call sub2 Print c Sub sub1() 229

Visual Basic c = a * b Sub sub2() c = a / b 8 Private Function fun(n) As Integer If n > 0 Then fun = n * fun(n - 1) Else fun = 1 End If End Function Dim a As Integer For i = 3 To 4 a = fun(i) Print a, Next i 9 Function Fun(a As Integer) Static c c = c * 2 + 1 / 4 Fun = a + c End Function Dim a As Integer a = 10 For i = 1 To 2 Print Fun(a); Next i 230

6 1 2 3 4 Visual Basic 5 Sub Main 6 DoEvents 6.1 6.1.1 1. 1 Load Load Load Form_Load Load Name 2 Unload Unload Load Form_QueryUnload 3 Show

Visual Basic [. ] Show [ ] Show Show Show 0 1 0 1 vbmodal 0 4 Hide [. ] Hide Hide Hide Unload Unload 2. 6.1 6.1 6.1 Name Caption StartUpForm Form1 1 6-1 6.2 Label1 6.3 6-2 6.4 6.5 232

6 6-1 6.2 Name StartUpForm Caption BorderStyle 1-Fixed Single Enabled True Visible True Height 4200 Width 5200 Top 0 Left 0 MaxButton False MinButton False ControlBox False MDIChild False MDI MDI StartUpPosition 2-CenterScreen 6.3 Name Label1 Caption Alignment 2-Center Font 233

Visual Basic ForeColor &H00800000& Height 855 Width 3650 Top 1080 Left 720 6-2 6.4 Name MainForm Caption BorderStyle 2-Sizable Enabled True Visible True Height 3600 Width 4800 Top 0 Left 0 MaxButton True MinButton True ControlBox True MDIChild False MDI MDI StartUpPosition 3-Default 234

6 6.5 1 2 3 4 1 1 2 Name Caption FontSize FontName Name Caption FontSize FontName Name Caption FontSize FontName Name Caption FontSize FontName ForeColor Name Text FontSize FontName Name Caption FontSize FontName Name Caption FontSize FontName Lbl1 Lbl2 Lbl3 LblKey Arial &H000000FF& Txt1 Arial CmdCalc CmdEnd 2 6-3 235

Visual Basic 6-3 CmdCalcCmdEnd Click Click Private Sub CmdCalc_Click() LblKey.Caption = Val(Txt1.Text) * Val(Txt1.Text) Private Sub CmdEnd_Click() End Click Private Sub Form_Click() MainForm.Show Unload StartUpForm MainForm.Show Show MainForm Unload StartUpForm Unload Hide Private Sub Form_Click() 236

6 MainForm.Show If StartUpForm.Visible Then StartUpForm.Hide End If Hide StartUpForm Load Initialize Load Unload QueryUnload Unload Set = Nothing Terminate Initialize Initialize Set = Nothing Load Initialize Unload Load Initialize 6.1.2 1 1 2 1 2 2 Load A Load B Load Form_Load C D Load Load Form_Load Load D 3 A Load Form_Load B Unload Form_QueryUnload C Show 237

Visual Basic D Load Load Form_Load Unload Form_QueryUnload Show Show Show C 4StartUpForm Form_Click StartUpForm MainForm MainForm StartUpForm Private Sub Form_Click() MainForm. 1 If StartUpForm. StartUpForm. End If 2 Then 3 StartUpForm Form_Click Show MainForm Hide StartUpForm Visible Visible 1 Show 2 Visible 3 Hide 6.1.3 1 A Hide B Show C Load D Unload 2 A Hide B Show C Load D Unload 3 Show A Show B Show C Show D Show 238

6 4 A Enabled B BorderStyle C Height D Width 1 Visual Basic 6.0 1 2 2 Visual Basic 6.0 3Form_ClickStartUpForm MainForm MainForm StartUpForm Private Sub Form_Click() MainForm. 1 2 StartUpForm 4 Name Form1 Form2 Form1 Form1 Command1 Form1 Form2 Private Sub Command1 Click() 1 Form2. 2 5 6.2 6.2.1 1. 239

Visual Basic Visual Basic 6.0 1 6-4 6-5 6-4 6-5 240

6 2. 1 Visual Basic StartUpForm 6-6 StartUpForm.frm.bas 6-6 6-6.vbp 1.vbp 2 241

Visual Basic 3 Visual Basic.exe 6-6 XX.exeXX 6-6 vb1.vbp vb1.exe vb1.exe Windows 6.2.2 1 Visual Basic 6.0 Visual Basic 6.0 2 Visual Basic 6.0 1 2 1 2 3 Visual Basic 6.0 1 2 Visual Basic 1 2 4 A.frm B.vbp C.bas D.cls Visual Basic 6.0.frm.bas.cls.vbp B 242

6 6.2.3 1 A.frm B.vbp C.bas D.cls 2 A.frm B.vbp C.bas D.cls 3 A B C D Visual Basic 1 Visual Basic 1 2 3 2 Visual Basic 6.3 Visual Basic 6.3.1 Visual Basic Module Visual Basic 3 1..bas 243

Visual Basic Public Dim Private 6-7 6-8 6-7 6-8 244

6 2. Visual Basic.frm Dim Public. ( ) 3. Sub Main Visual Basic Sub Main Sub Main Sub Main Sub Main Sub Main 6-9 6-9 245

Visual Basic Visual Basic Sub Main Visual Basic Sub Main Sub Main Sub Main 4. DoEvents Visual Basic Windows Visual Basic Windows Visual Basic DoEvents Windows DoEvents DoEvents [ = ] DoEvents [ ( ) ] DoEvents 6.3.2 1 Visual Basic Module Visual Basic 3 1 2 3 1 2 3 2 1 2 3 1 2 3.bas 3 1 2 3 4 1 2 Public 3 4 Dim Private 4 1 3 1 2 3.frm 2 5 246

6 Visual Basic Visual Basic Sub Main Sub Main Sub Main Sub Main 6.3.3 1 A B Sub Main C D 2 A B Sub Main C D Public 3 A B C D 4 A B C D 5 Sub Main A B Sub Main C Visual Basic Sub Main D Sub Main 247

Visual Basic 1 1 2 2 1 2 3 3 Visual Basic 4 Visual Basic 6.4 1 2 Load Form_Load Unload Form_QueryUnload Show Hide 3 Visual Basic.vbp.bas.frm.cls.vbg 4 5 Visual Basic 6 Visual Basic.exe 7 Public 248

6 8 Dim Private 9 Sub Main Sub Main Sub Main Visual Basic Sub Main 10 Visual Basic Visual Basic DoEvents 6.5 1 Visual Basic A B Sub Main C Load D 2 A Hide B Show C Load D Unload 3 A B C Visual Basic D 4 Load A Load B Load Form_Load C Load D 5 A Load Form_Load B Show C Unload Form_QueryUnload 249

Visual Basic D Load 6 Visual Basic 6.0 A B C Sub Main D 7 Visual Basic A.vbp B.frm C.sys D.exe 1Form_ClickStartForm MainForm MainForm StartForm Private Sub Form_Click() 1. Show Unload 2 2 Visual Basic 6.0 1 2 3 Visual Basic.vbp 1 2 4 Command1 Command2 Command1 Command1 Command2 1. Enable = False 2. Enable = True 5 6 Visual Basic 6.0 7 Name Form1 Form2 Form1 Form1 Command1 Form1 Form2 250

6 Private Sub Command1 Click() 1 Me Form2. 2 8 1 2 9StartUpForm Form_Click StartUpForm MainForm MainForm StartUpForm Private Sub Form_Click() MainForm. 1 If StartUpForm.Visible Then StartUpForm. 2 End If 10 1 2 3 4 251

7 1 2 3 4 5 6 7 7.1 7.1.1 1. Visual Basic 1 Character 2 Field 4 2 3 Record Visual Basic 4 File 100 100 2. 1 Sequential File

7 Random Access File 2 ASCII ASCII ASCII File ASCII Binary File 7.1.2 1 A C B D Visual Basic Character Field Record File A 2 1 2 ASCII 3 Visual Basic 253

Visual Basic ASCII ASCII 1 2 3 ASCII 7.1.3 1 A B C D 2 A B C D 3 A B C D 4 A B C D 1 1 2 2 1 2 3 1 2 254

7 7.2 7.2.1 1. Seek Seek 1 Seek Seek #, Seek 1~511 Open 1~ 2 31 1 2 Seek Seek ( ) Seek Seek 1~ 2 31 1 2. FreeFile Fr eefile [ ] FreeFile 0 1~255 1 256~511 3. Loc Loc ( ) Loc / Loc Loc Loc 4. LOF LOF ( ) LOF Open Visual Basic 128 255

Visual Basic Visual Basic LOF 128 FileLen 5. FileLen FileLen ( ) FileLen ASCII 6. FileAttr FileAttr (, ) FileAttr 1 2 1 FileAttr 7.1 2 7.1 FileAttr 1 Input 2 Output 4 Random 8 Append 32 Binary 7. EOF EOF( ) EOF EOF True False Get True False 8. Lock Unlock Lock [#] [, /[ ] To ] Unlock [#] [, /[ ] To ] Lock Unlock Lock Unlock 256

7 1~ 2 31 1 2 15 1 7.2.2 1 A EOF LOF Lock Unlock B LOF EOF Lock Unlock C EOF LOF Unlock Lock D LOF EOF Unlock Lock EOF LOF Lock Unlock A 2 Seek A 1~255 B 1~511 C 1~ 2 15 1 D 1~ 2 31 1 Seek 1~ 2 31 1 D 7.2.3 1 Visual Basic A 255 B 511 C 512 D 256 2 Visual Basic A Seek B Skip C FreeFile D FileAttr 3 Visual Basic FileLen A B C D 4 Visual Basic A Seek B Skip C FreeFile D FileAttr 257

Visual Basic 5 Visual Basic Open A Seek B LOF C Loc D EOF 6 Visual Basic A Seek B LOF C Loc D EOF 7 Visual Basic A 128 B 256 C 512 D 1 024 1 1 2 2 EOF 3 Visual Basic 4 FreeFile 1 7.3 7.3.1 1. Visual Basic Open Open [For ] [Access ] [ ] As [#] [ Len = ] Open 258

7 1 7.2 7.2 Input Output Append Random Access Access 7.3 7.3 Read Write Read Write Append Open 7.4 7.4 Lock Shared Lock Read Lock Write Lock Read Write Read Write 259

Visual Basic [#] 1~511 Open Len= 2 15 1 512 Len 2 Output Append Input Random Binary 3 Open Open 2. Print# Write# 1 Print# Print #,[ [Spc(n) Tab(n)] [] [;,] ] Print # Open Spc(n) Tab(n) 4 4.1.1 Print# Print Print Print# Print # ;, " 260

7 Print# Print# Close Print# 2 Write# Write #, Write# Open Print# Write# 3. Input# LineInput# 1 Input# Input #, Open Input# 2 LineInput# LineInput #, 261

Visual Basic Open LineInput# Input# Input# LineInput# 3 Input$ Input$ ( n, # ) Input$ n n 2 16 1 Open 4. Close Close [ [ # ] ] [, [ # ] ] Close Visual Basic Open Close Close 7.3.2 1 c:\source1.txt 1 c:\source2.txt 2 Open Open 262

7 Open [For ] As [#] For 1 Open "c:\source1.txt" For Input As #1 2 Open "c:\source2.txt" For Output As #2 2 Visual Basic #6 Print # Print Print #,[ [Spc(n) Tab(n)] [] [;,] ] # 1~511 Spc(n) n Tab(n)n Visual Basic 6 # #6 Visual Basic Spc(n) Tab(n) Print #6, Visual Basic 3 1 2 3 Output Append Input Random Binary 1 2 Output Append 3 Input Random Binary 4 1 2 LineInput# Input# Input# LineInput# 1 Input# 2 LineInput# 5 A Write #, B Write #,using; C Print #, D Print #,using; Print# Print #,[ [Spc(n) Tab(n)] [] [;,] ] 263

Visual Basic Write# Write #, Write Print B 6 A Input # Read# B Read LineInput# C Get# LineInput# D LineInput # Input # Input# LineInput# Get VB Read D 7 A Put C Print B Get D Close Put Get Print Close D 7.3.3 1 A Put B Write C Print D Open 2 A B C D 3 Close A B C 264

7 D 4 A Write #2,name$,salary B Write #2, name$;salary C Print #2, name$,salary D Print #2, name$;salary 5 A Input# Read# B Read LineInput# C Get# LineInput# D Input# LineInput# 6 work.dat A Open "work.dat" For Output As #1 B Open "work.dat" For Append As #1 C Open work.dat" For Output As #1 D Open work.dat For Append As #1 7 Open Input A B C D 8 Print #1,str$ Print A B C D 9c:\t1.txt A F="c:\t1.txt" Open F For Input As #1 B F="c:\t1.txt" Open "F" For Input As #1 C Open "c:\t1.txt" For Output As #1 D Open c:\t1.txt For Input As #1 10 c:\t1.txt A F="c:\t1.txt" Open "F" For Append As #2 B F="c:\t1.txt" Open "F" For Output As #2 C Open c:\t1.txt For Output As #2 D Open "c:\t1.txt" For Output As #2 265

Visual Basic 1 1 newfile1.dat 2 2 newfile2.dat 3 EOF 1 LOF 2 4 1 2 Write# Input# 3 4 5 A sour.dat dest.dat Open "c:\sour.dat" For 1 As #3 Open "c:\dest.dat" For 2 As #2 While 3 Input #3, Name$, eng, phy, Math Write #2, Name$, (eng + phy + Math) / 3 Wend Close #3, #2 6 c:\stud1.txt END Private Sub Form_Load() Open "c:\stud1.txt" For Output As #1 Text1 = "" Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If 1 Then Close #1 End Else 2 Text1 = "" End If 266

7 End If 7 C stud1.txt new.txt stud1.txt Dim str1$ Open "c:\stud1.txt" For 1 As #1 Open "c:\new.txt" For Output As 2 Do While Not EOF(1) 3 Print #2, str1 Loop Close 4 5 "c:\stud1.txt " 7.4 7.4.1 n n 1 1. Type End Type Type End Type Private Type End Type 267

Visual Basic 2. Open Open [ For ] As # [ Len = ] Open Open Random Random Len= 128 Open " " For Random As # [Len= ] 3. Put Put #, [ ], Open 1~ 2 31 1 Random 4. Get Get #, [ ], Get Put 268

7 5. 7.4.2 1 A B C D Visual Basic Type End Type C 2 A C B D Type End Type Private C 3 A Type stud B Type stud id As lnteger id As Integer name As String * 10 name As String * 10 score (1 To 4) As Single score() As Single End Type End Type C Type stud D Type stud id As Integer id As Integer name As String * 10 name As String score (1 To 4) As String score (1 To 4)As Single End Type End Type Visual Basic B 269

Visual Basic score() C score() D name A A 4 Open "old.txt" For Random As # 1 Len=20. old.txt A 20 B 20 C 20 D 20 Open old.txt Open Open [ For ] As # [ Len = ] Open Random B 5 A Get,, B Get,, C Put,, D Put,, Get Get Put Put D 7.4.3 1 12 A Type person B Type person no As lnteger no As Integer name As String name As String * 10 270

7 fee(1 To 12) As Single fee () As Single End Type End Type C Type person D Type person no As Integer no As Integer name As String * 10 name As String * 10 fee (1 To 12) As String fee (1 To 3) As Single End Type End Type 2 Type stud no As lnteger name As String * 10 mark(1 To 3) As Single End Type 0301 78 88 96 A Dim s As stud B Dim s As stud stud.no=0301 s.no=0301 stud.name=" " s.name=" " stud.mark=78,88,96 s.mark=78,88,96 C Dim s As stud D Dim s As stud s.no=0301 stud.no=0301 s.name=" " stud.name=" " s.mark(1)=78 stud.mark(1)=78 s.mark(2)=88 stud.mark(2)=88 s.mark(3)=96 stud.mark(3)=96 3 Type stud no As lnteger name As String * 10 mark(1 To 3) As Single End Type 10 Dim s10(1 to 10) As Stud 3 3 271

Visual Basic A s10(3).mark(3) s10(3).name B s3.mark(3) s3.name C s10(3).mark s10(3).name D With s10(3).mark.name End With 4 stud.dat stud s A Open stud.dat For Random As #1 Put #1,1,s Close#1 B Open "stud.dat" For Random As #1 Put #1,1,s Close #1 C Open "stud.dat" For Output As #1 Put #1,1,s Close #1 D Open "stud.dat" For Random As #1 Put #1 s Close #1 5 EOF() 1 A B C D 6 1 q.dat 100 A Open "q.dat", For Input Access Read AS#1 LEN=100 B Open "q.dat", For Append Access Read AS#1 LEN=100 C Open "q.dat", For Random AS#1 LEN=100 D Open "q.dat", For Append AS#1 LEN=100 7 4 5 va A Put #4 va 5 B Put #4 5 va C Get #4 va 5 D Get #4 5 va 8 Open "source.txt" For Random As # 1 source.txt A 128 B 128 C 256 D 256 272

7 9 c:\file.txt 1 2 4 5 10 20 25 50 100 Dim InputData Open "c:\file.txt" For Input As #1 Do While Not EOF(1) Line Input #1, InputData Loop Close #1 MsgBox InputData A B 1 C 100 D 1 F1.DAT Type worker Name As String *10 Pay As Single End Type Dim work1 As worker Open "c:\f1.txt" For Random As #1 Len = Len(work1) work1.name = "LiuMin": work1.pay = 400 1 Close #1 Open "c:\f1.txt" For Random As #1 Len = Len(work1) 273

Visual Basic 2 Print "work1:l"; work1.name Print "work1:l"; work1.pay Close #1 End 2 Open 3 1 2 4 1 2 7.5 7.5.1 DriveListBox DirListBox FileListBox Visual Basic 6.0 3 7-1 7-1 Visual Basic 6.0 1. 7-2 Drive. Drive [ = ] 274

7 7-2 Drive Drive Change Change Drive1 Change Drive1_ Change() Drive 2. 7-3 7-3 Path Path 275

Visual Basic [. ]. Path [ = " " ] [. ]. Path[ = " " ] DOS = Path Path Path Change Dir1 Change Dir1_Change() 3. Path 7-4 Path File1 Change File1_Change() 7-4 1 Pattern [. ]. Pattern [ = ] Pattern Pattern *.* 276

7 Pattern Pattern Pattern Pattern Pattern_Change 2 FileName [. ] [. ] FileName [ = ] FileName 3 7.5 7.5 Multiselect Archive Hidden Normal ReadOnly System ListCount ListIndex List True False Archive Hidden Normal ReadOnly System 4. Drive_Change Drive Path Dir_Change Path Path Private Sub Drive1_Change() 277

Visual Basic Dir1.Path=Drive1.Drive ' Private Sub Dir1_Change() File1.Path=Dir1.Path ' Drive Change Drive1_Change Path Path Change Dir1_Change Path 7.5.2 1 Visual Basic 1 2 FileListBox Visual Basic DriveListBox DirListBox FileListBox 1 DriveListBox 2 DirListBox 2 Drive Visual Basic Drive Change Change Drive1 Change Drive1_Change() Change 3 1 2 Visual Basic 278

7 Path 1 2 Path 4 1 Change 2 Change 3 Change Visual Basic Drive Change Path Change 1 Drive 2 Path 3 Path 5 Private Sub Drive1_Change() 1 Private Sub Dir1_Change() 2 Drive Change Drive1_Change Dir1.Path Drive1.Drive Path Change Dir1_Change File1.Path Dir1.Path 3 1 Dir1.Path=Drive1.Drive 2 File1.Path=Dir1.Path 6 Visual Basic A List B Multiselect C Pattern D FileName Visual Basic List Multiselect True False Pattern FileName 279

Visual Basic C 7 A Drive B Name C Visible D Index Visual Basic Drive Drive Name Visible Index A 7.5.3 1 A Visual Basic Drive Change B Change C D Drive 2 Visual Basic A ReadOnly B Archive C Hidden D System 3 Visual Basic A List B Multiselect C Pattern D FileName 1 FileName 1 Path 2 2 Path Path 3 1 2 280

7 4 Pattern Pattern 1 Pattern 2 7.6 7.6.1 1. (Kill ) Kill Kill ASCII *? kill "c:\vbtest\ *.bak" c:\vbtest.bak 2. (FileCopy ) FileCopy, FileCopy ASCII FileCopy *? Visual Basic FileCopy "source.doc", "d:\vbtest\target.doc" source.doc d:\vbtest target.doc 3. (Name ) Name As 281

Visual Basic Name ASCII Name Visual Basic Name 1 Name "oldfile.txt" As "newfile.txt" oldfile.txt newfile.txt 2 Name "c:\vbtest\oldfile.txt" As "c:\vbtest\ex\oldfile.txt" c:\vbtest oldfile.txt c:\vbtest\ex 3 Name "c:\vbtest\oldfile.txt" As "c:\vbtest\ex \newfile.txt" c:\vbtest oldfile.txt c:\vbtest\ex newfile.txt 4 Name "c:\vbtest" As "c:\vbtestnew" c:\vbtest c:\vbtestnew 4. Shell Shell ( [, ] ) Shell ASCII 7.6 7.6 vbhide 0 vbnormalfocus 1 282

7 vbminimizefocus 2 vbmaximizefocus 3 vbnormalnofocus 4 vbminimizenofocus 6 7.6.2 1 DriveListBox DirListBox FileListBox 3 Kill DriveListBox DirListBox FileListBox Kill File1.Path File1.FileName File1.Path + "\" + File1.FileName 2 file1.copy param1, param2 A file1 File Folder B param1 C param1 D param2 param1 parame2 True False True B 3 FileCopy A B C *? D Visual Basic FileCopy 283

Visual Basic FileCopy FileCopy ASCII FileCopy *? Visual Basic C 7.6.3 1 Kill VB A B C D 2 Name A Name B C D Visual Basic 3 Shell A Shell B C vbhide D vbhide 4 file1.copy param1, param2 A file1 File Folder B param1 C param1 D param2 5 Sub ShowFileInfo(filespec) Dim fs f,s Set fs =CreateObject( Scripting.FileSystemObject ) Set f =fs.getfile(filespec) s=f.datecreated MsgBox s 284

7 A filespec B C D 1 C vbtest 2 d:\vbtest source.doc target.doc 3 c:\vbtest oldfile.txt c:\vbtest\ex 4 c:\vbtest c:\vbtestnew 5 c:\vbtest run.exe 7.7 Visual Basic 1 Visual Basic CharacterField Record File 2 Sequential File Random Access File ASCII ASCII File Binary File 3 Seek Seek FreeFile Loc / LOF Open 285

Visual Basic FileLen FileAttr EOF Lock Unlock 4 Visual Basic Open Print# Write# Input# LineInput# Close 5 Type End Type Open Put Get 6 DriveListBox DirListBox FileListBox 7 Kill FileCopy Name Shell 7.8 1 Visual Basic A Add B AddItem C AddString D AddObject 2 286

7 Dim fs As New FilesystemObject,f As File C text.txt A f=fs.get File("c:\text.txt") B Set f=fs.get File("c:\text.txt") C f=fs.getfile("text.txt") D Set f=fs.getfile("text.txt") 3 A B ASCII C D 4 A B C ASCII D 5 A B C D 6 Visual Basic A Archive B ReadOnly C Hidden D System 7 A Write # 1, math,eng B Write # 1, math;eng C Print # 1,math,eng D Print # 1, math;eng 8 FileCopy A B C *? D Visual Basic 9 A Input # B Read # C LineInput # D Get # 10 Open "old.txt" For Random As # 1 Len=50.old.txt A 50 B 50 C 50 D 50 11 Visual Basic A List B Multiselect 287

Visual Basic C Pattern 12 D FileName Type Student no As Integer name As String * 10 score(1 To 4) As Integer End Type Dim stu1 As Student A B C D 13 A Put,, B Put,, C Get,, D Get,, 1 c:\vbtest oldfile.txt c:\vbtest\ex newfile.txt 2 Visual Basic 1 2 3 Private Sub Drive1_Change() 1 Private Sub Dir1_Change() 2 4 FileCopy 1 *? 2 Visual Basic d:\vbtest old.doc new.doc 3 288

7 5 Visual Basic 6 Visual Basic 7 Visual Basic 1 2 8 Visual Basic 1 2 Open 9 1 2 10 Visual Basic 1 2 3 4 5 6 11 Drive 1 2 3 289

A 1. Visual Basic 2. Visual Basic 3. 4. Visual Basic Visual Basic 1 Visual Basic 2 Visual Basic 3 1 2 4 1 2 1 1 Visual Basic 2 2 1 2 3 1 2

A 4 5 1 1 2 3 2 1 2 3 3 4 1 2 3 1 1 Print 2 Print Tab Spc Space $ 3 Format $ 2 InputBox 3 MsgBox MsgBox 4 5 1 2 1 1 2 2 1 2 3 291

Visual Basic 3 4 5 6 7 8 9 Tab 1 1 2 3 IIf 2 3 For 4 5 Do 6 7 GoTo 1 GoTo 2 On-GoTo 1 1 2 2 1 2 ForEach Next 3 3 1 Sub 1 Sub 2 Sub 3 2 Funtion 292

A 1 Funtion 2 Funtion 3 1 2 3 4 4 5 1 2 1 2 1 2 3 3 4 5 6 7 1 2 3 Visual Basic 1 2 3 SubMain 4 DoEvents 1 KeyPress 2 KeyDown KeyUp 3 4 293

Visual Basic 5 1 2 3 1 2 4 1 2 3 5 1 2 6 1 90 2 90 3 1 2 3 294

B 2 Visual Basic 2.1.3 1 C 2 A 3 A 4 D 5 D 6 B 7 C 8 B 9 C 10 D 11 B 12 C 13 D 14 D 15 B 16 A 17 C 18 B 19 A 20 D 1 2 1 2 3 3 4 1 2 5 1 Hide 2 Show 2.2.3 1 D 2 A 3 C 4 C 5 A 6 C 7 C 8 D 9 A 10 B 11 A 12 C 13 A 14 C 15 A 16 D 17 B 18 A 19 A 20 B 21 B

Visual Basic 1 1 2 SetFocus 2 Text 3 1 2 Min 3 Max 4 Tab 5 900 6 1 Command1.Enabled=True 2 Command1.Enabled=False 7 1 5 6 25 76 2.3.3 1 A 2 D 3 A 4 A 5 B 6 C 7 C 8 C 9 C 1 1 2 2 6 3 1 2 4 5 6 7 3 Visual Basic 3.1.3 1 C 2 A 3 B 4 C 5 B 6 B 296

B 1 1.frm 2.vbp 2 3 1 2 3 4 5 4 1 2 3 4 5 Debug.Print 3.2.3 1 D 2 B 3 A 4 C 5 B 6 B 7 B 8 D 9 B 10 C 11 A 12 C 13 B 1 2 2 4 3 4 1 2 64 3 4 5 6 6 1 As Single 2 As Date 7 a b= 22.5 8 End Type 3.3.3 1 A 2 D 3 B 4 B 5 C 6 B 7 B 8 B 9 C 10 A 1 1 Dim Static 2 Dim Private 3 Public Global 2 Option Explicit 3. 4 1 Dim 2 Static 5 1 # 2 $ 3 % 297

Visual Basic 6 1 2 3.4.3 1 C 2 B 3 C 4 B 5 D 6 A 7 D 8 C 9 D 10 A 11 B 12 C 13 C 14 B 15 A 16 C 17 D 18 A 19 C 20 B 1 8 2 3 3 1 4 (2*x^3+LOG(Abx(X 1))/2) 5 3 6 0 7 Good evening! 8 INT(100*x+0.5)/100 9 a 10 2*(1+Log(3*X)) 11 "xyz123abc" 12 True 13 57.9 a b 14 2 x (1 + x e ) 15 9 3.5.3 1 D 2 B 3 B 4 B 5 A 6 D 7 C 8 D 9 C 10 B 11 C 12 C 13 A 14 C 15 D 16 C 17 B 18 A 19 C 20 C 21 D 22 A 23 C 24 C 25 A 298

B 26 A 1 2 CBC 3 17 4 25 5 16 6 51 7 24 8 6 9 Int((Rnd * 6) + 1) 10 This is a book. 11 25 3.6.3 1 A 2 B 3 B 4 A 5 B 6 B 7 B 8 B 9 B 10 A 11 B 12 C 13 B 14 D 15 B 1 20 2 1 2 3 6 3 Good 4 4.4 5 x < 8 4 4.1.3 1 B 2 A 3 A 4 A 5 D 299

Visual Basic 6 C 7 B 8 C 9 D 10 B 11 A 1 Tab(3*j) 2 1 "000,000.00" 2 "###,###.##" 3 1 : 2 ; 3, 4.2.3 1 C 2 A 3 D 4 D 1 1 InputBox 2 t*j 2 N=9 S=1 022 3 1 Y=25 2 Y = 25 4 1 5 2 hello 4.3.3 1 B 2 C 3 A 4 C 5 D 6 C 7 A 1 CommonDialog1.ShowColor 2 Flags 3 1 TabStrip 2 ProgressBar 3 Slider 5 5.1.3 300 1 A 2 B 3 C 4 B 5 D

B 6 B 7 C 8 A 9 D 10 D 11 C 12 D 1 1 Call 2 1 2 3 24 3 4 32 2 5.2.3 1 C 2 B 3 B 4 A 5 A 6 C 7 D 8 C 1 3 1 2 24 120 3 10 4 11 12 13 5 1 0 0 0 1 0 5.3.3 1 A 2 C 3 D 4 D 1 1 2 2 vbtest2(a,b) 3 1 Optional 2 IsMissing 3 4 Variant 4 ParamArray 5 1 2 301

Visual Basic 5.4.3 1 B 2 A 3 D 4 D 5 C 6 A 7 D 1 TextBox 2 1 2 3 1 DragMode 2 Drag 3 DragDrop 4 DragOver 4 MousePointer 6 6.1.3 1 A 2 D 3 D 4 B 1 1 Unload 2 Show 2 Caption 3 1 Show 2 Unload 4 1 Unload Me 2 Show 5 Initialize 6.2.3 1 C 2 A 3 C 302

B 1 1 Form1.frm 2 Module1.bas 3 1.vbp 2.exe 6.3.3 1 D 2 B 3 D 4 A 5 C 1 1 Dim 2 2 1 2 Public 3. ( ) 3 Sub Main 4 DoEvents 7 7.1.3 1 B 2 D 3 D 4 B 1 1 2 2 1 2 3 1 2 7.2.3 1 B 2 A 3 B 4 D 5 B 6 D 7 A 303

Visual Basic 1 1 Lock 2 Unlock 2 1 True 2 Unlock 3 128 4 256~511 7.3.3 1 D 2 D 3 C 4 B 5 D 6 B 7 A 8 A 9 A 10 D 1 Open "newfile1.dat" For Output As #1 2 Open "newfile2.dat" For Input As #2 3 1 2 4 1 Open 2 Print# 3 LineInput# 4 Close 5 1 Input 2 Output 3 Not EOF 6 1 UCase(Text1)="END" 2 Print #1,Text1 7 1 Input 2 #2 3 Line Input #1, str1 4 #1, #2 5 Kill 7.4.3 1 C 2 C 3 A 4 B 5 B 6 C 7 D 8 B 9 C 1 1 Put #1, 1, work1 2 Random 3 1 Type End Type 4 1 Put 2 Get 2 Get #1, 1, work1 2 128 304

B 7.5.3 1 B 2 A 3 A 1 1 2 2 3 1 Drive1_Change 2 Dir1_Change 4 1 *.* 2 Pattern_Change 7.6.3 1 D 2 D 3 D 4 B 5 D 1 kill "c:\vbtest\ *.txt" 2 FileCopy " d:\vbtest\source.doc", " target.doc" 3 Name "c:\vbtest\oldfile.txt" As "c:\vbtest\ex\oldfile.txt" 4 Name "c:\vbtest" As "c:\vbtestnew" 5 Shell "c:\vbtest\ run.exe ",1 305

C 1 Visual Basic 1.6 1 A 2 D 3 D 4 B 5 D 6 C 7 B 8 A 9 D 10 B 11 A 12 C 13 B 1 1 2 3 2 1 2 3 1 2 4 ADO 5 F10 6 7 1.vbp 2.vbg 8 1 9 1 Shift+F7 2 Ctrl+R 3 Ctrl+G 2 Visual Basic 2.5

C 1 C 2 B 3 D 4 B 5 C 6 C 7 A 8 D 9 C 10 C 11 B 12 A 13 A 14 D 15 B 16 B 17 B 18 B 19 C 20 C 21 C 22 A 23 B 1 1 2 3 2 Text1 3 Timer 4 1 2 3 5 6 Sa&ve 3 Visual Basic 3.8 1 A 2 A 3 B 4 D 5 A 6 B 7 B 8 B 9 B 10 D 11 B 12 D 13 C 14 B 15 B 16 B 17 D 18 A 19 C 20 B 21 A 22 D 1 11 13 17 19 2 1 GoTo Lp 2 i 3 m 3 1 Ltrim() 2 Rtrim() 3 Trim() 4 1 Debug 2 Print 5 1 Ucase() 2 Lcase() 6 1 End 2 Stop 7 1 F5 2 Ctrl+Break 3 Shift+F5 8 1 Asc(x$) 2 Str$(x) 3 Val(x$) 307

Visual Basic 4 4.5 1 B 2 A 3 A 4 B 5 B 6 D 1 1 57 2 33 2 20 3 2 4 1 n Mod i n/i=n\i Int(n/i)=n/I 2 flag =0 5 (1) 1 To m (2)Mid 6 12.3+12.3 7 45 8 97 9 1 10 1 8 2 3 3 11 11 The Length Visual Is 6 12 1 Val 2 Val 13 CommonDialog1. Action=3 3 MsgBox 5 5.6 1 C 2 A 3 B 4 C 5 C 6 C 7 A 8 B 9 B 10 B 11 A 308

C 1 1 1 2 3 4 2 2 4 6 8 2 1 20 2 55 3 1 Fun = p 2 Fun(t) 4 a(5)=25 b(5)=25 5 3.5 5 6.5 6 Exit Sub 7 3 20 5 8 6 24 9 10.25 10.75 6 6.5 1 B 2 A 3 D 4 C 5 B 6 D 7 D 1 1 MainForm 2 StartForm 2 1 2 3 1 1.vbp 2 4 1 Command1 2 Command2 5 Initialize 6 Me 7 1 Unload 2 Show 8 1 2 9 1 Show 2 Hide 10 1 2 Public 3 4 Dim Private 309

Visual Basic 7 7.8 1 A 2 A 3 A 4 C 5 A 6 A 7 B 8 C 9 D 10 B 11 D 12 A 13 B 1 Name "c:\vbtest\oldfile.txt" As "c:\vbtest\ex\newfile.txt" 2 1 FileName 2 Pattern 3 1 Dir1.Path=Drive1.Drive 2 File1.Path=Dir1.Path 4 1 2 3 FileCopy " d:\vbtest\old.doc", "new.doc" 5 Shell 6 Kill 7 1 Seek 2 Seek 8 1 FileLen 2 LOF 9 1 2 Type End Type 10 1 Open 2 Print# Write# 3 Put 4 Input# LineInput# 5 Get 6 Close 11 1 Change 2 Drive1 3 Drive1_Change() 310

D Visual Basic 2002 90 100 ( 2 70 ) A B C D 1 A B C D 2 A Name B Name C Name D Name 3 EXE A B C D 4 Dim TestDate As Date TestDate A TestDate=#1/1/2002# B TestDate=#"1/1/2002"#

Visual Basic C TestDate=date("1/1/2002") 5 D TestDate=Format("m/d/yy","1/1/2002") Dim X As Intenger Sgn(X) 1 X A B 0 C 0 D 0 6 Command1 Static X As Integer Static Y As Integer Cls Y=1 Y=Y+5 X=5+X Print X,Y Command1 A 15 16 B 15 6 C 15 15 D 5 6 7 a=3 b=5 A a>=b And b>10 B (a>b)or(b>0) C (a<0)eqv(b>0) D ( 3+5>a)And(b>0) 8 x=inputbox(" " "0" " ") 10 A X 10 B InputBox C 0 D X 10 9 str1 str2 A Left B Mid C String D Instr 10 a="visual Basic" b="basic" 312

D A b=left(a,8,12) B b=mid(a,8,5) C b=right(a,8,12) D b=left(a,8,5) 11 Change A B C D 12 TextTime Timer1 Private Sub Timer1_ () TxtTime.text=Time A Enabled B Visible C Interval D Timer 13 Option1 Option2 Check1 Text1 Text A Option1.Value=True B Option1.Value=True Check1.value=False Check1.value=True C Option1.Value=False D Option1.Value=True Check1.value=True Check1.value=1 14 Esc Click True A Value B Default C Cancel D Enabled 15 Command1 313

Visual Basic For I=1 To 4 For J=0 To I Print Chr$(65+I) Next J Print Next I A BB B A C B D AA CCC BB CC BBB DDDD CCC DDD CCCC EEEEE DDDD EEEE DDDDD 16 A Autosize B Stretch C AutoRedraw D Appearance 17 Text1 Text2 Command1 Dim x As integer, n As Integer x=1 n=0 Do While x<20 x=x*3 n=n+1 Loop Text1.Text=Str(x) Text2.Text=Str(n) A 15 1 B 27 3 C 195 3 D 600 4 18 Text1 Command1 314 Dim I As Integer, n As Integer

D For I= 0 To 50 I=I+3 n=n+1 if I>10 Then Exit For Next Text1.Text=Str(n) A 2 B 3 C 4 D 5 19 Text1 Command1 Dim array1(10,10) As Integer Dim I, j As Integer For I=1 To 3 For j=2 To 4 array(i,j)=i+j Next j Next I Text1.Text=array1(2,3)+array1(3,4) A 12 B 13 C 14 D 15 20 Command1 Dim I As integer, j As integer Dim a(10,10) As integer For I=1 To3 For j=1 To 3 a(i,j)=(i-1)*3+j print a(i,j) Next j print Next I 315

Visual Basic A 123 B 234 C 147 D 123 246 345 258 456 369 456 369 789 21 Option Base 0 Private Sub Form1_Click() Dim a Dim I As Integer a=array(1,2,3,4,5,6,7,8,9) For I=1 To3 print a(5-i); Next A 4 3 2 1 B 5 4 3 2 C 6 5 43 D 7 6 5 4 22 A Form_Load B C Sub D 0 23 Command1 F1 F1 F1 1 0 A x=inputbox("") a=f1(val(x)) print a Function F1(ByteRef b As Integer) If b Mod 2 =0 Then Return 0 Else 316

D Return 1 End If End Function B x=inputbox("") a=f1(val(x)) print a Function F1(ByteRef b As Integer) If b Mod 2 =0 Then F1= 0 Else F1=1 End If End Function C x=inputbox("") a=f1(val(x)) print a Function F1(ByteRef b As Integer) If b Mod 2 =0 Then F1=1 Else F1= 0 End If End Function D x=inputbox("") a=f1(val(x)) print a Function F1(ByteRef b As Integer) If b Mod 2 =0 Then Return 1 Else Return 0 End If End Function 317

Visual Basic 24 Text1 Command1 Dim x,y,z As Integer x=5 y=7 z=0 Text1.Text="" Call P1(x,y,z) Text1.Text=Str(z) Sub P1(ByVal a As Integer, ByVal b As Integer,c As Integer) c=a+b A 0 B 12 C Str(z) D 25 A Static Static B Sub Sub C Sub Sub D 26 A KeyUp KeyDown A a KeyCode B KeyUp KeyDown 11 KeyCode C Keypress D Keypress 27 A B & C Visiable D 28 menu1 A menu1.enabled=true B menu1.enabled=false 318

D C menu1.visible=true D menu1.visible=false 29 A B ShowOpen ShowSave C ShowOpen D ShowColor 30.txt A "text(.txt) (*.txt)" B " (.txt) (.txt)" C "text(.txt) (*.txt)" D "text(.txt)(*.txt)" 31 A Sub Main B Show C Hide Unload D 32 A B Private C VB D 33 Type Books Name As String *10 TelNum As String *20 End Type A Dim B As Books Open "c:\person.txt" For Output As #1 B.Name = InputBox(" ") B.TelNum=InputBox(" ") 319

Visual Basic Write #1, B.Name, B.TelNum Close #1 B Dim B As Books Open "c:\person.txt" For Output As #1 B.Name = InputBox(" ") B.TelNum=InputBox(" ") Print #1, B.Name, B.TelNum Close #1 C Dim B As Books Open "c:\person.txt" For Output As #1 B.Name = InputBox(" ") B.TelNum=InputBox(" ") Write #1, B Close #1 D Dim B As Books Open "c:\person.txt" For Output As #1 B.Name = InputBox(" ") B.TelNum=InputBox(" ") Write #1, Name, TelNum Close #1 34 A B C Open D Input# 35 Path A B C 320

D D ( 2 30 ) 1 15 1 Lable1 Lable2 Caption HScroll Min 0 Max 100 Lable2 1 2 Private Sub HScroll1 1 () Lable2.Caption=Hscroll1. 2 2 Command1 Text1 Text2 4 Lable1 Lable2 Lable3 Lable 4 1 2 4 Option1 + * / Text1 Text2 Lable4 3 4 5 For i=0 To 3 321

Visual Basic If 3 =True Then opt=option1(i).caption End If Next Select Case 4 Case "+" Result=Val(Text1.Text)+Val(Text2.text) Case "-" Result=Val(Text1.Text)-Val(Text2.text) Case "*" Result=Val(Text1.Text)*Val(Text2.text) Case "/" Result=Val(Text1.Text)/Val(Text2.text) End Select 5 =Result 3 Command1 Command1 Command1 6 Private Sub Form1_Load() Command.Enabled=False Private Sub Text1_ 6 () Command.Enabled=True 4 pmenu Form1. 7 pmenu 5 8 9 Private Sub Form1_Click() Dim x As Single,amax As Single,amin As Single x=inputbox("enter a score") amax=x amin=x 322

D Do While 8 If x>amax Then amax=x End If If 9 Then amin=x End If x=inputbox("enter a score") Loop Print "Max=";amax,"Min=";amin 6 Private Sub Form1_Click() Text1.Text=" " Private Sub Text1_Change() Picture1.Print" " 10 11 7 Command1 Function M(x As Integer,y As Integer) As Integer M=IIF(x>y,x,y) End Function Dim a As Integer,b As Integer a=100 b=200 Print M(a,b) 12 8 13 9 Lable1 List1 Lable1 14 15 323

Visual Basic Private Sub Form_Load() List1.AddItem " " List1.AddItem " " List1.AddItem " " Private Sub 14 () Label1.Caption= 15 324

D Visual Basic 2002 1 C 2 A 3 C 4 A 5 D 6 B 7 B 8 D 9 D 10 B 11 D 12 D 13 D 14 C 15 A 16 B 17 B 18 B 19 A 20 D 21 C 22 C 23 B 24 B 25 D 26 D 27 A 28 D 29 C 30 A 31 C 32 B 33 A 34 B 35 A 1 1 Change _Change 2 Value 2 3 Option1(i).Value 4 opt 5 Lable4.Caption Form1. Lable4.Caption Me. Lable4.Caption Command1.Parent. Lable4.Caption 3 6 Change _Change 4 7 PopupMenu 5 8 x>=0 9 x<amin x<=amin amin>x amin>=x 6 10 11 7 12 200 8 13 Interval 9 14 List1_DblClick Form1. List1_DblClick Me. List1_DblClick 15 List1 List1.Text Form1. List1 Form1.List1.Text Me. List1 Me.List1.Text 325

Visual Basic Visual Basic 2003 90 100 (1~20 2 21~30 3 70 ) A B C D 1 A.bas B.res C.frm D.ocx 2 A UnloadForm1 Form1 B Load C Enable False D Height Width 3 Visual Basic A A#A B 4A C?XY D consta 4 Type Student number As String name As String age As String End Type A Student.name=" " B Dim s As Student s.name=" " C Dim s As Type Student s.name=" " D Dim s As Type 326

D s.name=" " 5 String(n,"str") A B n C n D n 2 2 6 cos ( a + b ) + 5e Visual Basic A Cos(a+b)^2+5*exp(2) B Cos^2 (a+b) +5*exp(2) C Cos(a+b)^2+5*ln(2) D Cos^2 (a+b) +5*ln(2) 7 Command1 a$="software and hardware" b$=right(a$,8) C$=Mid(a$,1,8) MsgBox a$,,b$,c$,1 A software and hardware B software C hardware D 1 8 a=inputbox("today","tomorrow","yesterday",,,"",5) A Today B Tomorrow C Yesterday D Day Before Yesterday 9 A Max B LargeCharge C Value D Max-Min 10 List1 Lable1 A Private Sub List1_Click() Lable1.Caption=List1.ListIndex 327

Visual Basic B Private Sub List1_Click() Lable1.Name=List1.ListIndex C Private Sub List1_Click() Lable1.Name=List1.Text D Private Sub List1_Click() Lable1.Caption=List1.Text 11 Command1, Private Sub Command_Click() x=0 n=inputbox("") For i=1 To n For j =1 To i x=x+1 Next j Next i Print x, 3 A 3 B 4 C 5 D 6 12 A B Enabled False C D 13 chkoption. A Tag B Index C ListIndex D Name 14 Command1 328

D Option Base 0 Private Sub Command_Click() Dim city AsVariant city=array(" "," "," "," ") Print city(1),, A B C D 15 Function Fun(S As String)As String Dim s1 As String For i=1to Len(S) s1= UCase(Mid(S,i,1))+s1 Next I Fun =s1 End Function Private Sub Commandl_Click() Dim Strl As String,Str2As String Str1=InputBox(" ") Str2=Fun(Str1) Print Str2 "abcdefg" " " A abcdefg B ABCDEFG C gfedcba D GFEDCBA 16 Open "c:/" For Output As #1 A C Test.Dat B C Test.Dat C 1 329

Visual Basic D, Print # Test.Dat 17 A Shell Windows B Shell, Visual Basic C Shell =Shell( ) D Shell DOS 18 A B " " C D 19 TxtA Private Sub TxtA_KeyPress(keyascii as Integer) KeyPress A B C D 20 Path A B C D 21 Private Sub Form_MouseDown(Button As Integer,Shift As Integer,X As Single, Y As Single) If Button=2 Then PopupMenu popform End If A B popform C X Y 330

D D Button=2 22 n! A n=5 x=1 Do x=x*i i=i+1 Loop While i<n Print x B n=5 x=1 i=1 Do x=x*i i=i+1 Loop While i<n Print x C n=5 x=1 i=1 Do x=x*i i=i+1 Loop While i<=n Print x D n=5 x=1 i=1 Do x=x*i i=i+1 Loop While I>n Print x 23 Command1 Lable1 Lable2 331

Visual Basic Private X As Integer X=5 Y=3 Call proc(x,y) Label1.Caption=X Label2.Caption=Y Private sub Proc(ByVal a As Integer,ByVal b AS Integer) X=a *a Y=b +b, A 5 3 B 25 3 C 25 6 D 5 6 24 Command1 Lable1 s=0 For i= 1 To 15 x=2*i 1 If x Mod 3 = 0 Then s=s+1 Next i Lable1.Caption=s, A 1 B 5 C 27 D 45 25 Command1 3 Label1 Label2 Label3 Private x As Integer Static y As Integer Dim z As Integer n=10 z=n+z y=y+z 332

D x=x+z Label1.Caption=x Label2.Caption=y Label3.Caption=z 3 3 A 10 10 10 B 30 30 30 C 30 30 10 D 10 30 30 26 Command1 Static b As Variant b=array(1,3,5,7,9) b 5 9,7,5,3,1 A For i=0 To 5-1\2 Tmp=b(i) b(i)=b(5-i-1) b(5-i-1)=tmp Next B For i=0 To 5 Tmp=b(i) b(i)=b(5-i-1) b(5-i-1)=tmp Next C For i=0 To 5\2 Tmp=b(i) b(i)=b(5-i-1) b(5-i-1)=tmp Next D For i=1 To 5\2 Tmp=b(i) b(i)=b(5-i-1) 333

Visual Basic b(5-i-1)=tmp Next 27 Drive1 Dir1 File1 Label1 Label2 Label1 334 A Private Sub Dir1_Change() File1.Path=Dir1.Path Private Sub Drive1_Change() Dir1.Path=Drive1.Drive Label1.Caption=File1.ListCount B Private Sub Dir1_Change() File1.Path=Dir1.Path Private Sub Drive1_Change() Dir1.Path=Drive1.Drive Label1.Caption=File1.List C Private Sub Dir1_Change() File1.Path=Dir1.Path Label1.Caption=File1.ListCount

D Private Sub Drive1_Change() Dir1.Path=Drive1.Drive D Private Sub Dir1_Change() File1.Path=Dir1.Path Label1.Caption=File1.List Private Sub Drive1_Change() Dir1.Path=Drive1.Drive Label1.Caption=File1.List 28 Form1 Form2 mdlfunc Form1 Form2 mdlfunc Form1 Private Sub frmfunction1() Form2 Public Sub frmfunction2() mdlfunc Public Sub mdlfunction() A 3 B frmfunction2 mdlfunction C 3 D mdlfunction 29 Text1 Text2 Command1 335

Visual Basic Type Person name As String*8 major As String*20 End Type Test29.dat person p A Open "c: Test29.dat" For Random As #1 Put #1,1,p Close #1 B Open "c: Test29.dat" For Random As #1 Get #1,1,p Close #1 C Open "c: Test29.dat" For Random As #1 Len=Len(p) Put #1,1,p Close #1 D Open "c: Test29.dat" For Random As #1 Len=Len(p) Get #1,1,p Close #1 30 CommonDialog1 Command1 Save SaveFile *.txt A 336

D CommandDialog1.FileName="SaveFile" CommandDialog1.Filter="All Files *.* (*.txt) *.txt (*.doc) *.doc" CommandDialog1.FilterIndex=2 CommandDialog1.DialogTitle="Save" CommandDialog1.Action=2 B CommandDialog1.FileName="SaveFile" CommandDialog1.Filter="All Files *.* (*.txt) *.txt (*.doc) *.doc" CommandDialog1.FilterIndex=1 CommandDialog1.DialogTitle="Save" CommandDialog1.Action=2 C CommandDialog1.FileName="Save" CommandDialog1.Filter="All Files *.* (*.txt) *.txt (*.doc) *.doc" CommandDialog1.FilterIndex=2 CommandDialog1.DialogTitle="SaveFile" CommandDialog1.Action=2 D CommandDialog1.FileName="SaveFile" CommandDialog1.Filter="All Files *.* (*.txt) *.txt (*.doc) *.doc" CommandDialog1.FilterIndex=1 CommandDialog1.DialogTitle="Save" CommandDialog1.Action=1 ( 2 30 ) 1 ~ 15 1 Visual Basic 1 2 Visual Basic 2 3 S 3 S =5 For i=2.6 To 4.9 Step 0.6 337

Visual Basic S =S +1 Next i 4 d:\pic a.jpg Picture1 4 5 5 6 z 20 200~300 5 For i=1to 20 x=int( 6 *200+100) If 7 =0 Then Print x S =S + 8 End If Next i Print "Sum=";S 7 Private Sub Form_Click() Dim a As Integer, b As Integer a=20: b=50 p1 a,b p2 a,b p3 a,b print "a=";a,"b=";b Sub p1(x As Integer,ByVal y As Integer) x=x+10 y =y +20 Sub p2(byval x As Integer,yAs Integer) x=x+l0 y =y +20 Sub p3(byval xas Integer, ByVal y As Integer) x=x+l0 338

D y=y+20,, a= 9 b= 10 8 Command1 Dim a As String a= 11 For i=1 To 5 Print Space(6-i);Mid$(a,6-I,2*i-1) Next i,, 5 4 56 34 567 23 456 789 9 Combo1 Label1 Label2 Caption ASCII 13 Label2 Label2 12 13 14 Private Sub Combo1 12 (KeyAscii As Integer) If KeyAscii = 13 Then For i=0 To Combo1.Listcount 1 If Combo1.Text= 13 Then 339

Visual Basic Label2.Caption=" " Exit Sub End If Next i Label2.caption=" " Combo1. 14 Combo1.Text End If 10 Private Sub search(a() As Variant,ByVal key As Variant,index%) Dim i% For i = Lbound(a) To Ubound(a) If key = a(i) Then index= i Exit Sub End If Next i index = -1 Private Sub Form_Load() Show Dim b() As Variant Dim n As Integer b=array(1,3,5,7,9,11,13,15) Call search(b,11,n) Print n 15 340

D Visual Basic 2003 1 D 2 A 3 D 4 B 5 B 6 A 7 C 8 C 9 A 10 D 11 D 12 B 13 B 14 D 15 D 16 A 17 B 18 C 19 D 20 A 21 D 22 C 23 B 24 B 25 C 26 C 27 C 28 D 29 C 30 A 1 1 2 2 3 3 9 4 4 Picture1.Picture=LoadPicture( d:\pic\a.jpg ) Picture1=LoadPicture( d:\pic\a.jpg ) 5 5 Timer 6 6 Rnd Rnd(n) n 7 x Mod 5 Int(x/5) x/5 x/5 Int(x/5) CInt(x/5) x/5 x/5 CInt(x/5) Round(x/5)-x/5 x/5 Round(x/5) x (x\5)*5 (x\5)*5 x Fix(x/5) x/5 x/5 Fix(x/5) 8 x 7 9 30 10 70 8 11 123 456 789 9 12 Keypress 13 Combo1.List(i) 14 AddItem 10 15 5 341

E Visual Basic 90 100 ( 2 70 ) A B C D 1 Visual Basic A B C D 2 Visual Basic A ReadOnly B Archive C Hidden D System 3 A Write # 8, math,eng B Write # 8, math;eng C Print # 8,math,eng D Print # 8, math;eng 4 Load A Load B Load Form_Load C Load D 5 Visual Basic A KeyDown B KeyUp C KeyPress D KeyAscii

E 6 Sub A Static B Private C Public D Defaut 7 Sub A ByVal B ByRef C ParamArray D Optional 8 Visual Basic A MouseDown B MouseMove C MouseUp D MousePointer 9 a Dim a Sub test() a = a + 1: b = b + 1: c = c + 1 Print "Sub"; a; b; c Private Sub Form_Click() a = 2: b = 3: c = 4 Call test Print "main:"; a; b; c A Sub:3 4 5 B Sub:2 3 4 Main:3 4 5 Main:1 2 3 C Sub:4 1 1 D Sub:3 1 1 Main:4 3 4 Main:3 3 4 10 VB A Sub B Function C Property D Private 11 k = 1 For j = 1 To 10 k = k j 343

Visual Basic Next j MsgBox k \ j A 6 B 5 C 4 D 3 12 CommonDialog A ShowOpen B ShowClose C ShowColor D ShowPrinter 13 For i = 1 To 2 x = 1 For j = 1 To 3 x = 2 For k = 1 To 4 x = x + 6 Next k Next j Next i Print x A 2 B 14 C 26 D 37 14 344 x = 0 Do Until x = -1 a = InputBox(" A ") a = Val(a) x = InputBox(" X ") x = Val(x) a = a * x Loop Print a

E 12 10 15 1 A 120 C 15 15 x x + B 15 D 120 y + sin 2x Visual Basic y A SQR(x+y)/(x y)+sin(x*2) B SQR(x+y)/(x y)+sin(2x) C SQR((x+y)/(x y))+sin(x*2) D SQR((x+y)/(x y))+sin(2x) 16 a = 1234 b$ = Str(a) c = Len(b$) Print c A 4 B 5 C 6 D 7 17 a = 1.25 b = 345 c = Len(Str$(a) + Str$(b)) Text1.Text = c A 3 B 4 C 8 D 9 18 a% = 2 / 3 b% = 32 / 9 Print a%; b% 345

Visual Basic A 1 4 B 0 3 C 1 3 D 0 4 19 a$ = "AAAAAA" a$ = Mid$(a$, 2, 4) Print a$ Mid$(a$, 2, 2) = "aa" Print a$ A AaaA B AAAA C aaaa D aaaa AAAA AaaA aaaa AAAA 20 A Type B Enum C Public D Dim 21 Dim c As Long c = 2222 c& = 8888 Print c; c& A 2 222 8 888 B 2 222 2 222 C 8 888 2 222 D 8 888 8 888 22 Dim Index% A Dim Index As Long B Dim Index As Integer C Dim Index As Single D Dim Index As Double 23 Type Address Street As String ZipCode As String Phone As String End Type 346

E Dim MyHome As Address With MyHome Street = " " ZipCode = "100081" Phone = "62000000" End With Print MyHome.Phone A B 100 081 C 62 000 000 D 10 008 162 000 000 24 Type Person no As Integer name As String * 13 brith As Date salary As Single End Type Dim zhao As Person A B C D 25 a = 0 : m = 5 For i = 1 To m b = 0 For j = 1 To i a = a + 1 b = b + 2 Next j Next i Print a; b A 12 12 B 12 21 C 15 10 D 15 15 347

Visual Basic 26 Dim a(4, 4), b(4, 4) For i = 1 To 4 For j = 1 To 4 a(i, j) = i + j b(i, j) = a(i, j) + i + j Next j Next i For i = 1 To 4 For j = 1 To 4 Print Tab(4 * j); a(i, j) + b(i, j); Next j Print Next i A 3 9 12 15 B 6 9 12 15 6 9 12 15 9 12 15 18 9 9 12 15 12 15 18 21 9 12 15 18 15 18 21 24 C 3 6 12 15 D 6 9 12 15 3 6 12 15 12 15 18 21 3 12 15 18 12 18 21 24 3 15 18 24 12 15 18 24 27 a = Text1.Text If a Mod 2 = 0 Then MsgBox " " Else MsgBox " " End If 23 A 348

E B C D 28 Function fact(n) s = 0 For k = 1 To n s = s + (k + 1) * k Next k fact = s End Function A N B 1 2 2 3 3 N N C 1 2+2 3+3 4+ + N+1 N D 1+2+3+ +N 29 Dim i, MyNum Do For i = 1 To 1000 MyNum = Int(Rnd * 1000) Select Case MyNum Case 7: Exit For Case 29: Exit Do Case 54: Exit Sub End Select Next i Loop A 7 B DO 1 000 C 1 000 D 54 30 349

Visual Basic x = InputBox(x) If x Mod 3 = 0 Then y = x Mod 3 If x Mod 3 = 1 Then y = x Mod 3 If x Mod 3 = 2 Then y = x Mod 3 Print y 68 A 0 B 1 C 2 D 31 Sub ABC() Dim Number, MyString Number = InputBox(n) If Number = 1 Then GoTo L1 Else GoTo L2 L1: MyString = "Number = 1" Print MyString GoTo L3 L2: MyString = "Number < > 1" Print MyString L3: Print MyString Call ABC InputBox 35 A Number 1 B Number <> 1 Number 1 Number <> 1 C Number 1 D Number <> 1 Number <> 1 Number 1 32 For j = 8 To 35 Step 3 350

E Print j; Next j A 10 B 9 C 27 D 28 33 For i = 1 To 6 a = a + i Next i Print a A 10 C 21 34 B 15 D 28 s = 0 i = 1 While i <= 100 s = s + 1 Wend Print s A 125 B 512 C D 100 35 Visual Basic A B C D ( 2 30 ) 1 15 351

Visual Basic 1 1 k = 1 For j = 1 To 5 k = k * j Next j MsgBox k / j 2 2 BB$ = "Visual Basic 6.0" m = Len(BB$) For j = 1 To m B$ = Mid$(BB$, j, 1) If B$ = "a" Then X = X + 1 Next j MsgBox X 3 Sub vbtest2(byval x As Integer,ByVal y As Integer) Print " x=";x;" y=";y x=x+y Print " x=";x;" y=";y Sub Form_Click() Dim a As Integer, b As Integer a=5:b=6 Print " a=";a;" b=";b Call 3 Print " a=";a;" b=";b vbtest2 4 4 5 5 Name Form1 Form2 352

E Form1 Form1 Command1 Form1 Form2 Private Sub Command1 Click() 6 Me Form2. 7 6 8 9 7 Dim A(11 to 30) 10 8 s = 1 For m = 1 To 3 If m <= 1 Then a = 1 ElseIf m <= 2 Then a = 2 ElseIf m <= 3 Then a = 3 Else a = 4 End If 'Print a Sum = Sum + a Next m Print Sum; 11 9 & Save v 12 10 a$ = "Good morning!" b$ = "Even" c$ = Left$(a$, 5) + LCase$(b$) + Right$(a$, 4) 353

Visual Basic Print c$ 13 11 books no 40 name 20 score 10 brithdate Type books no As String*40 name As String*20 score1 14 brithdate 15 End Type 354

E Visual Basic 1 D 2 A 3 B 4 C 5 A 6 B 7 C 8 C 9 D 10 D 11 B 12 B 13 C 14 B 15 C 16 B 17 D 18 A 19 B 20 B 21 D 22 B 23 C 24 A 25 C 26 B 27 A 28 C 29 D 30 C 31 B 32 A 33 C 34 C 35 B 1 1 20 2 2 2 3 3 vbtest2(a,b) 4 4 5 Type End Type 5 6 Unload 7 Show 6 8 9 7 10 20 8 11 6 9 12 Sa&ve 10 13 Good evening! 11 14 As Single 15 As Date 355

Visual Basic Visual Basic 90 100 ( 2 70 ) A B C D 1 Visual Basic A B C D 2 Visual Basic A List B Multiselect C Pattern D FileName 3 Type Student no As Integer name As String * 10 score(1 To 4) As Integer End Type Dim stu1 As Student A B C D 4 A B C Visual Basic D 356

E 5 Visual Basic A MouseDown B MouseMove C MouseUp D MousePointer 6 3 Text1.Text = UCase(Text1.Text) Private Sub Command2_Click() Text1.Text = LCase(Text1.Text) Private Sub Command3_Click() Text1.Text = Text1.Tag Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) Text1.Tag = Text1.Text Abc Command1 Command2 Command3 A ABC abc ABC B ABC abc Abc C abc ABC Abc D abc ABC abc 7 Sub test(x%, y%, z%) z% = x% + y% a% = 12.5: b% = 40.2 Call test(a%, b%, c%) Print c% A 0 B 52 C 53 D 8 Sub Sub test(x As Single, y As Single) 357

Visual Basic t = x x = t + 2 y = t - 2 Dim a As Single Dim b As Single a = 10 b = 4 Call test(a, b) Print a, b A 12 8 B 10 4 C 8 6 D 12 2 9 X = 0 Do Until X = -1 A = InputBox(" A ") A = Val(A) B = InputBox(" B ") B = Val(B) X = InputBox(" X ") X = Val(X) A = A + B + X Loop Print A 5 4 3 2 1 A 2 B 3 C 14 D 15 10 358

E Sub subp(b() As Integer) For i = 1 To 3 b(i) = b(i) + i Next i Dim a(1 To 3) As Integer a(1) = 10 a(2) = 20 a(3) = 30 Call subp(a) For i = 1 To 3 Print a(i), Next i A 11 22 33 B 10 20 30 C 1 2 3 D 21 42 63 11 Combo1 Command1 a = Combo1.List(1) Print a Private Sub Form_Load() Combo1.AddItem "12" Combo1.AddItem "34" Combo1.AddItem "56" A 12 B 34 C 56 D 0 12 A LostFocus B OutFocus C Lost D Fause 13 ListBox1 359

Visual Basic Dim Entry, i, Msg Msg = "Choose OK to add 100 items to your list box." MsgBox Msg For i = 1 To 100 Entry = "Entry" & i List1.AddItem Entry Next i A AddItem 100 B AddItem 1~100 C AddItem 1~100 D AddItem 100 14 Label1 A Label1.Enabled = False B Label1.Enabled = True C Label1.Visible = True D Label1.Visible = False 15 VB ( ) A Shift+Ctrl B Shift+ C Ctrl+ D Ctrl+ 16 Txt1 A Txt1.MultiLine=True B Txt1.MultiLine=True Txt1.ScrollBars=0 Txt1.ScrollBars=3 C Txt1.MultiLine=False D Txt1.MultiLine=False Txt1.ScrollBars=0 Txt1.ScrollBars=3 17 Value A Move B Change C Scroll D GotFocus 18 Form1 A Load Form1 B Form1.Show C Form1.Hide D Unload Form1 19 3 Command1 Command2 Command3 Command2.Enabled = False Command3.Visible = False 360

E A Command1 Command2 Command3 B Command1 Command2 Command3 C Command1 Command2 Command3 D Command1 Command2 Command3 20 Combo1 Chardonnay Fun_Blanc Gewrztraminer Zinfandel Combo1 Private Sub Form_Load() Combo1.AddItem "Chardonnay" Combo1.AddItem "Fun_ Blanc" Combo1.AddItem "Gewrztraminer" Combo1.AddItem "Zinfandel" text1 A Text1.Text = Combo1.List(0) B Text1.Text = Combo1.List(1) C Text1.Text = Combo1.List(2) D Text1.Text = Combo1.List(3) 21 Visual Basic A 128 B 256 C 512 D 1024 22 a.txt A Open " a.txt " For Append As #1 B Open " a.txt " For Output As #1 C Open a.txt For Append As #1 D Open a.txt For Output As #1 23 A Dim B Public C Static D Private 24 a=6 x=iif(a>5, 1,0) x A 5 B 6 C 0 D 1 25 x x = 0 361

Visual Basic For i = 1 To 20 Step 2 x = x + i \ 5 Next i Print x A 16 B 17 C 18 D 20 26 For i = 1 To 4 x = 4 For j = 1 To 3 x = 3 For k = 1 To 2 x = x + 6 Next k Next j Next i Print x A 7 B 15 C 157 D 538 27 A My Documents B VB98 C \ D Windows 28 S 2 3 A Mid(S, 3, 2) B Mid (S, 2, 3) C MidStr(S, 3, 2) D MidStr(S, 2, 3) 29 A B C D 30 Tan 30 Visual Basic A Tan30 B Tan (30) C Tan (30 ) D Tan (30*3.14/180) 362

E 31 A ReDim Preserve A(10,Ubound(A,2)+1) B ReDim Preserve A(Ubound(A,1)+1,10) C ReDim Preserve A(Ubound(A)+1) D ReDim A((UBound)(A)+1) 32 Dim a(10) For j = 0 To 10 a(j) = j - 5 Next j Text1.Text = a(a(6)/a(10)) A 5 B 1.6 C 0 D 33 Dim a(50) For j = 0 To 10 j = j * j a(j) = j Next j Text1.Text = a(25) A 5 B 25 C 45 D 55 34 Dim a(10) For i = 1 To 10 a(i) = i ^ 2 Next i Print a(i 2) 363

Visual Basic A 64 B 81 C 99 D 100 35 Dim a(4, 4), b(4, 4) For i = 1 To 4 For j = 1 To 4 a(i, j) = i + j b(i, j) = a(i, j) + i + j Next j Next i For i = 1 To 4 For j = 1 To 4 Print Tab(4 * j); a(i, j) + b(i, j); Next j Print Next i A 3 9 12 15 B 6 9 12 15 6 9 12 15 9 12 15 18 9 9 12 15 12 15 18 21 9 12 15 18 15 18 21 24 C 3 6 12 15 D 6 9 12 15 3 6 12 15 12 15 18 21 3 12 15 18 12 18 21 24 3 15 18 24 12 15 18 24 ( 2 30 ) 1 15 1 1 2 2 364

E Private Sub Drive1_Change() 3 Private Sub Dir1_Change() 4 3 Visual Basic.vbp 5 6 4 Visual Basic 7 ByVal 8 5 N MsgBox n = InputBox(" ") k = Int(Sqr(n)) i = 2 flag = 0 Do While i <= k And flag = 0 If 9 = 0 Then flag = 1 Else i = i + 1 End If Loop If 10 Then MsgBox " ", vbokonly, " " Else MsgBox " ", vbokonly, " " End If 6 InputBox 365

Visual Basic n = InputBox(" ") m = Len(n) For j = 11 dec = dec * 2 + Val( 12 (n, j, 1)) Next j Print ""; dec 7 A = -12.3 B = 12.3 c$ = "+" d$ = Str$(A) + c$ + Str(B) MsgBox d$ 13 8 Visual Basic 14 15 366

E Visual Basic 1 B 2 D 3 A 4 D 5 B 6 B 7 B 8 A 9 A 10 A 11 B 12 A 13 A 14 D 15 B 16 B 17 B 18 B 19 C 20 C 21 A 22 A 23 B 24 D 25 A 26 B 27 B 28 B 29 B 30 D 31 B 32 D 33 A 34 B 35 B 1 1 2 2 3 Dir1.Path=Drive1.Drive 4 File1.Path=Dir1.Path 3 5 1.vbp 6 4 7 8 5 9 n Mod i n/i=n\i Int(n/i)=n/I 10 flag =0 6 11 1 To m 12 Mid 7 13 12.3+12.3 8 14 15 367

F 1 National Computer Rank Examination NCRE 2 NCRE 1994 NCRE 3 NCRE NCRE 4 NCRE NCRE Internet

F QBasic C Fortran FoxBASE+ Visual Basic Visual FoxPro PC PC PC Windows PC B B B B 5 NCRE Visual Basic Visual FoxPro 90 QBasic C Fortran FoxBASE+ 120 180 QBasic C Fortran FoxBASE+ 60 Visual Basic Visual FoxPro 90 B 90 6 NCRE NCRE Fortran Fortran 4 9 B 7 8 369

Visual Basic 9 ( ) ( ) 10 11 100~90 89~80 79~60 59~0 12 Word Excel PowerPoint Office Internet PC Pentium PC PC Windows 98 PC 370

F Internet 13 NCRE 1994 NCRE 2001 600 214 200 / 150 100 50 0 1994 1995 1996 1997 1998 1999 2000 2001 NCRE 1994 2001 14 NCRE www.neea.edu.cn www.ncre.edu.cn 371