untitled



Similar documents
VB程序设计教程

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

《Visual Basic程序设计》实验课

四川省普通高等学校

PowerPoint Presentation

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

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>

MVB-1001.DOC

穨ac3-3.PDF

穨文件1

2

Microsoft PowerPoint - OPVB1基本VB.ppt

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

SMM667.mps

untitled

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

TC35短信发送程序设计

投稿類別:電子工程類

FY.DOC

untitled

<5B BECBB0EDB8AEC1F25D312D34B0AD5FC3E2BCAEBCF6BEF7C0DAB7E F31702E504446>

untitled

( CIP).:,3.7 ISBN TB CIP (3) ( ) ISBN O78 : 3.

第5章修改稿

( ) Wuhan University

列 出 所 有 的 非 負 整 數 解, 係 數 越 大 者 越 先 決 定, 故 先 決 定 z, 再 決 定 y, 最 後 決 定 x, 故 有 = 8 ( 種 ) x y z

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

CC213

PowerPoint プレゼンテーション

Microsoft PowerPoint - Chapter5

untitled


Ps22Pdf

2007年4月全国计算机二级考试VB语言笔试真题

C/C++ - 函数

INTRODUCTION TO COM.DOC

Visual Basic AD/DA Visual Basic 2

Visual Basic D 3D

Ps22Pdf

# # #!$$% &# " # #!# "!$$!$$% # (# " # #! " # $ % # )# " # "!

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

<4D F736F F D20C1E3B5E3CFC2D4D8C4A3B0E52E646F63>

VB控件教程大全

勤 學 * 卓 越 * 快 樂 成 長 本 校 在 老 師 群 策 群 力 共 同 討 論 下, 型 塑 了 學 校 願 景 : 勤 學 卓 越 快 樂 成 長 ( 一 ) 勤 學 運 用 真 的 力 量 培 養 勤 學, 以 語 文 教 為 基 礎 紮 根 ( 二 ) 卓 越 利 用 美 的 感

C/C++ - 文件IO

untitled

IsPostBack 2

TwinCAT 1. TwinCAT TwinCAT PLC PLC IEC TwinCAT TwinCAT Masc

untitled

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

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

E. (A) (B) (C) (D). () () () (A) (B) (C) (D) (E). () () () (A) (B) (C) (D) (E). (A)(B)(C) (D) (E) (A) (B) (C) (D) (E) (A) (B)(C) (D) (E). (A) (B) (C)

untitled

<4D F736F F D20AE67BD62B6A4C1FAB0EAB2BEA661B056BD6DAAF0B0EAB3F8A7695F30372E31302E31365F2E646F63>

! #$%&# ($%&)*+!


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

方 法 和 表 征 技 术 说 清 楚 环 境 质 量 现 状 及 其 变 化 规 律 方 面 取 得 了 重 大 突 破 第 三 阶 段 十 一 五 至 十 二 五 期 间 基 于 多 环 境 要 素 环 境 质 量 综 合 评 价 的 探 索 阶 段 环 境 污 染 呈 现 更 加 复 杂 的

Ps22Pdf

: : : ( CIP ) : ( ) /. :, ISBN :. G7. 4 CIP ( 00 ) 005 : : ( ) : : ( 0 : 0004) : : : / 6 : 7 ( ) : 408 () : 00

Microsoft Word - 第3章.doc

Microsoft Word - 扉页

科学计算的语言-FORTRAN95

Microsoft Word htm

(1)(6)(e) 2

<4D F736F F D20B3CCD0F2D4B12DC9CFCEE7CCE2A3AD3037C9CF>


Ps22Pdf

多層次傳銷與獎金系統

数 学 高 分 的 展 望 一 管 理 类 联 考 分 析 第 一 篇 大 纲 解 析 篇 编 写 : 孙 华 明 1 综 合 能 力 考 试 时 间 :014 年 1 月 4 日 上 午 8:30~11:30 分 值 分 配 : 数 学 :75 分 逻 辑 :60 分 作 文 :65 分 ; 总

浦东建设

Microsoft PowerPoint - VB14.ppt

3. 給 定 一 整 數 陣 列 a[0] a[1] a[99] 且 a[k]=3k+1, 以 value=100 呼 叫 以 下 兩 函 式, 假 設 函 式 f1 及 f2 之 while 迴 圈 主 體 分 別 執 行 n1 與 n2 次 (i.e, 計 算 if 敘 述 執 行 次 數, 不

细 胞 生 物 学 荧 光 技 术 原 理 和 应 用 的 平 面 内 呈 波 形 振 动 两 个 波 峰 之 间 的 距 离 为 波 长 波 峰 的 大 小 即 为 该 光 波 的 振 幅 不 同 波 长 的 光 具 有 不 同 的 颜 色 即 光 的 波 长 不 同 光 的 颜 色 也 不 同

9,, (CIP) /. :, ISBN T U767 CI P ( 2004 ) : 122 : / mail.whut.edu.c

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

untitled

+++ 期 效 果 不 佳 因 此 建 立 接 近 人 类 肝 癌 临 床 特 征 的 动 物 模 型 对 于 观 察 体 内 生 长 和 转 移 规 律 研 究 肿 瘤 对 各 种 治 疗 的 反 应 以 及 寻 找 新 的 肝 癌 治 疗 方 法 具 有 重 要 意 义 荧 光 素 酶 $ /!

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

CA-C750К

吳元康

996,,,,,,, 997 7, 40 ; 998 4,,, 6, 8, 3, 5, ( ),, 3,,, ;, ;,,,,,,,,,

B4C2

提问袁小兵:

untitled

(Microsoft Word - Motion Program \270\305\264\272\276\363 \307\245\301\366 \271\327 \270\361\302\367.doc)

68003 (Project Unity TC)_.indb

untitled

!!" "#! #$ %& ( ) * %& * + (, ) - * (! %& * + (, ) - * (!" *#! #$ #$# ". / "$. 0 1# 2 1/ *. $ "3. 4 3# 2 3/ ). 0 *". 1 4# 2 4/ 1. 3 )0. 4 )# 2 )/ /. $

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

Chapter12 Derived Classes

untitled

<4D F736F F D DA5BFA6A1C476C1C92DBEC7ACECB8D5A8F728B57BB35D292E646F63>

Ps22Pdf

立 志 于 打 造 最 贴 近 考 生 实 际 的 辅 导 书 计 算 机 考 研 之 数 据 结 构 高 分 笔 记 率 辉 编 著 周 伟 张 浩 审 核 讨 论 群 :

單元5

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

第 期 熊 安 萍 等 *1$ 文 件 系 统 中 范 围 锁 机 制 的 应 用 研 究! 锁 命 名 空 间 '+'($($ 描 述 了 资 源 和 锁 的 集 合 它 同 时 在 客 户 节 点 和 服 务 节 点 存 在 不 同 之 处 只 是 利 用 一 个 数 据 标 识 来 有 效 区

Microsoft Word - 财务d08z.doc

Transcription:

Visual Basic

2004 Visual Basic 4 1 2004 2 3 4 2004 4 2004 9 CIP + Visual Basic /.2004 ISBN 7-03-014494-5 I. II. III. Visual Basic IV. TP312 CIP 2004 107929 16 100717 http://www.sciencep.com 2005 1 16 2005 1 20.625 * 1-5 000 502 32.00 1CD

2004 Visual Basic 4 12004 3010 5 2 Visual Basic 20022003 3 20032004 4 +2004 42004 9 2004 12

VB 1. 2. Windows 3. 4. autorun.exe 5. VB VB VB VB 5 Turbo C 2.0 VB VB 260199990001~ 260199990005 VB.doc help.hlp

1 1... 2 1.1... 2 1.1.1... 2 1.1.2... 3 1.1.3... 4 1.1.4... 5 1.1.5... 6 1.1.6... 8 1.1.7... 11 1.2... 13 1.2.1... 13 1.2.2... 15 2... 16 2.1... 16 2.1.1... 16 2.1.2... 16 2.1.3... 17 2.2... 17 2.2.1... 17 2.2.2... 18 3... 19 3.1... 19 3.1.1... 19 3.1.2... 21 3.1.3... 22 3.1.4... 22 3.1.5... 25 3.2... 25 3.2.1... 25 3.2.2... 28

2 4... 29 4.1... 29 4.1.1... 29 4.1.2... 30 4.1.3... 31 4.1.4... 32 4.2... 32 4.2.1... 32 4.2.2... 35 2 5 Visual Basic... 37 5.1... 37 5.1.1 Visual Basic... 37 5.1.2 Visual Basic... 37 5.1.3... 37 5.1.4... 38 5.2... 38 5.2.1... 38 5.2.2... 41 6... 43 6.1... 43 6.1.1... 43 6.1.2... 44 6.1.3... 45 6.1.4... 45 6.1.5... 46 6.2... 46 6.2.1... 46 6.2.2... 49 7... 51 7.1... 51 7.1.1... 51 7.1.2... 52 7.1.3... 53 7.1.4... 53

3 7.2... 54 7.2.1... 54 7.2.2... 63 8... 66 8.1... 66 8.1.1... 66 8.1.2 MsgBox MsgBox... 67 8.1.3... 68 8.1.4... 68 8.2... 69 8.2.1... 69 8.2.2... 74 9... 78 9.1... 78 9.1.1... 78 9.1.2... 79 9.1.3... 80 9.1.4... 80 9.1.5... 80 9.1.6... 82 9.1.7... 82 9.1.8... 82 9.1.9 Tab... 82 9.2... 83 9.2.1... 83 9.2.2... 90 10... 97 10.1... 97 10.1.1... 97 10.1.2... 97 10.1.3 For... 97 10.1.4... 98 10.1.5 Do... 98 10.1.6... 98 10.1.7 GoTo... 99 10.2... 99 10.2.1... 99

4 10.2.2... 108 11... 112 11.1... 112 11.1.1... 112 11.1.2... 112 11.1.3... 113 11.2... 113 11.2.1... 113 11.2.2... 122 12... 126 12.1... 126 12.1.1 Sub... 126 12.1.2 Function... 127 12.1.3... 127 12.1.4... 128 12.1.5... 128 12.2... 129 12.2.1... 129 12.2.2... 140 13... 144 13.1... 144 13.1.1 KeyPress... 144 13.1.2 KeyDown KeyUp... 144 13.1.3... 144 13.1.4... 145 13.1.5... 145 13.2... 145 13.2.1... 145 13.2.2... 150 14... 152 14.1... 152 14.1.1... 152 14.1.2... 152 14.1.3... 153 14.1.4... 153 14.2... 153 14.2.1... 153

5 14.2.2... 155 15... 157 15.1... 157 15.1.1... 157 15.1.2... 157 15.1.3... 157 15.2... 158 15.2.1... 158 15.2.2... 161 16... 162 16.1... 162 16.1.1... 162 16.1.2... 162 16.1.3 Visual Basic... 163 16.1.4 DoEvents... 163 16.2... 164 16.2.1... 164 16.2.2... 167 17... 169 17.1... 169 17.1.1... 169 17.1.2... 169 17.1.3... 172 17.1.4... 173 17.1.5... 174 17.1.6... 174 17.2... 175 17.2.1... 175 17.2.2... 181 3 18... 186 18.1... 186 18.2... 186 18.3... 187

6 18.4... 191 19... 193 20... 211 21... 243 4 + 2004 4... 264... 274 2004 4... 278... 284 2004 9... 289... 301 2004 9... 306... 314

>>>> 1 2004 2005 4 4 30% 3010 5 DOS 30

1 1.1 1.1.1 1. 4 2.

1 3 1.1.2 1 Data_Structure=(D S) D S D 2 D D D R B=(D R) 3 3 1.1 1.2 1.1 1.2 4

4 1 1 1. 13 2 1.2 1.1. 3 1 n(n 0) a 1 a 2 a 3 a n 2 3 i(1 i n) n in i+1 ii 1 n n+1 1 4 i(1 i n)i+1 nn i1 n 1

1 5 1.1.4 1 top 2 s(1:m) m s(1:m)s(bottom)s(top) top=0 top=m 3 1 top 1 2 top 1 0 3 0 3 rear front 4 s(1:m)

6 1 rearfront frontrear rear=front=m 1 rear=rear+1 rear=m+1rear=1 s=1 2 front=front+1 front=m+1front=1 s=0 1.1.5 1 1 xia i-1 a i a i 1 p

1 7 x*s *p a i 2 i a i 1 p a i a i 1 next pnexta i a i a i n i 1 i n i=n+1 *p *pp =NULL*ppnext =NULL 2 next prior head 3 NULL (a 1 a 2 a n ) (b 1 b 2 b m ) (a 1 a n b 1 b m ) a n b 1 a n

8 1 NULL p pnext 1.1.6 1 Treen(n 0) T T Root m(m 0)T l T 2 T m Subtree 1Degree Degree Leaf 2Child Parents Child ParentsSibling 3Ancestor Descendant k k s k k s Ancestork s k Descendant k k

1 9 4path k 1 k 2 k i k i k i+1 1 i j k l k j Path j 1 5 Level Height Level 1 1Height Depth 0 6 OrderedTreeUnorderedTree OrderedTreeUnorderedTree 2 1 BinaryTreen(n=0)(n=0) 2 2 1 i2 i 1 i 1 2 k 2 k 1k 1 3 n 0 2 n 2 n 0 =n 2 +1 k 2 k 1 Full Binary Tree

10 1 1 2 Complete BinaryTree 1 4 n log 2 n + 3 lchild rchild BinTNode BinTreeroot root root=null n2n n 1 n+1 parent 3 3 1

1 11 2 3 3 3 1.1.7 1 1 2 k k k

12 1 log 2 n 2 1 1 R 1 R 2 R 2 R 1 R 2 R 1 R 2 R 1 2 R 3 3 R n n 1 n 2 n d 1 d 1 d 1 d 2 <d 1 d t =1 d t <d t 1< <d 2 <d 1 3 R 1 R 2 R n i 1 i<n AR i R n R min R min R i R min i R i R min B i 1 n n 1 n 1 n 2 n 1 2 1 4 Quick Sort R[1] R[h] temp R[1] R[i 1] R[i+1] R[h] temp temp tempr[i]r[1] R[i 1] temp.key

1 13 R[i+1] R[h] 1 i h R[1] R[i 1] R[i+1] R[h] 1.2 1.2.1 1. A B C D D 2. A C B D C 3. A C B D D 4. A C B D A 5. A C B D B 6. A C B D

14 1 C 7. A C B D D 8. A B C D E F A ABCDEF B DBEAFC C ABDECF D DEBFCA B 9. A C B D A 10. 1 2 3 4 A 1 2 3 4 B 4 3 2 1 C 3 4 2 1 D 2 4 1 3 D 11. 5 A 32 B 31 C 16 D 15 C 12. n A n+1 B n C (n+1)/2 D n/2 B 13. T 4 1 2 3 4 4 2 1 1 T A 8 B 7 C 6 D 5 A

1 15 1.2. 2 1. n log 2 n 2. 8 255 3. DBEAFCABDEFC DEBFCA 4. n(n 1)/2 5. 15 front=6rear=9 3 6. N O(Nlog 2 N)

2 2.1 2.1.1 / 2.1.2 1 goto 2 3

2 17 2.1.3 1 2 3 3 2.2 2.2.1 1.

18 1 A C B D B 2. A C B D A 3. A B C D D 4. A C B D B 5. A C A B D 2.2.2 1. 3 2. 3. 4.

3 3.1 3.1.1 1 2060

20 1 2 1 P D C A 2 3 4

3 21 3.1.2 1 4 2 2070 3 4

22 1 3.1.3 1 2 3 3 N-S PADPDL 3.1.4 1 2

3 23 3 1 / / 2

24 1 4 4 1 5 2 3 3 4

3 25 3.1.5 3 3.2 3.2.1 1. PFD A B C D B 2. 3 A B C D D

26 1 3. A B C D A 4. A B C D B 5. A B C D C 6. A C B D A 7. 4 A B C D B 8. A B C D B 9..... A B C D I D 10. A C B D

3 27 A 11. A PAD B SA C SC D DFD A 12. A PAD B PFD C N-S D DFD D 13. A B C D D 14. A C B D D 15. A B C D A 16....... A B C D D 17. A C B D C 18.

28 1 A B C D C 19..... A B C D A 3.2.2 1. 2. Jackson 3. 4. 5. 6. 7 7.

4 4.1 4.1.1 1 Data Database DB DataBase Management System DBMS DBMS 6 Database Administrator DBA Database system DBS 5 Database Application System DBAS 3 7

30 1 2 1 3 2060 2070 3 2 DBMS 3 3 3 4.1.2 1

4 31 3 3 2 E-R E-R E-R 3 E-R 3 4.1.3 1 3 2

32 1 4.1.4 1 2 3 E-RRDBMS 4.2 4.2.1 1. A B C D A 2. A B C D A 3.

4 33 A C B D B 4. A B C D B 5. A B C D D 6. A C B D A 7. E-R A B C D B 8. 4 A - E-R C B D A 9. A C B D D 10. 4 A C B D C 11.

34 1 A B C D C 12. A B C D A 13. A B C D B 14. A B C D B 15. E-R A B C D C 16. A B C D A 17. A C B D C 18. A C B D D 19. A B C D E-R D

4 35 4.2.2 1. 2. 3. 4. 5. 6. 7. E-R 8. E-R

2 >>>>

5 Visual Basic 5.1 5.1.1 Visual Basic 1. Visual Basic 2. Visual Basic 6.0 Visual Basic Windows 5.1.2 Visual Basic 1. Visual Basic Visual Basic 2. Visual Basic 5.1.3

38 2 5.1.4 Visual Basic 1. Visual Basic Form1 2..frm.bas.cls.vbp.vbg.res6 3. 4. ActiveX 5.2 5.2.1 ABCD 1 Visual Basic A Visual BasicWindows B VisualWindows C D Visual BasicOOP Visual BasicWindows C C 2Visual Basic

5 Visual Basic 39 A B C D Visual BasicVisual Basic B 3 Visual Basic A res B frm C vbp D cls Visual Basic res Visual Basic frm Visual Basic vbp Visual Basic cls Visual BasicC C 4 A bas B res C fnn D ocx 4 basresfrm ocx ActiveX D D 5Visual Basic A B C D Visual Basic A 6EXE A B C D 4 C 7 Visual Basic A B C Visual BasicREM D

40 2 Visual Basic _Visual Basic REM REM Visual Basic Visual Basic Visual Basic B 8 A Visual Basic B Visual Basic C Visual Basic D Visual Basic Visual Basic B 9Visual Basic A B C D Visual Basic A 10Command1 Caption(x) Alt+xCaption Ax & Cx # Bx & Dx # Caption& Alt+ A 11 A CCtrl+N B DF4 Ctrl+NF4

5 Visual Basic 41 D 12 A If x=y Then t=x: x=y y=t C If x=y Then t=x x=y y=t B If x=y Then t=x, x=y, y=t D If x=y Then t=x; x=y; y=t Visual Basic A A 13 Visual Basic A C B D Visual Basic Sub MainA A 14 A B C D Visual Basic3 B 5.2.2 1Visual Basic Visual Basic 3 2 (BorderStyle) BorderStyle6 Windows 6 3Visual Basictwip Visual Basictwip 1=1 440

42 2 twip ScaleMode ScaleMode 4 WindowState 3 WindowState

6 6.1 6.1.1 1. Visual Basic 1 Visual Basic Visual Basic 2. = 3 Visual Basic Visual Basic Click DblClick Load MouseDown 4

44 2 [.] [] 2 3 6.1.2 1 1 Windows 2 AutoRedraw BackColor ForeColor BackColor BorderStyle6 1 2.1 CaptionForm1 Form2 ControlBox BorderStyle 0 Enabled Height Width Icon.ico MaxButton MinButton Picture 1 Visual Basic

6 45 WindowState0 1 2 22 2 Click DblClick Load Unload Activate Deactivate Paint 6.1.3 1 Visual Basic 6.03 Visual Basic.exe Visual Basic 2.2 ActiveX 2 1 Name 2.3 2 Visual Basic 2.4 6.1.4 1.

46 2 2. 6.1.5 6.2 6.2.1 1 A B C D Visual Basic 4 B 2Form1 Visual Basic A From1.Caption ="Visual Basic" B From1.Value="Visual Basic" C Form.Caption="Visual Basic" D Form.Value="Visual Basic" Value B D Caption From. = From Form1 C C

6 47 3 A C B D C 4 A BorderStyle B WindowState C Height Width D MaxButton BorderStyle Height Width MaxButton WindowState0 1 2 WindowState 2 B 5 A C B D Visual Basic B 6 Form1Label1 A Left Top B Right Top C Right Height D Left Height Left TopLeft Top Label1.Left=Form1.Left Label1.Left Label1.Top=0 A 7 Form2.Caption="Open"Form2 Caption Open

48 2 A C B D Visual Basic. = Form2 Caption Open C 8 AName BName C Name DName Name Caption A A 9 A UnloadForm1Form1 BLoad C Enabled False DHeight Width A Unload A 10 A Picutre B Caption C Name D Icon Visual BasicName C 11 Frm1Cmd1 A Form_Click() Command1_Click() B Frm1_Click() Command1_Click() C Form_Click() Cmd1_Click() D Frm1_Click() Cmd1_Click()

6 49 Form_Click() ClickC C 12 6 1Text1ABC 6 1 A Private Sub Command1_Click() Text1.Text="ABC" C Private Sub Command1_Click() Text1="ABC" B Private Sub Command1_Click() Text1.Name=ABC D Private Sub Command1_Click() Text1.Text =Chr(65)&Chr(66)&Chr(67) B 3ABC C Text Text1Text B 6.2.2 1Label LabelCaption NameLabel1 Caption Name 2 StartUpPosition 40 12 3 StartUpPosition 3 2 StyleStyle 0 12

50 2 Style 4 Text1 Text2Text2 Text1 SetFocusText1.SetFocus Text1.SetFocus 5 WindowStateMaximized 2 Minimized 1 Normal 0 WindowState

7 7.1 7.1.1 Visual Basic 1 1 ASCII 0 Visual Basic 2 4 3 E e D d 4 1 8 8 1 11 3 84 4 5 1

52 2 6 TrueFalse 7 8100 1 19999 12 31 # mm/dd/yyyy mm-dd-yyyy 2. Visual Basic Type Type As As End Type 3. Enum [Public Private]Enum [= ] [= ] End Enum Public Private Public Visual Basic 0 1 7.1. 2 1. 1 Dim Static

7 53 2 Public Global 2 Variant VarType Variant16 3 Dim Static % & $ Visual Basic Visual Basic 7.1. 3 Visual Basic5 68 4.4 7.1. 4 1. Visual Basic 9 76 4.7 ^ / \ Mod +&

54 2 2. 1 Visual Basic 8 78 4.9 True False Visual Basic00 ASCII 2 Visual Basic 6 79 4.10 3 80 4.11 7. 2 7.2.1 1 Single A Time% B Sheigh t! C Name$ D CXYZ@ Visual BasicDim % A% A & A& A! A! A # A# A @ A@ A $ A$ A B

7 55 2 Type Student number As String name As String age As Integer End Type A Student.name="" C Dim s As Type Student S.name="" B Dim s As Student s.name= "" D Dim s As Type s.name="" A C D B B 3Visual Basic A A#A B 4A C?xY D consta A# B C* D D 4 A " "+" " C " "& 150 B " "+ 150 D " "&" " + & + & B B 5 A "01/03/2002" C #1/03/2002# B Date("01/03/2002") D 01/03/2002 ##MM/DD/YYYY# C C 6

56 2 Dim TestDate As Date TestDate A TextDate=#1/1/2002# B T estdate=#"1 /1/2002"# C TextDate=date("1/1/2002") D TestDate=Format("m/d/yy","1/1/2002") #mm/dd/yyyy# #2004 5 1 #5/1/2004# A 7 Visual BasicSqr(a+B)^3*2 A Sqr B + C ^ D * B 8 cos 2 (a+b)+5e 2 Visual Basic A cos(a+b)^2+5*exp(2) C cos(a+b)^2+5*ln(2) B cos^2(a+b)+5*exp(2) D cos^2(a+b)+5*ln(2) Visual Basic A A 9 String(n, "str") A Bn Cn D n String(n, "str") n n s B 10EOF() A B C D EOF B 11 Mid("abcdefghijk",5,3)

7 57 A efg B fgh C efghjik D fghijk Mid(A$,B,C)A$BC abcdefghijk5 3efg A 12True A "1"+ 2 ="12" B "1"+"2"="3" C "1"& 2 ="12" D "1"&"2"=" 3" Visual Basic A "1"+ 2"1"1 3C "1"& 22"2" "12" B D"3""12" C 13 A Rtrim() B Ltrim() C Left() D Trim() Rtrim(A$,x)xLtrim(A$,x)x Trim(A$,x)xLeft(A$,x) x B 14str1 str2 A Left B Mid C String D Instr 4 Left Mid String Instr D 15a="Visual Basic"b="Basic" A b=left(a,8,12) C b=rigth(a,5,5) B b=mid(a,8,5) D b=left(a,8,5) a b B B 16 1239 A Len("1234")+5 B Val("1234")+5

58 2 C Str(1234)&5 D Cstr(1234)+ "5" 4 LenA 9 ValB 1239 Str C12345 CstrD12345 B 17 Dim X As Integer Sgn(X)1X A C 0 B 0 D 0 Sgn(X) X X 0Sgn(X) 1X=0 Sgn(X) 0X 0Sgn(X)1 D D 18a10 a 15 Visual Basic A 10 a 15 B a=11 Or a=12 Or a=13 Or a=14 C a 10 And a 15 D Not (a =10) And (a =15) 10 a 15 a 10 a 15 C10 a 15 a 4 11 12 13 14 Ba 10Not(a =10),a 15Not(a =15) D Visual BasicA A 19a=3 b=5 A a>=b And b>10 C (a<0) Eqv (b>0) B (a>b)or (b>0) D ( 3+5>A)And (b>0) B 20 A="Good Morning. " B="Afternoon,Boys. " Good Boys. A Left(A,5)+Right(B,5) C Mid(A,1,5)+Mid(B,1,6) B Left(A,10)+Right(B,6) D Mid(A+B,1,11)

7 59 Left(A,5) A5 Good Right(B,5) B 5 Boys. A Good Boys B Good Morni,Boys. MidMid (A$,B,C)A$B CC Good Aftern D Good Morning A A 21 xx 3 A 0.01*Int(x+0.05) C 0.01*Int (100*(x+0.05)) B 0.01*Int (100*(x+0.005)) D 0.01*Int (x+0.005) 3 5 100100 B 22 Command13Label1 Label2 Label3 Private x As Integer Private Sub Command1_C1ick() Static y As Integer Dim z As Integer n=10 z= n+z y=y+z 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 x yzz y y z3 3 30 30 10 C 23 Command1 Private Sub Comma nd1_click() Static A As Integer Static B As Integer B=B+3 A=3+A

60 2 Print A,B 3 Command1 A 3 6 B 3 9 C 9 9 D 3 3 Command1 1 Command1 A B32 Command1 A B3 A B 6 3 Command1 A B 9 2Dim A As Integer 3 9 C 24 Command1 Private Sub Command1_Click() Static X As Integer Static Y As Integer Cls Y=1 Y=Y+5 X=5+X Print X,Y 3 Command1 A 15 16 B 15 6 C 15 15 D 5 6 X Y ClickY 1 5 X53 X15 Y6B B 25 True A 1000 999 C True Xor "1000" "999" B "1000" "999" D 1000 999 Xor False A False ASCII 1ASCII 9ASCII BTrue TrueFalseXorTrue

7 61 Xor False C DFalse B 26 Command1 Dim k As Integer Private Sub Form_Load() k=15 Private Sub Command1_Click() Static b As Integer b=b+k k=k+1 Print k b Command12 A 17 31 B 15 31 C 17 16 D 2 1 kb 16 15 Command1 b 150 b 31 k 1717 31 A 27 Private Sub Form_Click() Dim Strl As String, Str2 As String, Str3 As String Dim I A s Integer Str1 = "e" For I = 1 To 2 Str2 = UCase(Str1) Str1 = Str2 & Str1 Str3 = Str3 & Str1 Str1 = Chr(Asc(Str1) + I) Next I Print Str3 A EeFF B eeff C EEFF D eeff Asc(x)ASCII Chr(x) x ASCII Ucase(x) x

62 2 ForI=1Str2=E Str1=Ee Str3=Ee Str1=FI=2 Str2=F Str1=FF Str3=EeFF Str1=H EeFF A 28 Private Sub Form_Click() a$ = "*": b$ = "$" For k = 1 To 3 X$ = String$(Len(a$) + k, b$) Print X$; Next k Print A *** ** **** B *$*$*$ C 1*$2*$3*$ D $$$$$$$$$ For 9$ Len(Str) Str String$(n,ChA) n Cha D 29x Private Sub Command1_Click() Dim n As Integer,x As Integer,I As Integer x = 5 For I = 1 To 20 Step 2 n = I \ 5 x = x + n Next I A 21 B 22 C 23 D 24 \For x 5+0+0+1+1+1+2+2+3+3+ 3=21 A 30 Name Form1 Name Text1 Text2 Name Command1 Private Sub Command1_Click() a=text1.text+text2.text Print a Private Sub Form_Load()

7 63 Text1.Text="123" Text2.Text ="321" A 444 B 321123 C 123321 D 132231 Text1.Text Text2.Text + 123321 C 31 Private Sub Text1_KeyPress(KeyAscii As Integer) Dim Char As String Char=Chr(keyAscii) KeyAscii=Asc(Ucase(char)) Print String(6,KeyAscii) A A a B A C aaaaaa D AAAAAA D Asc(x) ASCII Chr $ (x) x ASCII String $ (n, "") n D 7.2. 2 1Fix( 48.65)+Int( 52.15) Fix Int Fix( 48.65)48 Int( 52.15)53 Fix( 48.65)+Int ( 52.15) 101 101 2 a=2 b=3 c=4 d=5 Not a<=c Or 4* c=b^2 And b<>a+c Not And Or Not a <= c Or 4 * c = b ^ 2 And b <> a + c

64 2 True False True False False False False 3 Text1 C Val C=Val(Text1.Text) C=Val(Text1.Text) 42004 8 18 Print day (now) <cr> nowday(now) 18 18 5 4ABC abc ABCDE afgh ASCII afgh 6A AbcDeA Ucase Lcase A=Ucase$(A) 7ABCD Private Sub Command1_Click() a="" For n=65 To 68 a=a+ Next n Print a 65 68 A B C D ASCII Chr() (ASCII) a ABCDChr$(n) Chr$ (n)

7 65 820 200 3005 Private Sub Command1_C1ick() For i = 1 To 20 x = I nt( *200+100) If =0 Then Print x S=S+ End If Next i Print "Sum=":S Rnd() Rnd(n) n x Mod 5Int(x/5) x/5 x

8 8.1 8.1.1 1. Print Print [.]Print [][ ] Print Print Print 2. Print Tab Spc Space$ 1 Tab(n) n Print Tab 1nn nn 1 PrintTabTab 2 Spc(n) Print ntab PrintSpc SpcTab 3 Space$(n) n

8 67 3Format$ Format$ Format$( ) 88 5.1 Str$ 4 InputBox InputBox(prompt[,title][,default][,xpos,ypos][,helpfile,comtext]) prompt title default xpos ypos helpfile comtext InputBox InputBox 8.1.2 MsgBox MsgBox MsgBox(msg[,type][,title][,helpfile,context]) msg type 98 5.2 title helpfile context InputBox 100 5.4

68 2 8.1.3 FontNameWindows FontSize 9 FontBold True FontItalic True FontUnderlineTrue 8.1.4 1 Print Printer Printer.Print [] Printer Page NewPage EndDoc 2 PrintForm [.]PrintForm PrintForm AutoRedraw True PrintForm

8 69 8.2 8.2.1 1 Print "Worker";Spc 3 ; "Peasant" A Worker Peasant C WorkerPeasant B WorkerPeasant D WorkePeasant Spc(n)n PrintC C 2 Print Format $(32556, # # # # # # # );Format$(32556, # # # ) A 3255632556 B 3255632556 C 32556 325 D 32556325 Format ## # 0 A 3 a=inputbox("today","tomorrow, "Yesterday","Day before yesterday",5) A Today B Tomorrow C Yesterday D Day before yesterday InputBox InputBox(prompt[,title][,default][,xpos,ypos][,helpfile,context]) default Yesterday C 4 age=inputbox(" "," ","38") 20 A age 20 C 38 B D Inputbox 73 B C DInputBox A A 5 x=inputbox("" "0" "")10

70 2 A X 10 C 0 BInputBox D X"10" InputBox 30 4 D D 6Temp=MsgBox(" ",vbyes No, " ") A B vbyesno C D Temp MsgBox3 C C 7Command1 Private Sub Command1_C1ick() 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 MsgBox MsgBox(prompt[,buttons][,title][,helpfile,comtext]) title b$hardsoft C 8 Temp=MsgBox(" ",vbabortretryignore, "") A 1 B 2 C 3 D 4 2 vbabortretryignore 3 C 9

8 71 Private Sub Command1_Click() MsgBox Str(123+123) A 123+123 B 123 C 246 D MsgBox Str(123+123) 246 C 10 Private Sub Command1_Click() Dim a 5 As String Dim b As Integer Dim I As Integer For I =0 To 5 a(i)=i+1 Print a(i); Next I A 123456 B 6 C 1 2 3 4 5 6 D 0 a A A 11 List1 Private Sub Form_Click() For I = 0 To List1.ListCount 1 If I Mod 2 = 0 Then Print List.List(I); End If Next I End sub Private Sub Form_Load() List1.Additem "" List1.Additem "" List1.Additem "" List1.Additem " " List1.Additem " "

72 2 A C B D Form_Load 5List 0Form_Click2 C 12 Private Sub Command1_Click() Dim MyString As String Dim MyLen As Integer MyString = "Hello World" MyLen = Len(MyString) MsgBox MyLen A Hello World B HelloWorld C 10 D 11 Len() D 13 Command1 Private Sub Command1_Click() Static A As Integer Static B As Integer Cls B=2 B=B+3 A=3+A Print A,B 3 Command1 A 3 5 B 6 6 C 9 5 D 3 3 Command1 A B 3 5Command1A BA 3 B 5 B 26 5 Command1 9 5 Command1Cls 9 5

8 73 C 14Command1 Private Sub Command1_Click() For I=1 To 4 For J=0 To 1 Print Chr$(65+I); Next J Print Next I A BB B A C B D AA CC BB CC BBB DDDD CCC DDD CCCC EEEEE DDDD EEEE DDDDD PrintFor Print Print For j i Chr$(65)="A" A 15 Private Sub Command1_Click() x = InputBox(" ") For I = 1 To Len(x) \ 2 If Mid(x, I, 1) <> Mid(x, Len(x) I + 1, 1) Then Exit For End If Next I If I > Len(x) \ 2 Then Print "Yes" Else Print "No" End If Ax Cx Bx Dx Len(x) x Mid(x,i,1)<>Mid(x,Len(x) i+1,1)

74 2 C 16 Private Sub Command1_Click() For i=1 To 5 For j=1 T i For k=j To 4 Print "a"; Next k Print Next j Print Next i A 4 B 5 C 38 D 40 i=1 4 i=2 7 i=3 9 i=4 10 i=5 10 4+7+9+10+10=40 D 8.2.2 1 Print Int(12345.6789*100+0.5)/100 3 5 100 100 12345.68 2

8 75 Private Sub Command1_Click Dim Password As String Password=Text1.Text If Password="myname" Then Form1.Show Else D=MsgBox( ) End If Refresh Private Sub Command2_Click() PasswordChar Command1 Default MsgBox MsgBox([,][, ][,]) EndUnLoad Me Command1 Default True PasswordChar * Unload Me " " vboknly "" End Text1 * True 3 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4

76 2 3 2 1 Private Sub Command1_Click() Dim b(3,3) For i=1 To 3 For j=1 To 3 k=k+1 B(i,j)=k Print b(i,j ); Next j Next i For i= For j= Print b(i,j); Next j Next i Print 3 To 1 Step 1 Print Print 3 To 1 Step 1 3 To 1 Step 1 4 Command1 Private Sub Command1_C1ick() Dim a As String a= For i =1 To 5 Print Space(6 i);mid$3(a,6 i,2*i 1) Next i 5 456 34567 2345678 123456789 Space Mid

8 77 "123456789" "123456789" 5 3Textl Text2 Text3 Command1 Private Sub Command1_Click() Dim d As Single d = If d > =0 Then Text2.Text = 3.14159*d Text3.Text = 3014159*(d/2)^2 End If d Text1.TextVal() Val(Text1.Text) 6 11 33 55 Private Sub Command1_Click() For j = 1 To 3 Print ; 11*(2*j 1); Next j Tab(n) n Tab Tab(3*j)

9 9.1 9.1.1 1. Caption 1 Alignment0 1 2 AutoSizeTrueCaption BorderStyle 0 1 2 Click DblClick 2 1 Text MaxLength0 Locked False True PasswordChar

9 79 MultilineTrue False ScrollBars01 2 3 Multiline True SelStart SelLength SelText 2 Change KeyPress LostFocus GotFocus 3 SetFocus [.]SetFocus 9.1.2 1. 1 PictureBox JPEG GIF PictureBox AutoSize True PrintClick DblClickPrint Cls 2 Image ImagePictureBox PictureBox PictureBox StretchImage ImageClick DblClickPrint Cls 2 Picture

80 2 LoadPicture [.]Picture = LoadPicture(" ") 3 1 Line BorderWidth BorderStyle X1 X2 Y1 Y2 2 Shape Shape 0 5 124 6.1FillStyle FillColor FillStyle 9.1.3 Click SetFocus DefaultTrue Style0 Caption 1 Picture Picture.bmp.ico 9.1.4 Value0 1 2 Alignment 0 1 Style 01 Click 9.1.5 1

9 81 1 List0 Listindex1 ListCount0List- Count 1 Sorted text MultiSelect 30 None 1 Simple2 Extended Selected 2 Click DblClick 3 AddItem RemoveItem Clear 2 1 Style 0 1 2 2 Click DblClickstyle 1 ChangeStyle 0 1 3

82 2 9.1.6 1 Value Max Min LargeChangeValue SmallChangeValue 2 Change Scroll 9.1.7 1. Name EnabledIntervalms 65s 2. Interval timer 9.1.8 1. Font FontSize FontName FontColor Visible Name Enabled Caption 2. 9.1.9 Tab 1 Enabled VisibleTrue GotFocus LostFocus

9 83 SetFocus LoadShow 2 Tab Tab Tab Tab Tab Tab Disabled Invisible Tab TabStop False Tab TabIndex Tab 9.2 9.2.1 1Change A C B D D 2 True A WordWrap B MultiLine C ScrollBars D Locked 4 WordWrap 3 MultiLine True ScrollBase 0 1 2 3 LockedFalseTrue B 3Esc Click True A Value B Default C Cancel D Enabled

84 2 4 Cancel Esc 3 Default True Click Enabled TrueFalse Value Cancel Esc Click C 4* A Text * C Password B Caption * D PasswordChar * PasswordChar TextBox D 5Text1 A Tex1.Enabled=False Text1.Alingment=0 C Tex1.Enabled=False Text1.Alignment=1 B Tex1.Enabled=True Text1.Alignment=0 D Tex1.Enable=False Text1.Alignment=2 EnabledTrue Alignment 01 2 D 6 A Change B KeyPress C LostFocus D SetFocus Change KeyPressLostFocusSetFocus D 7 A B C D

9 85 B 8 Pic1 temp1.bmp A Pic1="temp1.bmp" C Pic1.Picture="temp1.bmp" B Pic1.Picture=LoadPicture("temp1.bmp") D Pic1=LoadPicture("temp1.bmp") LoadPicture.Picture=LoadPicture(" ") 4 B B 9Form1 Image1 Private Sub Form_Load() Image1.Stretch=True Private Sub Image1_Click() Image1.Height=3000 A Image1.Picture=LoadPictrue("gg1.gif") Image1.Stretch=True B Image1.Picture="gg1.gif" Image1.Stretch=Not Image1.Stretch C Image1.Picture=LoadPictrue("gg1.gif") Image1.Stretch=Not Image1.Stretch D Image1.Picture="gg1.gif" Image1.Stretch=True LoadPicture Image1.Picture= LoadPicture("gg1.gif") StretchTrue FalseStretch Image1.Stretch=Not Image1.Stretch C

86 2 10 A Autosize C AutoRedraw B Stretch D Appearance 4 C D Picture AutoSize ImageImage Stretch Picture B B 11 A Caption B Value C Checked D Selected Caption Checked SelectedValue ValueTrue0 1 2 3 B 12Option1 Option2 Check1Text1 Text A Option1.Value=True Check1.Value=False C Option2.Value=False Check1.Value=True B Option1.Value=True Check1.Value=True D Option1.Value=True Check1.Value=1 Value Option ValueTrue Flash Check Value0 12 D D

9 87 13OptionButton AFrame Image B ComboBox Image C ComboBoxPictureBox DFramePictureBox Visual Basic D 14List1 A List1.Clear B List1.Delete List1.ListIndex C List1.RemoveItem List1.ListIndex D List1.Clear List1.ListIndex B DeleteClear RemoveItem0 ListIndex C C 15 A List B ListCount C ListIndex D Columns List ListCount ListIndexColumns A 16List1 3 123 456 789 List1.RemoveItem List1.ListIndex A 123 B 456 C 789 D ListIndex 1 RemoveItem ListIndex

88 2 1RemoveItem D 17 List1 A List.Sorted=0 B List.Sorted=True List.MultiSelect=0 List.MultiSelect= 0 C List.Sorted=True D List.Sorted=True List.MultiSelect=1 Sorted True MultiSelect 0 None 1 Simple 2 Extended Ctrl Shift Shift D 18 List1Label1 A Private Sub List1_Click() B Private Sub List1_C1ick() Label1.Caption=List1.ListIndex Label1.Name =List1.ListIndex C Private Sub List1_Click() D Private Sub List1_Click() Label1.Name=List1.Text Label1.Caption =List1.Text Caption Name Text ListIndex D D 19 Private Sub Command1_Click() List.RemoveItem 2 Private Sub Form_Load() List.MultiSelect=2

9 89 List1.AddItem"" List1.AddItem"" List1.AddItem"" List1.AddItem"" Command1 A B C D Form_Load 4 0 3Command12 C 20 A Max B Large Change C Value D Max Min A 21Timer3Interval A 3 B 30 C 300 D 3000 IntervalTimer 1000 13 3000 D 22 TxtTimeTimer1 Private Sub Timer1 () TxtTime.Text=Time A Enabled B Visible C Interval D Timer D 23HScroll1 LargeChange =5 SmallChange=3 Max=100 Value=45 Value

90 2 A 45 B 48 C 50 D 65 Value5C Value Max Min LargeChange Value SmallChangeValue C 24 ShapeFillStyle FillColorBackColor AShape FillStyle 2 7 BackStyle 1 BShape FillStyle 0 1 BackStyle 1 CShape FillStyle 2 7 BackStyle 0 DShape FillStyle 0 1 BackStyle 0 Shape FillStyle0 7 0FillColor 1 2 7 Shape BackStyle0 1 0 TransparentBackColor 1 Opaque BackColor A A 9.2.2 1Text1 Text2 Command1Command1Text2

9 91 Private Sub Command1_Click() Text2.SelStart=0 Text2. =Len(Text2.Text) Text2. 3 SelStart SelLength SelText SelStart SelLength SelText SetFocus SelStart0 SelLength SelLength SetFocus SelLength 2 Command1 Text1 Command1 Command1 SetFocus Private Sub Form_Load() Command1.Enabled=False Private Sub Text1 () Command1.Enabled=True Change 3 Private Sub Form_Load() Text1.Text=" " Private Sub Text1_Change() Picture1.Print"" Picture1.Print ""Text1 Change 46 4 2

92 2 22 33 3 5 Stretch StretchTrue AutoSize True True 6d:\pic a.jpg Picturel Picture1.Picture=LoadPicture("d:\pic\a.jpg") 7 Interval 8 Timer 9 Timer1 Label1 30 Label1100 Priv ate Sub Form_Load() Label1.Left=Form1.Width Timer1.Interval=30 Timer1.Enabled=True Private Sub Timer1_Timer() Label1.Left= Label1.Left 100 If Label1.Left<100 Then End If Form_LoadLabel1 Left Timer1.IntervalTimer 30 Timer1.Enabled True Timer1.Timer Left 100 EnabledFalse

9 93 Timer1.Enabled=False 5 105 LargeChangeValue LargeChange 11Form1 Click Caption Caption Label1.Caption="Visual Basic " Caption Label1 Visual Basic 12OKCmdOK_Click() Caption Click()Caption CmdOK OK 13 ListBox1 Private Sub Command1_Click() Dim Entry,I,Msg Msg="Choose Ok to add 100 tiems to your list box" MsgBox Msg For I =1 To 100 Entry="Entry"& I ListBox1.AddItem Entry Next I AddItem 100100 AddItemListBox1100 14 Label1 List1 Label1 Private Sub Form_load() List1.AddItem "" List1.AddItem ""

94 2 List1.AddItem "" Private Sub () Label1.Caption= List1_DblClickListBoxText List1.Text Label1.Caption List1_DblClick List1.Text 15 Visual Basic 16 Value Value=1 Value 17(mnuEditCopy) mneditpaste Private Sub mnueditcopy Click() mneditpaste. =True Enabled Visible Enabled Visible Text1 Text2 Enabled 18 Text1 Text2 Private Sub Text1 () Text2.Text=Text1.Text Change

9 95 Text Text Change 19 Label1 Command1 Timer1 1 1 Private Sub Form_Load() Timer1.Interval= Private Sub Timer1_Timer() Label1.Caption=Now Private Sub Command1_Click() End Timer1.Interval 1000 20 Private Sub Form_Click() Dim Msg As Integer Form1. MsgBox "Choose OK to make the form reappear" Form1. HideShow Hide Show 213Label1 Text1 HScroll1Label1 Label1 Left Private Sub Form_Load( ) HScroll1.Max=Form1.Width HScroll1.Min=0 HScroll1.LargeChange=50 HScroll1.SmallChange=10 Text1.Text=HScroll1.Value HScroll1.Value=0 Label1.Left=HScroll1.Value Private Sub HScroll1 Text1.Text=HScroll1.

96 2 Label1.Left=HScroll1.Value Label1 Change Label1 ChangeValueLabel1 Left Change() Value 22 Label1 Label2 Caption HScroll1Min0 Max100 Label2 Private Sub HScroll1 () Label2.Caption=HScroll1. Change Change() ChangeValue Caption Value Change Value 23 3 Picture DownPicture DisabledPicture DownPicture

10 10.1 10.1.1 1 If Then [Else ] True ThenElse 2 If 1 Then 1 ElseIf 2 Then 2 Else n+1 End If 3 IIf IIf(,, ) 10.1.2 Select Case Case 1 1 Case 2 2 Case Else n End Select 10.1.3 For For

98 2 For = To [Step ] [Exit For] Next Exit For Next 10.1.4 While [ ] Wend 10.1.5 Do 1 Do [{While Until}<>] [Exit Do] Loop 2 Do [Exit Do] Loop [{While Until}<>] 12 While Until {While Until}<>Do LoopExit Do Exit Do Loop 10.1.6

10 99 10.1.7 GoTo 1 GoTo Go To { } Go To 2 On-GoTo On GoTo 10.2 10.2.1 1 For I= To 10 Step 0 k=k+2 Next I A C B D 0 A 2x x=3 For I=1 To 20 Step 2 x = x + I / 3 Next I A 3 B 22 C1 D 4 For 2 x 3 A

100 2 3 Command1: Private Sub Command1_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 36 D 4 sum=0 For I =11 To 1 Step 2 sum=sum+i Next I Print I sum=sum+i I A 73 B 61 C 63 D 71 For 2 11 9 7 5 3 11 I3 A 5 Command1 Label1 Private Sub Command1_C1ick() S=0 For i=1 To 15 x=2*i 1 If x Mod 3=0 Then s=s + 1 Next i Label1.Caption=s

10 101 A 1 B 5 C 27 D 45 1 153B B 6 Private Sub Sele() Dim n As Integer i=21:n=3 Do While i > n i = i n Loop Print i A 3 B 5 C 6 D 8 While i 3i3 A 7 Private Sub Command1_Click() For i = 1 To 3 For j =5 To 1 Step 1 Print i + j Next j,i End Sud A 12 B 13 C 14 D 15 3 5=15 D 8 n! A Private Sub Command1_Click() n=5:x=1 Do x=x*1 i=i+1 Loop While i n Print x B Private Sub Command1_Click() n=5: x=1:i=1

102 2 Do x=x * 1 i=i + 1 Loop While i n Print x C Private Sub Command1_Click() n=5:x=1:i=1 Do x=x * 1 i=i + 1 Loop While i<=n Print x D Private Sub Command1_C1ick() n=5:x=1:i=1 Do x=x * 1 i=i + 1 Loop While i n Print x Do Loop WhileWhile C C 9Command1 Option Base 1 Private Sub Command1_Click() Dim a(5) As Integer Dim K As Integer Dim Total As Integer a(1)=2 a(2) =5 a(3) =4 a(5) = 6 For k = 1 To 5 Total = Total + a(k) Next k Print Total A 10 B 15 C 27 D 35

10 103 2+5+4+10+6=27 C 10 Private Sub Command1_Click() 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 x=33+6+6=15 B 11 Exit For A Exit For B C Exit For D For Exit For For Exit For D 12 x Private Sub Command1_Click() Dim a As Single, b As Single, c As Single, d As Single Dim x As Single a=100 b=20 c=1000 x=a If b>a Then d=a:a=b:b=d End If If b>c Then

104 2 x=b Else If a>c Then x=c A 100 B 20 C 1000 D 0 If If x=ax=100 A 13 Text1Command1 Private Sub Command1_Click() Dim i As Integer,n As Integer 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 D 4 D 5 For i Ifi10 10 For 1 i=3 n=12i=7 n=23i=11 n=3 i 10 33 B 14 Private Sub Command1_Click() Dim I,Mynum Do For I=1 To 1000 Mynum=Int(Rnd*1 000) Select Case Mynum Case 7: Exit For Case 29: Exit Do End Select n=n+1 Next I Loop

10 105 Print n A 7 C1000 B Do 1 000 D 0029 Do Loop Exit Do Rnd 0,1Int() D 15 Text1 Text2Command1 Private Sub Command1_Click() 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 Do While Loop 1x=3 n=12x=9 n=23x=27 n=3x 203 27 3 B 16 Private Sub Command1_Click() For I=1 To 4 X=0 For j=1 To 3 X=j For k=1 To 2 X=x+6 Next k Next j Next I Print x

106 2 A 7 B 15 C 157 D 538 x=j x=3+6+6=15 B 17 n Private Sub Command1_Click() n=0 For i=1 To 100 If i Mod 4=0 Then n=n+1 Next i Print n A 5050 B 25 C 26 D 33 If1004 100/4=25 B 18 2 Private Sub Form_Click() Dim N1 As Integer, N2 As Integer,N3 As Integer N1=1:N2=2 Print N1,N2 Do N3=N1+N2 Print N3; N1=N2:N2=N3 Loop Until N3>=5 A 1 1 1 B 2 3 5 C 2 5 7 D 2 3 4 Do Loop Until Until TrueN1 N21 1 2 1 N3 2 2 N1 1 N2 2 2>=5 False 2 N3 3False3 N3 5True22 3 5 B 19Command1

10 107 Private Sub Command1_Click() Dim a As Integer,y As Integer a=10:y=0 Do a=a+2:y=y+a Print "a=";a, "y=";y If y>20 Then Exit Do Loop Until a>14 A a=12 y=12 B a=12 y=12 a=14 y=16 a=16 y=28 C a=12 y=12 D a=12 y=12 a=14 y=26 a=14 y=44 a10 y0 Do Loop a=a+2:y=y+aa 12 y 12a=12 y=12 IF y>20 False Exit Do a>14 False a=a+2:y=y+aa 14 y 26a=14 y=26 IF y>20 True Exit Do C 20 Private Sub Command1_Click() Dim s As Integer, n As Integer s=0 : n=1 Do Until n>100 s=s+n n=n+1 Loop Print s A 5050 B 2500 C 3000 D 4000 Do Until Loop Until s s=1+2+ +99+100=5050 n A 21Command1 Private Sub Command1_Click() Dim I As Integer, a As Integer Do While I<20 Do While True

108 2 If I Mod 10=0 Then Exit Do Else I=I 1 End If Loop I=I+11 a=a+i Loop Print a A 21 B 32 C 33 D 11 I<20I Mod 10=0 B 10.2.2 1 Private Sub Command1_Click() For m=1 To 10 Step 2 a=10 For n=1 To 10 Step 2 a=a+2 Next n Next m Print a a=10 a a=10a 20 20 2 S S=5 For i =2.6 To 4.9 Step 0.6 S=S+1 Next i 0.6 2.6 4.9 4 S 9

10 109 9 3 1+2+3+ +10 Dim t As Single, k As Single k=0 While k<10 k=k+1 Wend Print t k 0k<10 1t t=t+k t=t+k 4 3 Private Sub Commandl_Click() k =10 Do x = k x = x 2 k = k 1 Loop While k >1 MsgBox x k 10 1 k=0x= 1 32 2 5 a=100 Do Print a a=a+1 Loop Until a <=10 a<=10 a100 1 a<=10 6 1+1/3+1/5+ +1/(2n+1) 1/(2n+1)10 4

110 2 Private Sub Command1_Click() Sun = 0 : n = 1 Do n= term = 1/ n Sum = Sum +term If term 0.0001 Then Loop Text1.Text = n Text2.Text = Sum Do Loopterm<0.0001 Exit Do n+2 n+2 Exit Do 7 Private Sub Form_Click() Dim x As Single,amax As Single,amin As Single x=inputbox("enter a score") amax=x amin=x Do While If x>amax Then Amax=x End If If Then Amin=x End If x=inputbox("enter a score") Print "Max=";amax, "Min=";amin x>=0 IfIf x<amin x>=0 x<amin 8100 999 1 Private Sub Form_Click() Dim I As integer

10 111 Dim K As integer For I=100 to 999 For K=2 To I-1 If Then End If Next K If then Print I End If Next I I I2 I 1 I IK 2 I 1 I KI Mod K=0I I Exit For Exit For KI K=I I Mod K=0 Exit For K=I 9 Command1 Function M(x As Integer,y As Integer)As Integer M=IIf(x>y,x,y) End Function Private Sub command1_click() Dim a As Integer,b As Integer a=100 b=200 Print M(a,B MIIf M 200 200

11 11.1 11.1.1 1. 2. 60 1 Dim 1[,2][,3] [As ] 0 Option Base 2 ReDim Dim Private Public ReDim 11.1.2 1 For InputBox Print

11 113 2 ForEach Next For Each In [Exit For] Next [] 3 Array = Array( ) Variant3 Variant Array 11.1.3 text1(0) text1(1) text1(2) 11.2 11.2.1 1m ninteger 1 Dim Arty(m,n) As Integer 3 Print A=A+B;A+B 2 n=32764+5 4 Chdrive c: A 1 B 2 C 3 D 4 1Print 3Chdrive 4 C

114 2 2 Dim Arrl ( 2 to 6) As Integer A 6 B 7 C 8 D 9 +1 Arrl6 ( 2)+1=9 D 3 Option Base 1 Dim Arr4(6,5) As Integer A 42 B 30 C 37 D 36 Option Base 1 Dim Arr4(6,5) As Integer Dim Arr4(1 to 6,1 to 5) As Integer 30 B 4 Option Base 0 Private Sub Form_Click() Dim a Dim i As Integer a=array(1,2,3,4,5,6,7,8,9) For i=0 To 3 Print a(5 i) Next A 4 3 2 1 B 5 4 3 2 C 6 5 4 3 D 7 6 5 4 Option Base 00 a=array(1,2,3,4,5,6,7,8,9) a(0) a(8) 1 9 For a(5) a(2)6 5 4 3 C 5Command1 Option Base 0 Private Sub Command1_Click() Dim city As Variant city = Array("","","","") Print city(1)

11 115 A B C D Option Base Array0 D D 6 Command1 Option Base 1 Private Sub Command1_Click() Dim I As Integer For I=1 To 3 For j=1 To 3 X(I,j)=(I j)*3+j Next j Next I For I=1 To 3 Print x(i,4 I) Next I A 1 5 9 B 1 4 7 C 3 5 7 D 3 6 9 For 3 3X 1 3For3 X(1,3) X(2,2) X(3,1) X(1,3)=(1 1) 3+3=3 X(2,2)=(2 1) 3+2=5 X(3,1)=(3 1) 3+1=7 C 7 Text1Command1 Private Sub Command1_Click() Dim array1(10,10) As Integer Dim i,j As Integer For i=1 To 3 For j=2 To 4 array1(i,j)=i+j Next j Next I Text1.Text=array1(2,3)+array1(3,4)

116 2 A 12 B 13 C 14 D 15 array1(2,3)+array1(3,4)=2+3+3+4=12 A 8 Command1 Private Sub Command1_Click() Dim I As Integer, a(9) As Integer For I=9 To 0 Step 1 a(i)=10 I Next I Print a(2);a(5);a(8) A 2 5 8 B 7 4 1 C 8 5 2 D 3 6 9 a10 a(0) a(9) For10 a(0) a(9) 10 1a(2) a(5) a(8) 8 5 2 C 9Command1 Private Sub Command1_C1ick() Static b As Variant b=array(1,3,5,7,9) b5 9 7 5 3 1 A For i=0 To 5-1\2 B For i=0 To 5 tmp=b(i) tmp=b(i) b(i)=b(5 i 1) b(i)=b(5 i 1) b(5-i-1)=tmp b(5-i-1)=tmp Next I Next I C For i=0 To 5\2 D For i=1 To 5\2 tmp=b(i) tmp=b(i) b(i)=b(5-i-1) b(i)=b(5-i-1) b(5-i-1)=tmp b(5-i-1)=tmp Next I Next I For B(0 n 1) nb(0) b(n 1) b(1) b(n 1 1) b(i) b(n i 1) i=0 1 2 n\2forn\2

11 117 b(i) b(n i 1)C C 10 Private Sub Command1_Click() Dim MyWeek, MyDay MyWeek=Array("Mon","Tue","Wed","Fri","Sat","Sun") MyDay= MyWeek(2) MyDay= MyWeek(4) MsgBox MyDay A Sat B Tue C Wed D Thu 0 MyWeek(4)5 Sat A 11Form_Click3 Option Base 1 Private Sub Form_Click() Dim i As Integer, j As Integer a(5,5) As Integer For i=1 to 5 For j=1 to 5 If i=j Then a(i,j)=i+j Else If i>j Then a(i,j)=1 Else a(i,j)=0 End If End If Next j Next i For i=1 to 5 For j =1 to 5 Print a(i,j) Next j Print Next i A 2 1 1 1 1 B 1 1 1 8 0 C 1 1 6 0 0 D 2 4 0 0 0 5 5a For a

118 2 10 a 3 1 1 6 0 0 C 12 Command1 Private Sub Command1_Click() Dim i As Integer,j As Integer Dim a(10,10)as Integer For i=1 To 3 For j=1 To 3 a(i,j)=(i 1)*3+j Print a(i,j) Next j Print Next j A 123 B 234 C 147 D 123 246 345 258 456 369 456 369 789 1 93D D 13 Command1 Private Sub Command1_Click() Dim i As Integer, k As Integer Dim a(9) As Integer Dim p(2) As Integer k=5 For i =0 to 9 a(i)=i Next i For i =0 to 2 p(i)=a(i*(i+1)) Next i For i=0 to 2 k=k+p(i)*2 Next i Print k

11 119 A 20 B 21 C 22 D 23 a p For a a(0) a(9) 0 9 p p(0)=a(0*1)=0 p(1)=a(1*2)=2 p(2)=a(2*3)=6p2 kk 21 B 14 List1Command1List1 MultiSelect 2Command1 Private Sub Command1_Click() For I =List1.ListCount 1 to 0 Step 1 If =True Then List1.Removeitem I End If Next I A List1.select(i) B List1.sort(i) C List1.list(i) D List1.select(List1.listindex) Select TrueFalse Select True A 15 Type Student Num As Integer Name As Integer * 13 End Type Dim stu(30) As Student A C B D Type Student Num Name 30stu B 16Form1_Click Private Sub Form_Click()

120 2 Dim M As Integer, K As Integer,t As Integer M=6:K=8 Select Case M Case Is<0 M=M+5 Case 1 To 10 t=m:m=k:k=t Case Is >10 M=K Mod 3 End Select Print M, K, t A 6 6 8 B 6 8 6 C 8 6 8 D 8 6 6 Form_Click M K 6 8 Select Case M M 6 2 Caset=M:M=K:K=tt 6 M 8 K 6 D 17Command1 Option Base 1 Private Sub Command1_Click() Dim a As Variant a=array(1,2,3,4) j=l For I=4 To 1 Step 1 s=s+a(i)*j j=j*10 Next I Print s A 4321 B 1234 C 34 D 12 4 1+3 10+2 100+1 1000=1234 B 18Form1_Click3 Option Base 1 Private Sub Form_Click() Dim I As Integer,j As Integer Dim k As Integer,a(5,5) As Integer For I=1 to 5

11 121 k=1 For j=1 to 5 If I<=j Then a(i,j)=k k=k+1 Else a(i,j)=1 End If Next j Next I For I=1 to 5 For j=1 to 5 Print a(i,j) Next j Print Next I A 1 2 3 4 5 B 1 1 2 3 4 C 1 1 1 2 3 D 1 1 1 1 2 5 5 For 1 1 1 For a3 1 1 1 2 3 C 19 A BName C Index D Index D D 203 chkoption

122 2 A Tag B Index C ListIndex D Name A D C B B 11.2.2 1 Dim Arr2( 2 to 6,1 to 5) As Integer +19545 45 2Dim A (100)A Visual Basic0 Dim A(100)A 101 101 0 3 Option Base 1 Dim Arr5(0 to 6,0 to 5)As Integer A 42 B 30 C 37 D 36 Option Base 1 1 0Arr5 (6 0+1) (5 0+1) =42 A 4 Private Sub Command1_Click() score = Int(Rnd*10)+80 Select Case score Case Is<60 a$ ="F" Case 60 To 69 a$ = "D" Case70 To79 a$="c" Case 80 To 89 a$="b"

11 123 Case Else a$ ="A" End Select Print a$ score Int(Rnd*10)+80 Rnd0 1 100 9 80 80 90 Select Case score Case Case 80 To 89 Casea$="B" B B 560 Option Base 1 Private Sub Command1_Click() Dim d 6 For i=1 To 60 n = d(n) = Next i For i = 1 To 6 Print d(i) Next i 1 6 Int(1+6*RnD) d d(n)+1 Int(1+6*RnD) d(n)+1 62020 Option Base 1 Private Sub Form_Click() Dim a(20) As Integer, i As Integer Dim t as Integer,j As Integer Randomize For i=1 to 20 a(i)=10+int(90*rnd Print a(i);

124 2 Next i Print i=1: Do while i<j t=a(i): :a(j)=t i=i+1:j=j 1 Loop For i=1 to 20 Print a(i) Next i Print i1j20 a(i) a(j) i j ij j j=20a(i) a(j) a(i)=a(j) j=20 a(i)=a(j) 7 Command1 Text1 Text24 Label1 Label2 Label3 Label4 12 4 Option1 + * / Text1 Text2 Label4 3 Private Sub Command1_Click() For i=0 To 3 If =True then opt=option1(i).caption End If

11 125 Next Select Case Case"+" Result=Val(Text1.Text)+Val(Text2.Text) Case" " Result=Val(Text1.Text) Val(Text2.Text) Case"*" Result=Val(Text.Text)*Val(Text2.Text) Case"/" Result=Val(Text1.Text)/Val(Text2.Text) End Select =Result Value True 1 Option(i).Value Select opt2optlabel4 3 Label4.Caption Option(i).Value opt Label4.Caption

12 12.1 12.1.1 Sub Sub 1 Sub 1 Sub Sub [Static][Public Private]Sub [()] 2 Sub 2 Sub Sub 1 Call [()] 2 [] 1 2 3 Sub Function Sub

12 127 12.1.2 Function 1 Function Function [Static][Public Private]Function ([]) [As ] = End Function 2 Function ([]) 3 Sub Function Sub FunctionFunction Sub Function Function FunctionSub Sub Sub Function 12.1.3 1.

128 2 2. ByDef 3. ByVal 4. 5. 12.1.4 Optional IsMissing Variant ParamArray Sub ParamArray Variant 12.1.5 Form Control

12 129 12.2 12.2.1 1 A Form_Load B CSub D 0 Form_Load Static A B D C C 2 A BPublic CDim DPublic Dim Visual Basic3/ /Private Dim Public B 3 A B C D C C

130 2 4 A B C D D D 5 Command1 Label1 Label2 Private x As Integer Private Sub Command1_Click() 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 xprivate YCommand1_Click() Proc x25 y 25 3 B 6 A Void play(var a:integer,var b:integer) B Sub play(int a,b) C Void play(int a,int B) D Sub play(a As Integer,b As Integer) Visual Basic Sub 4A Visual Basic Var Void B CInteger D D 7

12 131 A Static Static B Sub Sub C Sub Sub D Static Static Sub Sub Function Sub Sub Sub 4 D D 8 AShell Windows BShell Visual Basic C Shell < >=Shell() DShellDOS DOS Windows Shell com exe bat pie Shell Visual BasicShellB B 9 Option Base 1 Private Sub fun(a() As Integer,n As Integer) ReDim Preserve a(6) a(6)=a(1)*a(3)*a(5) n=ubound(a Private Sub Command1_Click() Dim arr1() As Integer,k As Integer ReDim arr1(5) For i=1 To 5 Arr1(i)=i Next i k=6 Call fun(arr,k) Print arr1(1); arr1(k)

132 2 A 1 3 B 0 0 C 1 15 D 0 15 Command1_Click arr1 5 Forarr1(1) arr1(5)1 5 funk6 funa6 a(6) 1 3 5=15Uboundnn 6 aarr1 nk arr1(1) arr1(6) 1 15 C 10 Command1 F1F1 F11 0 A Private Sub Command1_Click() x=inputbox(" ") a=f1(val(x)) Print a Function F1(ByRef b As Integer) If b Mod 2=0 Then Return 0 Else Return 1 End If End Function B Private Sub Command1_Click() x=inputbox(" ") a=f1(val(x)) Print a Function F1(ByRef b As Integer) If b Mod 2=0 Then F1=0 Else F1=1 End If End Function C Private Sub Command1_Click() x=inputbox( ) F1(Val(x))

12 133 Print a Function F1(ByRef b As Integer) If b Mod 2=0 Then F1=1 Else F1=0 End If End Function D Private Sub Command1_Click() x=inputbox(" ") F1(Val(x)) Print a Function F1(ByRef b As Integer) If b Mod 2=0 Then Return 0 Else Return 1 End If End Function Val(x)x ByRef Return b Mod 2=0b B B 11 Private Sub test(p, m, n) p = p + 1: m = m + 1: n = n + 1 Print "Sub:"; p; m; n Private Sub Command1_Click() a1 = 1: b1 = 2: c1 = 3 Call test(a1, b1 + 3, (c1)) Print "main"; a1; b1; c1 A Sub:26 4 B Sub 2 6 4 C Sub: 26 4 D Sub: 2 6 4 Main:26 4 Main: 1 6 4 Main: 12 3 Main: 2 2 3

134 2 testa1 b1+3 (c1)testa1 b1 c1 D D 12 Command1 Text1 Private Sub Command1_Click() Dim x,y,z As Integer x=5 y=7 z=0 Text1.text="" Call P1(x,y,z) Text1.Text=Str(x) Sub P1(ByVal a As Integer,ByVal b As Integer,c As Integer) c=a+b A 0 B 12 C Str(z) D CallP1 c P1 z12 B 13 Private Sub func(a As Integer) Static m As Integer Dim n As Integer m=m+a n=n+a Print m; n Private Sub Command1_Click() Dim k As Integer k=4 Call func(k) Call func(k) A 4 8 B 4 4 C 4 4 D 8 4 8 8 8 4 8 8 8 8

12 135 Command1_Clickk4 funckafuncm n m n44 4func m 4n 0 m 8 n 4 8 4 B 14 Dim a As Integer, b As Integer Private Function fun() Dim a As Integer a=5 Print a;b End Function Private Sub Command1_Click() b=5 Call fun Print a;b A 5 5 B 0 5 C 5 0 D 5 5 0 5 0 5 5 5 5 5 a a bcommand1_clickb 5 func a5 a a b5 a b 0 5 A A 15 Option Base 1 Private Sub fun (a() As Integer, n As Integer) ReDim Preserve a (n) a(6)=a(1)+a(2)+a(3)+a(4)+a(5) n=3 Private Sub Command1_Click() Dim arrl() As Integer,k As Integer ReDim arrl(5) For i=1 To 5 arrl(i)=i Next i k=6

136 2 Call fun(arrl,k) Print arrl(i); arrl(k);arrl(6) A 1 3 6 B 1 3 0 C 1 3 15 D Command1_Clickarrl 5 For arrl arrl(1) arrl(5) 1 5 fun arrlaknfun 6a(6) 1+2+3+4+5=15n3 a n arrl(1) arrl(5) 1 5arrl(6) 15 k 3 arrl(1) arrl(3) arrl(6) 1 3 15 C 16Form_Click Option Explicit Private x As Integer Public y As Integer Sub Test() Dim y As Integer x=2:y=2 Print "x=";x, "y=";y Private Sub Form_Click() x=1:y=1 Test Print "x=";x, "y=";y A x=2 y=2 B x=2 y=2 C x=2 y=1 D x=2 y=1 x=2 y=1 x=2 y=2 x=2 y =2 x=2 y=1 x y x y1 Test y x2y2x y2 x 2 y 1A A 17 Private Sub fun(byval x As Integer, ByVal y As Integer,z As Integer) z=x^3*y^3 Private Sub Command1_Click() Dim a As integer

12 137 Call fun(2,3,m) Print m A 216 B 0 C 35 D Command1_Clickfun2 3 x y mz fun z=x^3*y^3z 216 m 216 A 18 Dim a As Integer Dim b As Integer Private Sub fun() a=100 b=200 Private Sub Command1_Click() Dim a As Integer a=5 b=7 Call fun Print a; b A 100 200 B 5 200 C 100 7 D 5 7 a b Command1_Click aa a5 b7 funfun a b100 200 a b a5 b 200 B 19 Private Function fun3(x As Integer) Static a As Integer a=a+3 a=a+x fun3=a End Function Private Sub Command1_Click() Dim k As Integer,p As Integer k=2:m=1 n=fun3(k)

138 2 n=fun3(m) Print n A 6 B 7 C 9 D 12 Command1_Clickfun3k xfun3 aa 5 5 nfun3 5a 99n n9 C 20 Private Sub fun() Static a As Integer a=a+2 Print a Private Sub Command1_Click() Dim m As Integer For m=1 to 3 Call fun Next m A 2 2 2 B 0 0 0 C 2 4 8 D 2 4 6 Command1_ClickFor3 3 funfun aa fun a23 2 4 6 D 21Form_Click2 3 Private a As Integer, c As Integer Private Sub Form_Click() Dim a As Integer,b As Integer a=10 :b=10 :c=10 Print a,b,c Call test1(a,b Print a,b,c Private Sub test1(m As Integer,ByVal n As Integer) Dim c As Integer m=5:n=5:c=5 Print m,n,c

12 139 A 5 5 5 B 5 5 5 C 5 5 10 D 5 5 5 5 10 10 5 5 10 5 10 10 10 10 10 a cform_click a b10 10 10 test1 a m b ntest1cm 5 a5nc5 test1 5 5 5a b c 5 10 10 A 22 Function Fun(S As String) As String Dim s1 As String For i=1 To Len(S) s1=ucase(mid(s,i,1))+s1 Next i Fun=s1 End Function Private Sub Command1_Click() Dim Str1 As String,Str2 As String Str1=InputBox("") Str2=Fun(Str1) Print Str2 abcdefg A abcdefg B ABCDEFG C gfedcba D GFEDCBA FunLen(s) Mid(S,i,1) S i1 Ucase( ) s1abcdefg GFEDCBA D 23 Form1 Form2 mdlfunc Form1 Form2 mdlfunc Form1 Private Sub frmfunction1()

140 2 Form2 Public Sub frmfunction2() mdlfunc Public Sub mdlfunction() A 3 B frmfunction2 mdlfunction C 3 D mdlfunction PrivateA Public B PublicC D D 12.2.2 1 Function fact(x As Integer) As Long Dim p As Long, I As Integer P=1 For I=1 To x p=p*i Next I fact=p End Function Private Sub Command1_Click() i=val(input Box(" "))

12 141 a=fact((i)) Print a 5 fact(x)x!5 fact 1 2 3 4 5=120 120 2 Private Sub Command1_Click() a = 1: b = 1 Print "a="; a, "b="; b Call mult((a), B) Print "a="; a, "b="; b Sub mult(x, y) x = 2 * x y = 3 * y Print "x="; x, "y="; y 5 Print 1 a 2 b a 1b 35 Printa=1 b=3 a=1 b=3 3 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

142 2 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 5 41 10000 fact Private Sub Command1_Click() For k = 1 To 10000 a = LTrim(Str(k)) n = 0 For i = p = Val(Mid(a, i, 1)) n = Next i If n = k Then Print k Next k Function fact(x) If x <= 1 Then fact = 1 Else fact = End If End Function For1 To Len(A) fact n+fact(p) x * fact(x 1) 1 To Len(A) n+fact(p) x * fact(x 1) 51 +2 +3 + +10 Private Sub Form_Click() Dim s As Long,I As Integer s=0 For I=1 to 10

12 143 s=s+ Next I Print s Private Function fact(byval n As Integer) As Long Dim i As Integer,f As Long f=1 For i=2 To n f=f*i Next i End Function Form_ClickFor 1 10 s factifact(i) fact For2nf fnvisual Basic fact=f fact(i) 6 fact=f 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 v=v+20 Sub p2(byval x As Integer, y As Integer) x=x+10 y=y+20 Sub p3(byval x As Integer, ByVal y As Integer) x=x+10 y=y+20 a= b= ByVal ByRef 30 70

13 13.1 13.1.1 KeyPress KeyPress ASCII KeyPress KeyPressIndex As Integer KeyAscii As Integer KeyAscii KeyPressKeyAscii ASCII KeyPress KeyAscii KeyPress KeyAscii 13.1.2 KeyDown KeyUp KeyDown KeyUp KeyDown KeyUpKeyPress KeyDown KeyUp KeyPress ASCII KeyDown KeyUp Index As IntegerKeyCode As Integer Shift As Integer 13.1.3 1 MouseDown MouseUp MouseMove Button Shift x y 2 Button Button3 16 338 8

13 145 3 Shift Button Shift 316 3 3ShiftCtrlAlt88 4 x y 13.1.4 WindowsVisual Basic MousePointer MousePointer160 15 10.9 13.1.5 1 DragMode 1 00 1 Click MouseDrown DragIcon 2 DragDrop DragOver 3 Move DragDragMode 01 2DragDrop 13.2 13.2.1 1

146 2 AKeyUp KeyDownA a KeyCode BKeyUp KeyDown 11 KeyCode C KeyPress D KeyPress 3 KeyPress ASCII Shift ASCII KeyUp KeyDown 4C C 2 Text1ASCII A KeyDown B Change C KeyUp D KeyPress 4 KeyDown KeyUp Keycode Change KeyPressKeyASCIIASCII D 3 A A KeyDown KeyPress KeyUp Change B KeyDown KeyPress KeyUp Change C KeyDown Change KeyUp KeyPress D KeyPress Change KeyDown KeyPress Change KeyUpChange A 4 A 4 Txta Private Sub Txta_KeyPress(KeyAscii As Integer)

13 147 KeyPress A C B D 4 KeyPress D 5 Ctrl a Private Sub Text1_KeyDown(KeyCode As Integer,Shift As Integer) Print KeyCode,Shift A a 2 B 65 2 C 97 1 D 97 2 KeyDownKeyCode Shift KeyCode a65 Shift Shift Ctrl Alt Shift Shift0 1Ctrl Shift1 1 Alt Shift2 1 Ctrl Shift 2 B 6KeyDown KeyPress Private Sub Text1_KeyDown(KeyCode As Integer,Shift As Integer) Private Sub Text1_KeyPress(KeyASCII As Integer) A KeyDownKeyCode KeyPressKeyASCII B 11 KeyCode C KeyCode D KeyASCII KeyDownKeyCode KeyPress KeyASCIIASCII

148 2 KeyASCIIC C 7 MouseDown Private Sub Form_MouseDown(Button As Integer,Shift As Integer, X As Single,Y As Single) A Button B Shift C X D Y MouseDown4Shift 3 Button 0 11 12 1 A 8 A DragMode B DragOver C DragDrop D DragIcon DragMode10 DragOverDragOver DragDrop Drag DragDrop DragIcon Icon Cur A 9 A Move CLeft B DTop Move LeftTop B B 10MouseIcon

13 149 MousePointer A 0 B 1 C 64 D 99 MousePointer 1 15 99MouseIcon D 11 Private Sub form MouseDown(Button As Integer,Shift As Integer,X As Single,Y As Single) If Shift=6 And Button=2 Then Print "BBBB" End If BBBB A Shift C Ctrllt B Shift D Ctrl Alt MouseDown Button Shift Button 1 2 3 Shift 30Shift 1Crtl 2Alt 6110CtrlAlt D D 12 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 D Button=2

150 2 Button12 4 D D 13.2.2 1 Command1_Click Command1 True Default Default 2MousePointer MouseIcon MousePointer99 99 31Text1 2 Text2Tab Private Sub Text1_KeyDown(Keycode As Integer, Shift As Integer) If Then Text2. End If Text2 SetFocus Text2 KeyDownKeyCode 13KeyCode=13 SetFocus KeyCode=13 SetFocus 4 KeyPress KeyDown True KeyPress KeyPreviewTrue KeyPress KeyUp KeyDown KeyPreview 5 Combo1Label1 Label2 Caption ASCII13 Label2 Label2 3

13 151 Private Sub Combo1 (KeyAscii As Integer) If KeyAscii=13 Then For i=0 To Combo1.ListCount 1 If Combo1.Text= Then Label2.Caption=" " Exit Sub End If Next i Label2.Caption="" Combo1. Combo1.Text End lf KeyPress List List AddItem KeyPress Combo1.List(i) AddItem 6 0 Drag 0 21 DragMode01 Drag 0 1 2 DragMode