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
14 14.1 14.1.1 14.1.2 1 EnabledTrue False 2 OnOff CheckedTrue False 3
14 153 Alt & Caption Caption 14.1.3 14.1.4 PopupMenu PopupMenu11.711.8 PopupMenuMouseDown Button 14.2 14.2.1 1 A BVisible False C - D Visible True Enabled False Checked True Visible True - C
154 2 C 2 A B & CVisible D Caption Name A 3 MenuItem1 A MenuItem1.Caption=" " C MenuItem1.Enabled=True B MenuItem1.Checked=True D MenuItem1.Visible=True Caption Checked True Enabled True VisibleTrue B 4 A B Enabled False C D BEnabledFalse B 5MenuItem1E dit A MenuItem1.Caption=" \E dit" B MenuItem1.Caption=" &E dit"
14 155 C MenuItem1.Caption=" >E dit" D MenuItem1.Caption=" <>E dit" Caption & B B 6menu1 A Menu1.Enabled=True C Menu1.Visible=True B Menu1.Enabled=False D Menu1.Visible=False Enabled VisibleEnabled Visible D 7 pl Visible False Form1 A Popup pl B Forml.Popup pl C pl.popup D Popup Forml.pl Visible FalsePopup.Popup B B 14.2.2 1Visual Basic 2Visual Basic 3Unload Unload Enabled Visible 4 Click
156 2 5 6Pmenu Form1. Pmenu Visible False PopupMenu PopupMenu
15 15.1 15.1.1 ActiveVisual Basic Help 15.1.2 DefaultEXT Dialog FileName FileTitle Filter Filter Index Index Flags InitDir MaxFileSize CancelError HelpCommand HelpContext HelpFile HelpKey 15.1.3 1 Color FlagsFlags Flags12.612.7 2 Flags FontBold FontItalic FontName FontSize FontStrikeThru FontUnderline Max Min Flags 12.812.9 3 Copies Flags FromPage ToPage hdc Max Min PrinterDefault Flags 12.1012.11
158 2 15.2 15.2.1 1 A B ShowOpen ShowSave C ShowOpen D ShowColor CommonDialog Timer C C 2 A FileName B Filter C FilterIndex D InitDir FileName Filter FilterIndex InitDir B 3.txt A "text (.txt) (*.txt) " B "(.txt) (.txt) " C "text(.txt) (*.txt) " D "text(.txt)(*.txt) " Filter
15 159 description1 filter1 description2 filter2 A A 4Cdlg A Cdlg.ShowOpen C Cdlg.ShowSaveAs B Cdlg.ShowSave D ShowOpen Cdlg ShowOpen ShowSave ShowFont Action ShowOpenA A 5Cdlg A Cdlg.Action=6 C Cdlg.Action=4 B Cdlg.Action=5 D Cdlg.Action=3 Action 6 A 6 A FileName B Filter C FilterIndex D Name 4 FileName Filter FilterIndex Name A 7 A FontSize B FontName C Max D Min 4 FontSize FontName MaxPoint Min Point
160 2 C C 8 A Copage B FromPage C Pages D Topage 4 Copage FromPage Topage A Pages A 9 FileName A B C D FileName D D 10 CommonDialog1Command1 Save SaveFile*.txt A Private Sub Command1_C1ick() CommonDialog1.FileName="SaveFile" CommonDialog1.Filter= "All Files *.* (*.txt) *.txt (*.doc. *.doc" CommonDialog1.FilterIndex=2 CommonDialog1.Dialog.Title="Save" CommonDialog1.Action=2 B Private Sub Command1_Click() CommonDialog1.FileName="SaveFile" CommonDialog1.Filter="A11 Files *.* (*.txt) *.txt *.doc *.doc" CommonDialog1.FilterIndex=1 CommonDialog1.DialogTitle="Save"
15 161 CommonDialog1.Action=2 C Private Sub Command1_C1ick() CommonDialog1.FileName="Save" CommonDialog1.Filter="All Files *.* (*.txt) *.txt (*.doc *.doc" CommonDialog1.FilterIndex=2 CommonDialog1.DialogTitle="SaveFile" CommonDialog1.Action=2 D Private Sub Command1_C1ick() CommonDialog1.FileName="SaveFile" CommonDialog1.Filter="All Files *.* (*.txt) *.txt (*.doc *.doc" CommonDialog1.FilterIndex=1 CommonDialog1.DialogTitle= Save CommonDialog1.Action=1 Action2 DDialogTitle C *.txtfilter FilterIndex 1 12 2B A 15.2.2 1 FileName FileTitle FileName FileTitle 2Form1CommonDialog1 Action 2 CommonDialog1.showSave 3Form1 Form2 Form2 Form1.show vbmodeless,form2
16 16.1 16.1.1 1 1 Load Load 2 Unload Unload 2 [].Show [] 1 0 []. Hide 16.1.2 1 Visual Basic Show 2
16 163.exe 16.1.3 Visual Basic Visual Basic Visual Basic3 1 Public Dim Private 2 Dim Public 3 SubMain SubMain Form_LoadSubMain SubMain SubMain SubMain SubMainVisual Basic 16.1.4 DoEvents DoEventsVisual BasicDoEvents
164 2 DoEvents [ =]DoEvents[()] DoEvents DoEvents DoEvents CPU DoEvents 16.2 16.2.1 1 A Sub Main BShow CHide Unload D Sub Main Hide Unload C 2 A BPrivate CVisual Basic D B 3Visual Basic A B
16 165 CForm1 D Visual Basic 1 B 4MDI A B CMDI DMDI MDIMDI MDI D 5 Form1Form2X Form1 A Dim X As Integer C Private X As Integer B Static X As Integer D Public X As Integer Dim Private Static Public D 6 MDI A MDI BMDI C MDI DMDI MDI MDI MDIMDIMDI MDI MDI B
166 2 B 7 Form1 A Form1.Unload B Close Form1 C Form1.End D Unload Form1 Unload EndA C Visual Basic Close BUnload D D 8 MDI A MDI B MDI C D MDIMDI MDI MDI MDI MDI MDI MDIMDI D D 9 MDI A MDIForm1.Arrange0 C MDIForm1.Arrange2 B MDIForm1.Arrange1 D MDIForm1.Arrange3 MDIArrangeArrange 0 MDI 1 MDI 2MDI 3 MDI C C 10 4 DoEvents
16 167 A DoEvents B DoEvents C DoEvents D DoEvents DoEvents C C 11 A B C D D D 16.2.2 1Form1 Initialize Load Activate Resize Paint Paint 2myfrm1 Command1_Click Visual BasicShow Show Visual BasicModel 1Visual BasicModel 0 myfrm1.show vbmodel myfrm1.show 1 3 DoEvents Visual Basic DoEvents 4 Me
168 2 Me MeUnload Form1 Unload 5
17 17.1 17.1.1 1 2 1 2 3ASCII ASCII ASCII 17.1.2 1 Open [For ] [Access ] [] As[#] [Len=]
170 2 5 Input Output Append Output Random/ Binary Output Append Input Random Binary 2 Close # Open 3 1 Seek Seek # Input Output Append Random Get Put Seek 0 SeekSeek
17 171 2 Seek Seek( ) Input Output AppendSeek RandomSeek SeekSeek 4 1 FreeFile 2 Loc Loc( ) 3 LOF LOF( ) Visual Basic 128 128 4 EOF EOF( ) True False GetTrue
172 2 Do While EOF(1) Loop 17.1.3 1 Print# Write# 1 Print# Print#,[[Spc(n) ab(n)][][;,] Print# Print# Print# 2 Write# Write#,[] Write# Output Append Print# Write# 2 Input # Line Input # 1 Input # Input#,
17 173 2 Line Input# Line Input#, 3 Input$ Input (,# ) 17.1.4 / 1 1 Put #[ ] Get Put Seek Open Len Put 2 Get #[ ]
174 2 2 17.1.5 1 1 Drive Click Change 2 Path Click Change 2 Pattern Click DblClick 17.1.6 1Kill Kill *? 2FileCopy
17 175 FileCopy, FileCopy * 3 Name Name As Name * 17.2 17.2.1 1 A B C Open D Input # 4 Open Input # Get # B B 2 Path A
176 2 B C D A 3 True A Archive B Normal C Hidden D System ArchiveTrue HiddenTrue SystemTrue NormalTrue C 4 OpenFor A Output B Input C Append D Random Visual BasicFor Random D 5 A B C D Input # Print # Get # Put #Input # Print # D D 6 Open "c:test.dat" For OutPut As #1 AC Test.Dat
17 177 B C Test.Dat C1 D Print # Test.Dat OutputOpen A 7Text1 Text2 Command1 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(p) Get #1,1,p Close #1 plen A BPut Get Get C C
178 2 8ListIndex A2 B1 C 0 D 1 ListIndex 0ListIndex 1 B 9 Loc A B C /128 D LocOpen / 128 A A 10 A Drive B Path C Name D Pattern 4 Path Name Drive Pattern B B 11 Path A B C D Path A 12 Drive1 Dir1
17 179 File1Label1 Label2 Label1 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 Private Sub Drive1_Change() Dir1.Path=Drive1.Drive Label1.Caption=File1.ListCount 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
180 2 Drive1 Dir1File1 Drive1_Change Dir1.Path=Drive1.Drive Dir1_Change File1.Path=Dir1.Path C C 13 Type Books Name As String *10 TelNum As String *20 End Type Command1 Command1_Click Person. txt A Private Sub Command1_Click() Dim B As Books Open "c:\person.txt" For Output As #1 B.Name=InputBox("") B.TelNum=InputBox("") Write #1,B.Name,B.TelNum Close #1 B Private Sub Command1_Click() Dim B As Books Open "c:\person.txt" For Input As #1 B.Name=InputBox("") B.TelNum=InputBox("") Print #1,B.Name,B.TelNum Close #1 C Private Sub Command1_Click() Dim B As Books Open "c:\person.txt" For Output As #1 B.Name=InputBox("") B.TelNum=InputBox("") Write #1,B Close # 1 D Private Sub Command1_Click() Open "c:\person.txt" For Input As #1 Name=InputBox("") TelNum=InputBox("") Print #1,Name,TelNum Close #1
17 181 B D Input C Write #A A 14Open "Text.Dat" For Output As # FreeFile A Text.Dat BText.Dat CText.Dat DText.Dat OutputText.Dat Text.Dat C C 15 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 Open Append B B 17.2.2 1 Visual Basic 3 2C a1.txt FileLen FileLen LOF FileLen("C:\a1.txt")
182 2 3 Drive1Dir1 Drive1_Change Change Path Drive1_Change Dir1.Path=Drive1.Drive Dir1.Path=Drive1.Drive 4 10 3 Dmyfile1.dat Private Sub Form_Click() Dim k As Integer Open Randomize For I=1 To 10 K=100+Int (899*RnD) "d:\myfile1.dat" For Random as # 1 For 10 Put Put # 1, I, k Close # 1 Next I "d:\myfile1.dat" For Random As # 1 Put # 1, I, k Close # 1 5Ca1.txt Da2.txt Private Sub Form_Click() Dim Ch As String Open "c:\a1.txt" For As # 10 Open"d:\a2.txt" For Output As # 20 Do While LineInput # 10,Ch Loop Close # 10 Close # 20
17 183 Input Do While Not EOF 10 20,Ch Print # Input Not EOF 10 Print # 20,Ch 610D a1.dat 5 Private S Dim k As Dim n As Int N=Len(k) ub Form_Click() Integer eger,i As Integer Open As #10 Len=n For I=1 To 10 K=InputBox(" ") Next I Get # 10,k Print k "D:\a1.dat" For Random For 10Put #10,I,k 5Seek #5 Seek #10, 5 Get# "D:\a1.dat" For Random Put # 10,I,k Seek # 10, 5 7al.txt Private Sub Form_Click() Dim Ch As String *1 Dim n As Integer Open "c:\al.txt"for Input As #10 Do While Ch=Input(1,#10) If Then n=n+1 End If Loop Close #10
184 2 nal.txt n 1 Not EOF(10) Ch>="0" And Ch< ="9" n Print n Not EOF 10 Ch>="0" And Ch<="9" Print n 810 1 100 Option Base1 Private Sub Form_ Click() Dim a 10 As Integer,I As Integer Dim sum As Integer, aver As Single For I=1 To 10 a(i)=int(100 *Rnd )+1 sum=sum+ a(i) Next I Print sum,aver 10a For sumfor Randomize Randomize aver=aver/10 Randomize aver=aver/10 9 File1Dir1 Dir1_Change Change Path Change Path PathFile1.Path=Dir1.Path File1.Path=Dir1.Path
3 >>>>
18 18.1 1 Pentium 300MHz 64MB 24 300MB 800 600(VGA) 2 Windows 2000 Visual Basic 6.0 18.2 1 1003 21530 22040 130 2 90 5
18 187 18.3 1 18-1 18-1 18-118-2 18-2 2 18-2
188 3 18-3 18-3 N Y 18-4 18-4 3 90
18 189 3 4 18-518-6 18-5 18-6 3 3
190 3 5 Visual Basic 6.0Visual Basic 6.0 Visual Basic 6.0 Visual Basic Visual Basic 6.0 Visual Basic 6.0 518-7 18-7 6 Visual Basic 6.0 18-8 18-8 18-9
18 191 18-9 18-10 18-10 18.4 3 1 3 1 2 Visual Basic 2 2? 3 1
192 3 2 1 2 Visual Basic 3 4
19 1 Form1 Labe11 Text1 Text Command1 Click sjt1.vbp sjt1.frm Visible False Print ClickCancel TrueEsc Click Default True Click Click Private Sub Command1_Click() Label1.Visible = False Text1.Visible = False Form1.Print Text1.Text
194 3 2 Form1Text1 Text FontNameHScroll1 Min 10 Max 100 LargeChange 5 SmallChange 2 sjt2.vbp sjt2.frm ValueFontSizeValue ChangeChange Change Private Sub HScroll1_Change() Text1.FontSize = HScroll1.Value 3 Form1 Command1 3 Index 0 1 2 300 800 sjt1.vbp sjt1.frm
19 195 Height Left 300 800Ctrl+C Ctrl+V 3Command1 Caption 4 Form1Text1 0 C1T1 1 Text1.Text=Text1.Text+1 T1.Enabled=True sjt2.vbp sjt2.frm T1EnabledFalse C1 ClickT1 EnabledTrue 1T1 Interval1 000T11 TimerIntervalC1 Click T1.Interval = 1000 Timer Text1.Text = Text1.Text + 1 11 Text Name Command1Caption T1 Enabled False Click Private Sub Command1_Click() T1.Enabled = True Timer Private Sub T1_Timer() Text1.Text = Text1.Text+1
196 3 5 Form1 Timer1 1 Timer 2 sjt1.vbp sjt1.frm Timer IntervalTimer Interval=1 0001 1 Timer Interval=10 00010 1 Timer Interval=0Timer Interval 65 535 1 Timer1 Interval 1 000 6 Form1Text1 P1 sjt2.vbp,sjt2.frm Text1 KeyPress KeyUp KeyDown
19 197 Private Sub Text1_KeyPress(KeyAscii As Integer) Picture1.Print Text1.Text+Chr(KeyAscii) Private Sub Text1_KeyUp(KeyCode As Integer,Shift As Integer) Picture.Print Text1.Text 7 Form1 Label1 Label2 Text1 Text2 Text Command1 Click sjt1.vbp sjt1.frm InputBox 1 23 InputBox Text Private Sub Command1_Click() Dim a As String, b As String Text1.Text = InputBox(" ","") Text2.Text = InputBox(" "," ") 8 Form1Text1 HScroll1 Min 500 Max 2000
198 3 LargeChange 50 SmallChange 20 1.2 sjt2.vbp sjt2.frm Value ChangeValue Change Value Height WidthHeight Text1 HScroll1 Private Sub HScroll1_Change() Text1.Height = HScroll1.Value Text1.Width = Text1.Height * 1.2 9 Form12 file edit 3cut copy paste
19 199 sjt1.vbp sjt1.frm 2003/9 Visual Basic 4 33 10 Text1 Text2 Text1 * Text2 sjt2.vbp sjt2.frm 2003/9 TextText1 * Text1 PasswordChar* Text2 Text1 Change Text2.Text = Text1.Text Private Sub Text1_Change() Text2.Text = Text1.Text 11 Form1T1 T2 T1 T2
200 3 sjt1.vbp sjt1.frm 2003/9 10 Text T1 Text2 Text1 Change Text2.Text = Text1.Text Private Sub Text1_Change() Text2.Text = Text1.Text 12 Form1Text1 C1 sjt2.vbp sjt2.frm 2003/9 Width Private Sub C1_Click() Text1.Move (Form1.Width Text1.Width) 13 Form1Text1 Op Dis Exit
19 201 sjt1.vbp sjt1.frm 2003/9 Private Sub dis_click() Text1. Text = "" Private Sub exit_click() End 14 Form1L1 4 AAAA BBBB CCCC DDDD sjt2.vbp sjt2.frm 2003/9 ListIndex ListIndex Private Sub L1_Click() L1.RemoveItem (ListIndex) 15 Form1 T1 1400 400C1 C2 C1 C2 3
202 3 sjt1.vbp sjt1.frm2003/9 3 Text1.Height = 2 * Text1.Height Text1.Width = 2 * Text1.Width Text1.FontSize = 3 * Text1.FontSize Private Sub C1_Click() Text1.Text = "" Private Sub C2_Click() Text1.Height = 2 * Text1.Height Text1.Width = 2 * Text1.Width Text1.FontSize = 3 * Text1.FontSize 16 Form1C1 Text1 Text2 Text1 Text1 Text2Text1 visual basic programming sjt2.vbp sjt2.frm2003/9 LCase UCase LCase$ UCase$
19 203 Private Sub C1_Click() Text1.Text = LCase$(Text1.Text) Text2.Text = UCase$(Text1.Text) 17 Form1Command1 Command2 Command1 0.2 1.2 Command2 200 100 sjt1.vbp sjt1.frm2003/9 3 1.2 200 100 Private Sub Command1_Click() Form1.Height = 1.2 * Form1.Height Form1.Width = 1.2 * Form1.Width Private Sub Command2_Click() Form1.Left = Form1.Left + 200 Form1.Top = Form1.Top + 100 18 Form1Label1 Left 0 HScroll1 Min 0 Max 3000 SmallChange 10 LargeChange 100
204 3 sjt2.vbp sjt2.frm2003/9 Left Value HScroll1_Change Left Private Sub HScroll1_Change() Label1.Left = HScroll1.Value 19 Form1 1 2 File Open Close sjt1.vbp sjt1.frm 2003/9 20 Form1Text1 Text2 Text1 Text2 Text1Text2 Text1
19 205 sjt2.vbp sjt2.frm2003/9 Text1 Text2 Text1 Change Text2.Text = Text1.Text Font Private Sub Text1_Change() Text2.Text = Text1.Text 21 Form1Command1 CD1 sjt1.vbp sjt1.frm2003/9 ActiveX
206 3 Filter 1 12 2 2 Action CD1.Action = 1 Action CD1.ShowOpenShowOpen Private Sub Command1_Click() CD1.ShowOpen Filter FilterIndex Private Sub Command1_Click() CD1.Action = 1 22 Form1 Command1 100 sjt2.vbp sjt2.frm2003/9 Click Command1. Left = Command1.Left 100 Private Sub Command1_Click() Command1.Left = Command1.Left 100 23 Form1H1
19 207 100 1 10 L1 L2 1 100 sjt1.vbp sjt1.frm 2003/9 Max 100 Min 1 LargeChangeValue 10 24 Form1Text1 Text2 M1 Copy Clear Text1 Text2 Text2 Text2 sjt2.vbp sjt2.frm 2003/9 Click
208 3 Private Sub Copy_Click() Text2.Text = Text1.Text Private Sub Clear_Click() Text2.Text = "" 25 Form1 Label1 Label2 Text1 Text2 Text Command1 Click sjt1.vbp sjt1.frm 2004/4 Command1 Click() Private Sub Command1_Click() Print Text1.Text & "," & "" & Text2.Text & " " 26 Form1Picture1 Hscrol1Command1 pic1.jpg Min 100 Max 1500 LargeChange 100 SmallChange 10
19 209 sjt2.vbp sjt2.frm 2004/4 Command1 Click() HScroll1 Change() Width Value Private Sub Command1_Click() HScroll1.Max = 1500 HScroll1.Min = 100 HScroll1.LargeChange = 100 HScroll1.SmallChange = 10 Private Sub HScroll1_Change() Picture1.Width = HScroll1.Value 27 Form1 Label1 Text1 Text Command1 Click sjt1.vbp sjt1.frm 2004/4 VisibleFalse
210 3 Private Sub Command1_Click() Text1.Visible = False Label1.Visible = False Print Text1.Text
20 1 sjt3.vbp Item Add Delete List1 Text1 sjt3.vbpsjt3.frm Private Sub Add_ Click() Text1.Text = InputBox( " ") List1.AddItem? Private Sub Delete_Click() Text1.Text = InputBox(" ") For i = 0 To? If List1.List(i) =? Then List1.RemoveItem?
212 3 End If Next i 1 Text1.Text 2For ListCount i 0List1.ListCount 1 34 IfFor Text1.Text i Private Sub Add_Click() Text1.Text = InputBox(" ") List1.AddItem Text1.Text Private Sub Delete_Click() Text1.Text = InputBox(" ") For i = 0 To List1.ListCount 1 If List1.List(i) = Text1.Text Then List1.RemoveItem i End If Next i 2 sjt4.vbpsjt4.frm FindMax4 Option Base 1 Private Function FindMax(a() As Integer) Dim Start As Integer
20 213 Dim Finish As Integer, i As Integer Start =?(a) Finish =?(a) Max =?(Start) For i = Start To Finish If a(i)? Max Then Max =? Next i FindMax = Max End Function Private Sub Command1_Click() Dim arr1 Dim arr2(4) As Integer arr1 =Array( Val(Text1.Text),Val(Text2.Text),Val(Text3.Text),Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(?) Next i M = FindMax(?) Print": ";M 12For Lbound Ubound 3Max a(start) Max 45IfForMax a(i)>max a(i)max 64 Cint arr1(i) 7FindMax() arr2() Option Base 1 Private Function FindMax(a() As Integer) Dim Start As Integer Dim Finish As Integer, i As Integer Start = Lbound(a) Finish = Ubound(a) Max = a(start) For i = Start To Finis h If a(i) Max Then Max = a(i) Next i FindMax = Max End Function Private Sub Command1_Click() Dim arr1 Dim arr2(4) As Integer arr1 = Array(Val(
214 3 Text1.Text),Val(Text2.Text),Val(Text3.Text),Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(arr1(i)) Next i M=FindMax(arr2()) Print ": ";M Form2 Form2 Form1 Form2 Form2 Form1Form1Form1 Form2 3 sjt3.vbp Form1 Form2Form1 Form2 C1 C2 Form1 Private Sub C1_Click() End Private Sub C2_Click() Load?? = True Form1 Form2 Form1 C2 ClickLoad Form1Visible True Form2
20 215 Private Sub C1_Click() End Private Sub C2_Click() Load Form1 Form1.Visible=True 4 sjt4.vbp P1 3 Private Sub C1_Click() Dim k As Integer For k = 0 To 2 If Op1(k).? Then Call draw(?) End If Next k Sub draw(a As Integer) P1.Print" "& Op1(?).Caption 0 Op1Op1(1) Op1(2)3 Op1(i).Caption ValueTrue
216 3 C1_ClickFor drawcaption Private Sub C1_Click() Dim k As Integer For k = 0 To 2 If Op1(k).Value Then Call draw(k) End If Next k Sub draw(a As Integer) P1.Print " " & Op1(a).Caption 5 sjt3.vbp 3 Private Sub C1_Click() For i =? To? If Op1(i).? = True Then Print"" + Op1(i).? End If Next i 4 Private Sub C1_Click() For i = 0 To 2
20 217 If Op1(i). Value = True Then Print""+Op1(i). Caption End If Next i 6 sjt4.vbp Form13 B1 B2 L1L1 500 3000 B1 B2 Cb1 Cb2 Cb1 10 15 20Cb2 Cb1Cb2L1 Private Sub Form_Unload(Cancel As Integer) Open"out4.txt" For Output As #1 Print #1, Cb1.Text, Cb2.Text, CInt(L1.Font.Size), L1.Font Close #1 L1 Click Cb1 Val L1 FontSize Cb2Windows Private Sub Cb1_Click() L1.FontSize = Val(Cb1.Text) Private Sub Cb2_Click() L1.FontName = Cb2.Text Private Sub Form_Unload(Cancel As Integer)
218 3 Open"out4.txt"For Output As #1 Print #1,Cb1.Text,Cb2.Text,CInt(L1.Font.Size),L1.Font Close #1 7 sjt3.vbp Option1 Option2 List1 Text1Click 3 sjt3.vbpsjt3.frm Private Sub Form_Click() If Option1.Value = True Then Text1.Text = InputBox(" ") List1.AddItem? End If If Option2.Value = True Then Text1.Text = InputBox(" ") For i = 0 To? If List1.List(i) =? Then List1.RemoveItem? End If Next i End If 1Value True Option1 Text1.Text 2Option2 ListCount
20 219 List0 For 0 ListCount 1 List1.ListCount 1 3RemoveItem i Private Sub Form_Click() If Option1.Value = True Then Text1.Text = InputBox(" ") List1.AddItem Text1.Text End If If Option2.Value = True Then Text1.Text = InputBox(" ") For i = 0 To List1.ListCount 1 If List1.List(i)=Text1.Text Then List1.RemoveItem i End If Next i End If 8 sjt4.vbpsjt4.frm Sort 4 Option Base 1 Private Sub Sort(a() As Integer) Dim Start As Integer, Finish As Integer Dim i As Integer, j As Integer, t As Integer Start =?(a) Finish =?(a) For i =? To 2 Step 1 For j = 1 To? If a(j)? a(j + 1) Then t = a(j + 1) a(j + 1) = a(j) a(j) = t End If
220 3 Next j Next i Private Sub Command1_Click() Dim arr1 Dim arr2(4) As Integer arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(arr1(i)) Next i Sort arr2() Text1.Text = arr2(1) Text2.Text = arr2(2) Text3.Text = arr2(3) Text4.Text = arr2(4) 12Sort a Lbound UboundLbound Ubound 345 For n n 1 1 ifinish 2 1 j1 i 1 Option Base 1 Private Sub Sort(a() As Integer) Dim Start As Integer, Finish As Integer Dim i As Integer, j As Integer, t As Integer Start = Lbound(a) Finish = Ubound(a) For i = Finish To 2 Step 1 For j = 1 To i-1 If a(j) a(j + 1) Then t=a(j + 1) a(j + 1) = a(j) a(j) = t End If Next j Next i Private Sub Command1_Click()
20 221 Dim arr1 Dim arr2(4) As Integer arr1 = Array(Val( Text1.Text),Val(Text2.Text),Val(Text3.Text),Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(arr1(i)) Next i Sort arr2() Text1.Text = arr2(1) Text2.Text = arr2(2) Text3.Text = arr2(3) Text4.Text = arr2(4) 9 Form1P1 P2 1 900 1 700pic1.bmpP1 pic2.jpgp2 C1 P1 pic2.jpgp2 pic1.bmp 3 sjt3.vbp sjt3.frm 2003/9 3 Picture Picture Private Sub Command1_Click() Form1.Picture = P1.Picture P1.Picture = P2.Picture P2.Picture = Form1.Picture Form1.Picture = LoadPicture("")
222 3 10 sjt4.vbp Ch1 Ch2 Text1 C1 sjt4.vbp sjt4.frm 2003/9 Value 0 1 CaptionText1 Text Load Text Dim a As String Private Sub C1_Click() If Ch1.Value = 0 And Ch2.Value = 0 Then Text1.Text = a End If If Ch1.Value = 1 And Ch2.Value = 0 Then Text1.Text = a & Ch1.Caption End If If Ch1.Value = 0 And Ch2.Value = 1 Then Text1.Text = a & Ch2.Caption End If If Ch1.Value = 1 And Ch2.Value = 1 Then
20 223 Text1.Text = a & Ch1.Caption & Ch2.Caption End If Private Sub Form_Load() a = Text1.Text 11 sjt3.vbp Text1 L1 C1 2003/9 Private Sub C1_Click() ' L1.? Text1.Text Private Sub L1_Click() ' L1.RemoveItem? AddItem RemoveItem Text1.Text AddItem ListIndex RemoveItem Private Sub C1_Click() L1. AddItem Text1.Text Private Sub L1_Click() L1.RemoveItem L1.ListIndex 12 sjt4.vbp Text1C1 3 Op1 Op2 Op3
224 3 2003/9 1 10 15 Value True False Private Sub C1_Click() If Op1.Value = True Then Text1.Text = "1" If Op2.Value = True Then Text1.Text = "10" If Op3.Value = True Then Text1.Text = "15" 13 sjt3.vbp F1 F2 F1 Op1 Op2 F2 Op3 Op4C1 Text1 1 2 3 4 sjt3.vbp sjt3.frm2003/9
20 225 2003/9 Value True False Private Sub Command1_Click() If Op1.Value = True And Op3.Value = True Then Text1.Text = "" End If If Op1.Value = True And Op4.Value = True Then Text1.Text = "" End If If Op2.Value = True And Op3.Value = True Then Text1.Text = "" End If If Op2.Value = True And Op4.Value = True Then Text1.Text = "" End If 14 sjt4.vbp 3 Text1 Text2 Text3 Op1 Op2 Text1 Text2 Text1 Text2Text1Text2 Text3 sjt4.vbp sjt4.frm
226 3 2003/9 Text3 Private Sub Op1_Click() Dim a As String a = Text1.Text Text1.Text = Text2.Text Text2.Text = a Op1.Visible = False Private Sub Op2_Click() Text3.Text = Text1.Text & Text2.Text 15 sjt3.vbp sjt3.frm 4Visual Basic Turbo C C++ Java Option1 XXX Option2 XXX XXX 2003/9 List
20 227 ListIndex Value True Private Sub C1_Click() If Option1.Value = True Then Text1.Text = List1.List(List1.ListIndex) & "" Else If Option2.Value = True Then Text1.Text = List1.List(List1.ListIndex) & "" End If End If 16 sjt4.vbp sjt4.frm Command1 5001250 2003/9 Private Sub Command1_Click() Dim i As Integer, j As Integer, isum As Integer Print "1250" For i = 1 To 500 '? = 0 For j = i To 500 ' isum =? If isum >= 1250 Then Exit For Next j ' If isum =? Then Print i; " "; j End If Next i For
228 3 1iSum isum 2 isum + i 3 1250 1250 Private Sub Command1_Click() Dim i As Integer, j As Integer, isum As Integer Print "1250" For i = 1 To 500 isum = 0 For j = i To 500 isum = isum + j If isum >= 1250 Then Exit For Next j If isum = 1250 Then Print i; " "; j End If Next i 17 Form1 Timer1 Image1 pic.ico HScroll1 Min100 Max1200 LargeChange100 SmallChange25 sjt3.vbp sjt3.frm 2003/9 HScroll1 Change Timer1 IntervalHScroll1 Value Image1 Visible Visible Timer1 Timer Private Sub HScroll1_Change() Timer1.Interval = HScroll1.Value Private Sub Timer1_Timer()
20 229 Image1.Visible = Not Image1.Visible 18 sjt4.vbp List1 3 _GB2312Text1 HScroll1 10 50 2003/9 Private Sub HScroll1_Change() ' Text1.FontSize =? If List1.Text <> "" Then ' Text1.FontName =? Else MsgBox " ",, "" End If Value FontSize TextFontName
230 3 Private Sub HScroll1_Change() Text1.FontSize = HScroll1.Value If List1.Text <> "" Then Text1.FontName = List1.Text Else MsgBox " ",, "" End If 19 sjt3.vbp 2003/9 Private Sub Form_Unload(Cancel As Integer) unload_sub Sub unload_sub() Open "out3.dat" For Output As #1 Print #1,Form1.Op1.Value,Form1.Op2.Value,Form1.Ch1.Value, Form1.Ch2.Value, Form1. Text1.FontName, Form1.Text1.FontUnderline,Form1.Text1.FontItalic Close #1 Op1(0).Value = True FontName FontUnderline
20 231 FontItalic Private Sub Command1_Click() If Op1(0).Value = True Then Text1.FontName = "" Else Text1.FontName = "" End If If Check1.Value = 1 Then Text1.FontUnderline = True Else Text1.FontUnderline = False End If If Check2.Value = 1 Then Text1.FontItalic = True Else Text1.FontItalic = False End If 20 sjt4.vbp 0.1 0.1 2003/9 Private Sub Timer1_Timer() ' P1.? P1.Left + 20 Timer1 Interval 100 0.1Timer Timer1 TimerLeft
232 3 = Click Timer1 Enabled Timer1 Interval 100 Private Sub Timer1_Timer() P1. Left = P1.Left + 20 Private Sub C1_Click() Timer1.Enabled = True Private Sub C2_Click() Timer1.Enabled = False 21 Form1Label1 Text1Combo1 3 Command1 Command2Text1 Text1 Click sjt3.vbp sjt3.frm2003/9 Command1 Click()Text1 Combo1 Command2 Click()Combo1 ListCount Private Sub Command1_Click() Combo1.AddItem Text1.Text Private Sub Command2_Click()
20 233 Print Combo1.ListCount 22 sjt4.vbp n nz a ZA 2003/9 Private Sub Command1_Click() Dim n As Integer, k As Integer, m As Integer Dim c As String, a As String For k = 0 To 2 If Op1(k).Value Then ' n = Val(Op1(k).? ) End If Next k m = Len(Text1.Text) a = "" ' For k = 1 To? ' c = Mid$(Text1.Text,?, 1) c = String(1, Asc(C + n) If c > "z" Or c > "Z" And c < "a" Then c = String(1, Asc(C 26) End If '? = a + c Next k Text2.Text = a Asc Ascii Len Mid
234 3 String Val 1 CaptionCaption 2For m 3 k 4 aa Private Sub Command1_Click() Dim n As Integer, k As Integer, m As Integer Dim c As String, a As String For k = 0 To 2 If Op1(k).Value Then n = Val(Op1(k). Caption ) End If Next k m = Len(Text1.Text) a = "" For k = 1 To m c = Mid$(Text1.Text, k, 1) c = String(1, Asc(C + n) If c > "z" Or c > "Z" And c < "a" Then c = String(1, Asc(C 26) End If a = a + c Next k Text2.Text = a 23 sjt3.vbp L1 Op13 Index 0 1 2 Text1 Op1 Click Text1 Text1
20 235 2003/9 Private Sub Op1_Click(Index As Integer) Dim a As String, b As String, c As String a = "" b = "" ' Select Case? Case 0 Text1.Text = a + Me.Op1(0).Caption + " " Case 1 ' Text1.Text =? + Me.Op1(1).Caption + " " Case 2 Text1.Text = b + Me.Op1(2).Caption + " " End Select SelectIndex 1Index2 a Private Sub Op1_Click(Index As Integer) Dim a As String, b As String, c As String a = "" b = "" Select Case Index Case 0 Text1.Text = a + Me.Op1(0).Caption + " " Case 1 Text1.Text = a + Me.Op1(1).Caption + " " Case 2 Text1.Text = b + Me.Op1(2).Caption + " " End Select 24 sjt4.vbp Form1 Text1 F1 F2
236 3 F1Op1 Op2 F2 Op3 Op4C1 F1 F2 Text1 2003/9 Private Sub Form_Unload(Cancel As Integer) Open "out4.txt" For Output As #1 Print #1, Op1.Value, Op2.Value, Op3.Value, Op4.Value, Text1.Text Close #1 Value True False Private Sub Command1_Click() If Op1.Value = True And Op3.Value = True Then Text1.Text = " " End If If Op1.Value = True And Op4.Value = True Then Text1.Text = " " End If If Op2.Value = True And Op3.Value = True Then Text1.Text = " "
20 237 End If If Op2.Value = True And Op4.Value = True Then Text1.Text = " " End If 25 sjt3.vbpsjt3.frm List1 Text1 MouseDown 3 2004/4 Private Sub Form_MouseDown(Button As Integer, _ Shift As Integer, X As Single, Y As Single) If Button = 1 Then Text1.Text = InputBox(" ") ' List1.AddItem? End If If Button = 2 Then Text1.Text = InputBox(" ") ' For i = 0 To? ' If List1.List(i) =? Then ' List1.RemoveItem? End If Next i End If 1 Text1.Text 2
238 3 ForList1.ListCount 1 3List Text1.Text 4i Private Sub Form_MouseDown(Button As Integer, _ Shift As Integer, X As Single, Y As Single) If Button = 1 Then Text1.Text = InputBox(" ") List1.AddItem Text1.Text End If If Button = 2 Then Text1.Text = InputBox(" ") For i = 0 To List1. ListCount 1 If List1.List(i) = Text1.Text Then List1.RemoveItem i End If Next i End If 26 sjt4.vbpsjt4.frm FindMin4 2004/4 Option Base 1 Private Function FindMin(a() As Integer) Dim Start As Integer Dim Finish As Integer, i As Integer ' Start =?(a) ' Finish =?(a) ' Min =?(Start) For i = Start To Finish
20 239 ' If a(i)? Min Then Min =? Next i FindMin = Min End Function Private Sub Command1_Click() Dim arr1 Dim arr2(4) As Integer arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(arr1(i)) Next i ' M = FindMin(?) Print ": "; M LBound Ubound CInt 12For Lbound Ubound 3Min a 45Mina(i) < Min a(i) Min< a(i) 6 FindMin arr2 arr2 Option Base 1 Private Function FindMin(a() As Integer) Dim Start As Integer Dim Finish As Integer, i As Integer Start = LBound(A Finish = UBound(A Min = a (Start) For i = Start To Finish If a(i) < Min Then Min = a(i) Next i FindMin = Min End Function Private Sub Command1_Click() Dim arr1
240 3 Dim arr2(4) As Integer arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(arr1(i)) Next i M = FindMin( arr2 ) Print ": "; M 27 sjt3.vbp Item Add Delete List1 Text1 sjt3.vbpsjt3.frm 2004/4 Private Sub Add_Click() Text1.Text = InputBox(" ") ' List1.AddItem? Private Sub Delete_Click() Text1.Text = InputBox(" ") ' For i = 0 To? ' If List1.List(i) =? Then ' List1.RemoveItem? End If Next i 7
20 241 Private Sub Add_Click() Text1.Text = InputBox(" ") List1.AddItem Text1.Text Private Sub Delete_Click() Text1.Text = InputBox(" ") For i = 0 To List1.ListCount 1 If List1.List(i) = Text1.Text Then List1.RemoveItem i End If Next i 28 sjt4.vbpsjt3.frm Sort4 sjt4.vbp sjt4.frm2004/4 Option Base 1 Private Sub Sort(a() As Integer) Dim Start As Integer, Finish As Integer Dim i As Integer, j As Integer, t As Integer ' Start =?(a) ' Finish =?(a) ' For i =? To 2 Step 1 ' For j = 1 To? ' If a(j)? a(j + 1) Then t = a(j + 1) a(j + 1) = a(j) a(j) = t End If Next j
242 3 Next i Private Sub Command1_Click() Dim arr1 Dim arr2(4) As Integer arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text)) For i = 1 To 4 arr2(i) = CInt(arr1(i)) Next i Sort arr2() Text1.Text = arr2(1) Text2.Text = arr2(2) Text3.Text = arr2(3) Text4.Text = arr2(4) 8 8
21 1 sjt5.vbptext1 0 Op1 13 C1 C2 13 Text1 1Text1 Private Sub Op1_Click(Index As Integer) Select Case? Case 0 Timer1.Interval = 1000 Case 1 Timer1.Interval = 3000 End Select Private Sub Timer1Timer() Text1.Text =?.Text + 1 1 Index ClickIndexSelect IndexIndex 2 Timer 1
244 3 C1 C2 Click C1Timer1 Enabled True C2Timer1 Enabled False Timer1 EnabledFalse Private Sub Op1_Click(Index As Integer) Select Case Index Case 0 Timer1.Interval = 1000 Case 1 Timer1.Interval = 3000 End Select Private Sub Timer1_Timer() Text1.Text=Text1.Text+1 C1 C2 Click Private Sub C1_Click() Timer1.Enabled = True Private Sub C2_Click() Timer1.Enabled = False 2 sjt5.vbp P1 P2 P1.ico.ico.icoTimer1 Timer2 Timer1 123Timer2 Dim a%, b As Boolean Private Sub C1_Click()
21 245 Timer2.Enabled=? b=true Private Sub Timer1_Timer() a=a+1 If a 6 Then a=1 End If Select Case a Case 1 P1.Picture = LoadPicture(".ico") Case 2, 3 P1.Picture = LoadPicture(".ico") Case 4, 5, 6 P1.Picture = LoadPicture("?") If b Then Timer2.Enabled = True End Select Private Sub Timer2_Timer() If (a <4) And (P2.Left > P1.Left And P2.Left < P1.Left + P1.Width) Or P2.Left <= 100 Then Timer2.Enabled=? Else P2.Move? 10, P2.Top, P2.Width, P2.Height End If Timer2 Enabled FalseTimer2 Timer C1 C1 Click Timer2.Enabled=True Timer13Timer1 Interval 1000 1a Timera1 6a=1 1 a=2 3 2 a=4 5 6 3Select Case a a=4 5 6P1.Left + P1.Width P1.Left P1.Left+P1.Width P1.Left b Dim a%, b As Boolean Private Sub C1_Click()
246 3 Timer2.Enabled = True b=true Private Sub Timer1_Timer() a=a+1 If a>6 Then a=1 End If Select Case a Case 1 P1.Picture = LoadPicture(".ico") Case 2,3 P1.Picture = LoadPicture(".ico") Case 4,5,6 P1.Picture = LoadPicture(".ico") If b Then Timer2.Enabled = True End Select Private Sub Timer2_Timer() If (a<4) And (P2.Left>P1.Left And P2.Left<P1.Left + P1.Width) Or P2. Left<= 100 Then Timer2.Enabled = False Else P2.Move P2.Left 10, P2.Top, P2.Width, P2.Height End If 3 sjt5.vbp Text1 C1 C2 isprime a True False 15 0001 Text1 Text1 out5.txt isprime out5.txt isprime Private Function isprime(a As Integer) As Boolean Dim flag As Boolean flag = True
21 247 b% = 2 Do While b% <= Int(a/2) And flag If Int(a/b%) = a/b% Then flag = False Else b% = b%+1 End If Loop isprime = flag End Function i=15 001 ii 1 Do While Loop Exit Do OutputPrint# Text1.Text Private Sub C1_Click() Dim i As Integer i = 15001 Do While (1) If!isprime(i) Then i=i+1 Else Text1.Text = i Exit If End If Loop Private Sub C2_click() Open "c:\exam\2004\out5.txt" For Output As #1 Print #1,Text1.text Close #1 4 3 Read Calc Save Text1 MultiLine True ScrollBars 2 datain1.txt1001 50 dataout.txt
248 3 sjt5.vbp ReadData Datain1.txt100 Arr WriteDate dataout.txt sjt5.vbp sjt5.frm Option Base 1 Dim Arr(100) As Integer Sub ReadData() Open App.Path &"\"&"datain1.txt"for Input As #1 For i = 1 To 100 Input #1,Arr(i) Next i Close #1 Sub WriteData(Filename As String, Num As Integer) Open App.Path &"\"& Filename For Output As #1 Print #1,Num Close #1 APP APP APP.Path 3Click 3 Option Base 1 Dim Arr(100) As Integer Dim a(100) Dim s As Integer Private Sub Read_Click() ReadData Private Sub Calc_Click() For i = 1 To 100 If Arr(i) >= 50 Then Text1.Text = Text1.Text + Str(Arr(i)) + " " s = s + Arr(i) End If Next i Print s Private Sub Save_Click() WriteData "Dataout.txt", s 5 sjt5.vbp Text1 Text2 3 C1 C2 C3
21 249 isprime a True False in5.txttext1 Text1 Text2 Text2out5.txt isprime Private Function isprime(a As Integer) As Boolean Dim flag As Boolean flag = True b% = 2 Do While b% <= Int(a / 2) And flag If Int(a / b%) = a / b% Then flag = False Else b% = b% + 1 End If Loop isprime = flag End Function isprime out5.txt 2003/9 Click Click isprime Dim a As Integer Private Sub C1_Click() Open "in5.txt" For Input As #1 Input #1,a Text1.Text = a Close #1 Private Sub C2_Click() Dim flag As Boolean, i As Integer a = a + 1 Do While Not isprime(a) a = a + 1 Loop Text2.Text = a
250 3 Private Sub C3_Click() Open "out5.txt" For Output As #1 Print #1,Text2.Text Close #1 6 sjt5.vbpform1 1 1 2003/9 Private Sub C1_Click(Index As Integer) ' Select Case? Case 1 Timer1.Enabled = False ' Case? Timer1.Enabled = True End Select Private Sub Timer1_Timer() ' Text1.Text = Text1.Text? Visual Basic sjt5.vbp Index0Index1 Index Enabled True False + 3Text1.Text = Text1.Text + 1 1 Interval1000 1 Timer Private Sub C1_Click(Index As Integer) Select Case Index Case 1 Timer1.Enabled = False
21 251 Case 0 Timer1.Enabled = True End Select Private Sub Timer1_Timer() Text1.Text = Text1.Text + 1 7 sjt5.vbp ReadData1 ReadData2 datain1.txt datain2.txt 20 Arr1 Arr2 WriteData dataout.txtsjt5.vbp Form1 3 C1 C2 C3 ReadData1 ReadData2datain1.txt datain2.txt20 Arr1 Arr2 3 n 2 n 3 n n 1 2 3 203 WriteDate dataout.txt dataout.txtsjt5.vbp sjt5.frm2003/9 Option Base 1 Dim Arr1(20) As Integer Dim Arr2(20) As Integer Sub ReadData1() Open App.Path & "\" & "datain1.txt" For Input As #1 For i = 1 To 20 Input #1, Arr1(i) Next i Close #1 Sub ReadData2() Open App.Path & "\" & "datain2.txt" For Input As #1 For i = 1 To 20 Input #1, Arr2(i)
252 3 Next i Close #1 Sub WriteData(Filename As String, Num As Integer) Open App.Path & "\" & Filename For Output As #1 Print #1, Num Close #1 C1 ReadData1 ReadData2 Click C2Arr3 20 Arr3Sum C3 Click C3 Click WriteData dataout.txt Sum Option Base 1 Dim Arr1(20) As Integer Dim Arr2(20) As Integer Dim Sum As Integer Private Sub C1_Click() Call ReadData1 Call ReadData2 Private Sub C2_Click() Dim Arr3(20) As Integer Sum = 0 For i = 1 To 20 Arr3(i) = Arr1(i) + Arr2(i) Sum = Sum + Arr3(i) Next i Print Sum Private Sub C3_Click() Call WriteData("dataout.txt", Sum) 8Text1 Command1 Command2 in5.txt 5 out.txt
21 253 in5.txt3 Name 8 Sex 4 Age Integer Private type StudInfo Name As String *8 Sex As String *4 Age As Integer End Type out5.txt sjt5.vbp sjt5.frm2003/9 StudInfoPrivate StudInfo Student in5.txt Open "in5.txt" For Random As #1 Len = Len(Student) Len = Len(Student) Text1.Text = Student.Name & Student.Sex & Student.Age & Chr(13) & Chr(10) & Text1.Text Chr(13) Chr(10)Chr(13) Chr(10) in5.txt out5.txt Command2 Click Randomin5.txt Get # Outputout5.txt Print # Write #Print # Write #
254 3 MultiLine True Private Type StudInfo Name As String * 8 Sex As String * 4 Age As Integer End Type Dim Student As StudInfo Private Sub Command1_Click() Open "in5.txt" For Random As #1 Len = Len(Student) For i = 1 To 5 Get #1, i, Student Text1.Text = Student.Name & Student.Sex & Student.Age & Chr(13) & Chr(10) & Text1.Text Next i Close #1 Private Sub Command2_Click() Open "in5.txt" For Random As #1 Len = Len(Student) Open "out5.txt" For Output As #2 Len = Len(Student) For i = 1 To 5 Get #1, i, Student Print #2, Student.Name; Student.Sex; Student.Age Next i Close #1 Close #2 9 Form1 3Label1 Label2 Label3 3 Text1 Text2 Text3 Command1 Command2 in5.txt 3 3out5.txt out5.txt3 Name 8 Tel 10 Post Long
21 255 Private Type PalInfo Name As String *8 Tel As String *10 Post As Long End Type Dim Pal As PalInfo in5.txt 333 out5.txt2 Private Sub Command2_Click() Open "out5.txt" For Output As #1 Print #1,Text1.Text, Text2.Text, Text3.Text Close 1 sjt5.vbp sjt5.frm 2003/9 Private Type PalInfo Name As String * 8 Tel As String * 10 Post As Long End Type Dim Pal As PalInfo in5.txtlen = Len(Pal) Len(Pal) Pal Open "in5.txt" For Random As #1 Len = Len(Pal) 3 Get #1, 3, Pal out5.txt Open "out5.txt" For Output As #1
256 3 Input# Line Input# Print# Write# Get# Put# Type PalInfo Name As String * 8 Tel As String * 10 Post As Long End Type Dim Pal As PalInfo Private Sub Command1_Click() Open "d:\01.dat" For Random As #1 Len = Len(Pal) Get #1, 3, Pal Text1.Text = Pal.Name Text2.Text = Pal.Tel Text3.Text = Pal.Post Close #1 Private Sub Command2_Click() Open "d:\out5.txt" For Output As #1 Print #1, Text1.Text, Text2.Text, Text3.Text Close #1 10 sjt5.vbp in5.txt15 atext1 Text1 Text1 Text2 Text2 Text1Text2 2003/9
21 257 Dim a(15) As String Private Sub C1_Click() Dim k As Integer Open "in5.txt" For Input As #1 Form1.Cls For k = 1 To 15 Input #1, a(k) Print a(k) Next k ' Close? Private Sub C2_Click() Dim k As Integer, n As Integer, c As String ' n = Len(? ) c = "" If n > 0 Then For k = 1 To 15 ' If Left(a(k),? ) = Text1.Text Then ' c = c + " " +? End If Next k If c = "" Then Text2.Text = "" Else ' Text2.Text =? End If Else Text2.Text = "" End If Len Left 1 #1 2 Text1.Text 3c a(k) 4 Text2 c Dim a(15) As String Private Sub C1_Click() Dim k As Integer
258 3 Open "in5.txt" For Input As #1 Form1.Cls For k = 1 To 15 Input #1, a(k) Print a(k) Next k Close #1 Private Sub C2_Click() Dim k As Integer, n As Integer, c As String n = Len( Text1.Text ) c = "" If n > 0 Then For k = 1 To 15 If Left(a(k), n) = Text1.Text Then c = c + " " + a(k) End If Next k If c = "" Then Text2.Text = "" Else Text2.Text = c End If Else Text2.Text = "" End If 11 sjt5.vbp Text1 Text2 3 C1 C2 C3 in5.dat 50 Text150 Text2 50 out5.dat Click 2003/9
21 259 Dim a(50) As Integer Private Sub C1_Click() Dim k As Integer, ch As String Open "in5.dat" For Input As #1 ch = "" For k = 1 To 50 ' Input #1,? ch = ch + Str(a(k)) + " " Next k Close #1 ' Text1.Text =? Private Sub C2_Click() Private Sub C3_Click() Open "out5.dat" For Output As #1 Print #1, Text2.Text Close #1 1For 50 a ch a(k) 2a ch Text1ch Text1 Text Click a n n 1 Dim a(50) As Integer Private Sub C1_Click() Dim k As Integer, ch As String Open "in5.dat" For Input As #1 ch = "" For k = 1 To 50 Input #1, a(k) ch = ch + Str(a(k)) + " " Next k Close #1 Text1.Text = ch Private Sub C2_Click() Dim i As Integer, j As Integer, num As Integer
260 3 Dim ch As String For i = 1 To 49 For j = 49 To i Step 1 If a(j + 1) < a(j) Then num = a(j + 1) a(j + 1) = a(j) a(j) = num End If Next j Text2.Text = Text2.Text + Str(a(i)) + " " Next i Private Sub C3_Click() Open "out5.dat" For Output As #1 Print #1, Text2.Text Close #1 12sjt5.vbp L1 L2C1 Text1 Text2 Text1 * Text23 C1 Text1 123456Text1 Text2 1 3 3 2003/9 Private Sub C1_Click() ' If? = "123456" Then Text1.Text = "" ' Text1.? = "" Else Text2.Text = Text2.Text 1 ' If Text2.Text >? Then MsgBox " " & (3 Text2.Text) & " " Else
21 261 MsgBox "3 " ' Text1.Enabled =? End If End If 1Text1 Text1.Text 2PasswordChar"" Text1 3Text23 0 4 3Text1 * Text1 PasswordChar* Text Private Sub C1_Click() If Text1.Text = "123456" Then Text1.Text = "" Text1. PasswordChar = "" Else Text2.Text = Text2.Text 1 If Text2.Text > 0 Then MsgBox " " & (3 Text2.Text) & " " Else MsgBox "3 " Text1.Enabled = False End If End If 13 3 Read Calc Save Text1 MultiLine True ScrollBars 2 datain1.txt100 1 dataout.txt
262 3 sjt5.vbp ReadData datain1.txt100 Arr WriteData dataout.txt 2004/4 Option Base 1 Dim Arr(100) As Integer Sub ReadData() Open App.Path & "\" & "datain1.txt" For Input As #1 For i = 1 To 100 Input #1, Arr(i) Next i Close #1 Sub WriteData(Filename As String, Num As Integer) Open App.Path & "\" & Filename For Output As #1 Print #1, Num Close #1 4 3Click Calc ClickText1.Text = Text1.Text + "Arr(" + Str(i) + ") = " + Str(Arr(i)) + Chr(13) + Chr(10) 3 Option Base 1 Dim Arr(100) As Integer Dim a(100) Dim s As Integer Private Sub Read_Click() ReadData Private Sub Calc_Click() For i = 2 To 100 If i Mod 2 = 0 Then Text1.Text = Text1.Text + "Arr(" + Str(i) + ") = " + Str(Arr(i)) + Chr(13) + Chr(10) s = s + Arr(i) End If Next i Print s Private Sub Save_Click() WriteData "Dataout.txt", s
>>>> 4 + 2004 42004 9
2004 4 Visual Basic 90 100 1 20 2 21 30 3 70 ABCD 1 A Visual Basic B Visual Basic C Visual Basic Width Height D Visual Basic 2 A B.BAS C D 3 A DblCLick B CMouseMove D 4Visual Basic A.frm B.bat C.vbg D.vbp 5 A B Visual Basic C Visual Basic
2004 4 265 D 6TelBook A Type TelBook Name As String*10 TelNum As Integer End Type C Type TelBook Name String*10 TelNum Integer End Type TelBook B Type TelBook Name As String*10 TelNum As Integer End TelBook D Typedef TelBook Name String*10 TelNum Integer End Type 7 A Const var 1=123 C DefInt a-z B Dim var2= ABC D Static var3 As Integer 8 List1 A List1.List B List1.ListIndex C List1.Index D List1.Text 9 A MouseDown B MouseUp C Load D Click 10a=10, b=5, c=1, Print a>b>c A True B False C 1 D 11 A Caption B Name C BackColor D BorderStyle 12 A BOF B LOC C LOF D EOF 13 ASub Main B CHide D 14MouseDown Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 4
266 4 + A Button B ShiftShift C ShiftAlt Ctrl D X Y 15 Combo13 A Combo1.RemoveItem Text B Combo1.RemoveItem 2 C Combo1.RemoveItem 3 D Combo1.RemoveItem Combo1.Listcount 16 A TabStop False B LostFocus CEnabled False Tab DTabIndexTab 17Caption A = B * C & D - 18 Open "Tel.dat" For Random As #1 Len=50 Tel.dat A C B D 19 Command1 Text1 Text2 : Private Sub Command1_Click() n=text1.text Select Case n Case 1 To 20 x=10 Case 2, 4, 6 x=20 Case Is <10 x=30 Case 10 x=40 End Select Text2.Text=x Text1 10Text2
2004 4 267 A 10 B 20 C 30 D 40 20 Do Loop While<> A0 B C Exit Do DTrue 21 Command1: Private Sub Command1_Click() Dim num As Integer num = 1 Do Until num > 6 Print num; num=num + 2.4 Loop A 1 3.4 5.8 B 1 3 5 C 1 4 7 D 22 Command1: Private Sub Command1_Click() Dim a As Integer, s As Integer a = 8 s = 1 Do s = s + a a = a 1 Loop While a <= 0 Print s; a A 7 9 B 34 0 C 9 7 D 23 : Public Function f(x As Integer) Dim y As Integer
268 4 + x=20 y=2 f=x*y End Function Command1: Private Sub Command1_Click() Static x As Integer x=10 y=5 y=f(x) Print x;y A 10 5 B 20 5 C 20 40 D 10 40 24 : Public Sub Fun (a(),byval x As Integer) For i =1 To 5 x=x+a(i) Next Text1Command1 Private Sub Command1_Click() Dim arr(5) As Variant For i=1 To 5 arr(i)=i Next n=10 Call Fun(arr(),n) Text1.Text=n A 10 B 15 C 25 D 24 25 Command1: Option Base 1 Private Sub Command1_Click() d=0 c=10
2004 4 269 x=array(10, 12, 21, 32, 24) For i= 1 To 5 If x(i) > c Then d=d+x(i) c=x(i) Else d=d c End If Next i Print d A 89 B 99 C 23 D 77 26 HScroll1 HScroll2 6 Label1 Label2 Label3 Label4 Label5 Label6 Label4~Label6A B A*BLabel1 Label2 Label3A*B Label1 Label2 Label3 A Private Sub Command1_Click() Label3.Caption=Str(Val(Label1.Caption)*Val(Label2.Caption)) B Private Sub Command1_Click() Label3.Caption= Hscro1ll.Value* HScroll2.Value C Private Sub Commandl_Click() Label3.Caption=HScroll1*HScroll2 D Private Sub Command1_Click() Label3.Caption=HScroll1.Text * HScroll2.Text 27 Command1 Private Sub Command1_Click() For n = 1 To 20
270 4 + If n Mod 3 <> 0 Then m = m + n \ 3 Next n Print n A 15 B 18 C 21 D 24 28 Text1 Private Sub Form_Load() Show Text1.Text = "" Text1.SetFocus Private Sub Form_MouseUP(Button As Integer,Shift As Integer,X As Single, Y As Single) Print "" Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Print "Visual Basic"; A A Visual Basic C A B D Visual Basic 29 Private Sub Command1_Click() Dim sum As Double, x As Double sum = 0 n = 0 For i = 1 To 5 x = n / i n = n + 1 sum = sum + x Next For A 1+1/2+ 2/3+3/4+4/5 B 1+1/2+2/3+3/4 C 1/2+2/3+3/4+4/5 D 1+1/2+1/3+ 1/4+1/5 30 A Static arr1(3)
2004 4 271 arr1(1) = 100 arr1(2) = "Hello" arr1(3) = 123.45 B Dim arr2() As Integer Dim size As Integer Private Sub Command2_Click() size = InputBox(" ") ReDim arr2(size) C Option Base 1 Private Sub Command3_Click() Dim arr3(3) As Integer D Dim n As Integer Private Sub Command4_Click() Dim arr4(n) As Integer 2 30 1 15 1 i 1 s 2 s=2 For i=3.2 To 4.9 Step 0.8 s=s+1 Next i 2 KeyPreview True Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Print Chr(KeyCode) Private Sub Form_KeyPress (KeyAscii As Integer) Print Chr(KeyAscii) AShift 3 4 3Label1 Timer1 Private Sub Form_Load() Timer1.Enabled= False
272 4 + Timer1.Interval= 5 Private Sub Form_Click() Timer1.Enabled= 6 Private Sub Timer1_Timer() Label1.Caption= 7 1 4Text1 Label1 Command1 : Private Sub Command1_Click() S$=InputBox("") Text1.Text=S$ Private Sub Text1_Change() Label1.Coption=Ucase(Mid(Text1.Text,7)) VisualBasic 8 5List1 Command1 Label1 Private Sub Commandl_Click() If List1 ListIndex >= 9 Then List1.RemoveItem 10 Label1.Caption= 11 Else MsgBox " " End If
2004 4 273 6 Option Base 1 Private Sub Command1_Chick() Dim arr1, Max as Integer arr1=array(12,435,76,24,78,54,866,43) 12 =arr1(1) For i=1 To 8 If arr1(i)> Max Then 13 Next i Print ":";Max Array8 7smtextl.txt Text1 Private Sub Command1_Click() Dim indata As String Text1.Text="" Open ".\smtext1.txt" 14 As #1 Do While 15 Input #1,inData Text1.Text=Text1.Text&inData Loop Close #1
274 4 + 1 C A B DC Timer Width Height 2 A 4 A 3 B A CDName B 4 B 4.frm.vbg.vbp Visual Basic.bat Visual Basic 5 C C Visual Basic Visual Basic.exeVisual Basic Windows 6 A 7 B Const Dim DefIntDefType Static B 8 D 4 List
2004 4 275 ListIndex Index Text D 9 C 10 B a > b > c a > b True True > c True Visual Basic0 TrueFalse 11 A 12 D BOF Visual Basic 3 LOC LOF EOFTrue False D 13 A A Main Sub Main Main 14 A 15 B RemoveItem 03 2 B 16 A GetFocus LostFocus Enabled Visible True TabTabIndex Tab TabIndex TabTab TabStop FalseTab Tab Tab
276 4 + A 17 D 18 C 19 A Select Casen Case Case Text2 10 20 A 21 B num B 22 C 23 C xf 20y f 40C 24 A n 10 25 C x(i) > c 26 D TextDC Value 27 C Mod\ 28 D Form_LoadText1AText1 KeyDown Visual Basic D 29 C 30 D D 2 30 1 5.6 2 5 For 3i=5.6 4.9 s5 3 A 4 a
2004 4 277 KeyPreview True KeyPressKyeAscii Ascii AKeyAscii=97 a Shift+A KeyAscii=65 A KeyDownKeyCode AKeyCode=65 AShift+A KeyDownKeyCode 16 Shift 65 A AA a 5 1000 6 True 7 Time Time$ 5LoadTimer1 1Timer1 Interval 1000 6Timer1 Enabled True 7 TimerTime Label1 Caption 8 BASIC Ucase(Mid(Text1.Text,7)) Text1.Text7 VisualBasic BASIC 9 0 10 List1.ListIndex 11 List1.ListCount 9 List1 ListIndex 0 10 RemoveItem List1.ListIndex 11ListCount Label1 Caption 12 Max 13 Max = arr1(i) 14 For Input 15 Not EOF(1) 14 Open InputFor Input 15 Do While Loop Do WhileNot EOF(1)
2004 4 Visual Basic 1 12 15 30 C:\WEXAM\26190210 Visual Basic 1Form1P1 1800 1700 pic1.bmp sjt1.vbp sjt1.frm 2 Form1Text1 Text2 C1 Text1 Text1 Text2 sjt2.vbp sjt2.frm 22 20 40 C:\WEXAM\26190210
2004 4 279 1 sjt3.vbp Private Sub C1_Click() ' For i =? To? ' If Op1(i).? = True Then ' Print "" + Op1(i).? End If Next 2 sjt4.vbp Private Sub c1_click() Dim flag As Boolean ' For i =? To Cb1.ListCount 1 ' If Cb1.List(i) = Cb1.? Then flag = True
280 4 + Else flag = False End If Next If flag Then MsgBox "" Cb1.Text = "" Else ' Cb1.? Cb1.Text End If 31 30 C:\WEXZM\26190210 in5.txtform1 Text1 C1 in5.txt out5.txt sjt5.vbpsjt5.frm 2 12 15 30 C:\WEXAM\26190101 Visual Basic 1 Form1 Text1
2004 4 281 sjt1.vbp sjt1.frm 2 Form1Cmd1 Cmd2 Cmd1 Cmd2 2 sjt2.vbp sjt2.frm 22 20 40 C:\WEXAM\26190101 1 sjt3.vbp sjt3.frm 30 0 1 000 Command1
282 4 + Option Base 1 Private Sub Command1_Click() Dim arrn(30) As Integer Dim Max As Integer Randomize For i = 1 To 30 ' arrn(i) = Int(Rnd *?) Next i '? = arrn(1) For i = 2 To 30 ' If? Then Max = arrn(i) End If Next i Print Max 2 sjt4.vbp sjt4.frm 0 1 000 5 7 5 7Fun Function Fun() End Function Sub SaveData() Open App.Path & "\" & "outtxt.txt" For Output As #1 Print #1, Text1.Text Close #1 Function Fun() End Function Private Sub Command1_Click() d = Fun() Text1.Text = d SaveData 31 30 C:\WEXZM\26190101 sjt5.vbp sjt5.frm datain.txt 32 43 76 58 28 12 98 57 31 42 53 64 75 86 97 13 24 35 46 57 68 79 80 59 37 datain.txt Mat 5 5
2004 4 283 Option Base 1 Private Sub Form_Click() Const N = 5 Const M = 5 ' Dim? Dim i, j ' Open App.Path & "\" & "datain.txt"? As #1 For i = 1 To N For j = 1 To M '? Next j Next i Close #1 Print Print "" Print For i = 1 To N For j = 1 To M Print Tab(5 * j); Mat(i, j); Next j Print Next i Print Print " " For i = 1 To N For j = 1 To M ' If? Then Print Tab(5 * j); Mat(i, j); Next j Next i
284 4 + 1 1 1 2 ScrollBars 3MultiLineTrue ScrollBars 3MultiLine True ClickText1 Text Text2 Text Private Sub Command1_Click() Text2.Text = Text1.Text 2 1 Private Sub C1_Click() For i = 0 To 2 If Op1(i). Value = True Then Print "" + Op1(i). Caption End If Next 2 10 0 2 Text Text 3 AddItem
2004 4 285 Private Sub c1_click() Dim flag As Boolean For i = 0 To Cb1.ListCount 1 If Cb1.List(i) = Cb1. Text Then flag = True Exit For Else flag = False End If Next If flag Then MsgBox "" Cb1.Text = "" Else Cb1. AddItem Cb1.Text End If 3 APP APP Visual Basic APP.Path.vbpAPP.Path EOF EOFTrue FalseDo While Not EOF(1) Line Input #strx Chr(13) + Chr(10) Text1 MultiLine True Private Sub Form_Load() Dim strx As String, stry As String Open App.Path & "\" & "in5.txt" For Input As #1 Do While Not EOF(1) Line Input #1, strx stry = stry + strx + Chr(13) + Chr(10) Loop Text1.Text = stry Close #1 Private Sub Command1_Click() Open App.Path & "\" & "out5.txt" For Output As #1 Write #1, Text1.Text
286 4 + 2 Close #1 1 1 MultiLine True Scrollbars 2 Text Font Caption 2 Left Top Cmd1Cmd1 ClickLeft Top 0 Cmd22 Click Cmd2.Height = 2 * Cmd2.Height Cmd2.Width = 2 * Cmd2.Width Private Sub Cmd1_Click() Cmd1.Left = 0 Cmd1.Top = 0 Private Sub Cmd2_Click() Cmd2.Height = 2 * Cmd2.Height
2004 4 287 Cmd2.Width = 2 * Cmd2.Width 2 1 1Rnd0 10 1 000 Rnd1 0001 000 Randomize 2Max MaxMax 3 If Max arrn(i) > Max Max < arrn(i) Option Base 1 Private Sub Command1_Click() Dim arrn(30) As Integer Dim Max As Integer Randomize For i = 1 To 30 arrn(i) = Int(Rnd * 1000 ) Next i Max = arrn(1) For i = 2 To 30 If arrn(i) > Max Then Max = arrn(i) End If Next i Print Max 2 Fun Function Fun() Dim a As Integer, i As Integer a = 0 For i = 5 To 1000 If (i Mod 5 = 0) Or (i Mod 7 = 0) Then a = a + 1 End If Next i Fun = a End Function
288 4 + 3 1 Max(N,M) Max(M,N) 2 Input 3Input #1, Mat(i, j)i j i = j i = j Option Base 1 Private Sub Form_Click() Const N = 5 Const M = 5 Dim Mat(N, M) As Integer Dim i, j Open App.Path & "\" & "datain.txt" For Input As #1 For i = 1 To N For j = 1 To M Input #1, Mat(i, j) Next j Next i Close #1 Print Print "" Print For i = 1 To N For j = 1 To M Print Tab(5 * j); Mat(i, j); Next j Print Next i Print Print " " For i = 1 To N For j = 1 To M If i = j Then Print Tab(5 * j); Mat(i, j); Next j Next i
2004 9 Visual Basic 90 100 ABCD 1 Text1 A Text1.Maxlength=0 C Text1.Visible=False B Text1.Enabled=False D Text1.Width=0 2 Form1Visual Basic A Form1.Name="Visual Basic" B Form1.Title="Visual Basic" C Form1.Caption="Visual Basic" D Form1.Text="Visual Basic" 3 Text1 HScroll1 Min Max 0 100 A Private Sub HScroll_Change() Text1.Text=HScroll1.value B Private Sub HScroll_Click() Text1.Text=HScroll1.value
290 4 + C Private Sub HScroll_Change() Text1.Text=HScroll.Caption D Private Sub HScroll_Click() Text1.Text=HScroll.Caption 4 Open Alt O Open Open ACaption &Open BCaption O&pen CName &Open DName O&pen 5 Command1 Private Sub Command1_Click() x=inputbox("input") Select Case x Case 1,3 Print " 1" Case Is >4 Print " 2" Case Else Print "Else " End Select 2 A 1 B 2 C Else D 6 MsgBox A MsgBox B MsgBox C MsgBox D MsgBox 7 Timer1 0.5 A Timer1.InterVal=0.5 C Timer.Interval=50 B Timer1.Interval=5 D Timer1.Interval=500
2004 9 291 8 Command1 Private Sub Command1_Click() Static x As Integer Cls For i=1 To 2 y=y+x x=x+2 Next Print x,y 3 Command1 A 4 2 B 12 18 C 12 30 D 4 6 9 AHide B C D 10 A B C D LOF 11 A B C D 12Visual Basic A ForLoop B Const C 9abc D a#x 13value A 3 B 2 C 1 D 0 14 5 Mod 3+3\5*2 A 0 B 2 C 4 D 6 15x=4 y=8 z=7x<y And (Not y>z) Or z<x
292 4 + A 1 B -1 C True D False 16 Command1 Private Sub Command1_Click() a$="visualbasic" Print String(3,a$) A VVV B Vis C sic D 11 17 x=2 For i=1 To 10 Step 2 x=x+i Next x A 26 B 27 C 38 D 57 18 AKeyPress BKeyPress CKeyDown KeyUp A a DKeyDown KeyUp 1 1 19 a=9.8596 Print Format(a,"$00,00.00") A 0,009.86 B $9.86 C 9.86 D $0,009.86 20 CommandDialog1Command1 Private Sub Command1_Click() CommonDialog1.FileName ="" CommonDialog1.Filter="All file *.* (*.Doc) *.Doc (*.Txt) *.Txt" CommonDialog1.FilterIndex=2 CommonDialog1.DialogTitle="VBTest" CommonDialog1.Action=1
2004 9 293 A B C VBTest D*.Txt 21Form1 Form2Form1 Command1Form1 Private Sub Command1_Click() Dim a As Integer a=10 Call g(form2,a) Private Sub g(f As Form,x As Integer) y=iif(x>10,100,-100) f.show f.caption=y A Form1 Caption100 C Form1 Caption 100 B Form2 Caption 100 D Form2 Caption100 22 Command1 Private Sub Command1_Click() Dim x As Integer Static y As Integer x=10 y=5 Call f1(x,y) Print x,y Private Sub f1(byref x1 As Integer, y1 As Integer) x1=x1+2 y1=y1+2 A 10 5 B 12 5 C 10 7 D 12 7 23 Option Base 1 Private Sub Command1_Click() Dim a(10) As Integer Dim n As Integer
294 4 + n=inputbox("") If n<10 Then Call GetArray(a,n) End If Private Sub GetArray(b() As Integer,n As Integer) Dim c(10) As Integer j=0 For i=1 To n b(i)=cint(rnd()*100) If b(i)/2=b(i)\2 Then j=j+1 c(j)=b(i) End If Next Print j A bc B c C GetArray n D10 24 Command1 Option Base 1 Private Sub Command1_Click() Dim a a= Array(1,2,3,4,5) For i=1 To UBound(a) a(i) = a(i)+i-1 Next Print a(3) A 4 B 5 C 6 D 7 25 Option Base 1 Private Sub Form_Click() Dim arr,sum Sum = 0 arr = Array(1,3,5,7,9,11,13,15,17,19) For i=1 To 10
2004 9 295 If arr(i)/3 = arr(i)\3 Then Sum =Sum+arr(i) End If Next I Print Sum A 13 B 14 C 27 D 15 26 File1 Private Sub File1_DblClick() x=shell(file1.filename,1) A xcall Shell(File1,FileName,1) B CFile1.FileName D File1 27 Label1 VisualBasic Command1 Command2 Timer1Interval 500 Private Sub Form_Load() Timer1.Enabled=False Private Sub Command1_Click() Timer1.Enabled=True Private Sub Timer1_Timer() If Label1.Left<Width Then Label1.Left = Label1.Left + 20 Else Label1.Left=0 End If
296 4 + A B C D 28 a$="abbacddcba" For i=6 To 2 Step 2 X=Mid(a,i,i) Y=Left(a,i) z=right(a,i) z=ucase(x&y&z) Next I Print z A ABA B BBABBA C ABBABA D AABAAB 29 Command1 Option Base 1 Private Sub Command1_Click() Dim a As Variant a=array(1,2,3,4,5) Sum=0 For i=1 To 5 Sum = sum+a(i) Next I x=sum/5 For i =1 To 5 If a(i)>x Then Print a(i); Next I A 1 2 B 1 2 3 C 3 4 5 D 4 5 30Form1 Model1 Model2 Model1 Public x As Integer Public y As Integer
2004 9 297 Sub S1() x =1 S2 Sub S2() y=10 Form1.Show End Show Model2 Sub Main() S1 Sub Main A Form1 Model1 Model2 B Model1 Model2 Form1 C Model2 Model1 Form1 D Model2 Form1 Model1 2 30 1 15 1 a$="beijingshanghai" b$=mid(a$,instr(a$,"g")+1) b$ 1 2 2 num =0 While num<=2 num = num+1 Wend Print num 3List1Text1 Label1 Caption Sum Command1 1 100 7 List1
298 4 + Private Sub Form_Load() For i=1 To 100 If i Mod 7 =0 Then 3 End If Next Private Sub Command1_Click() Sum =0 For i=0 To 4 Sum =Sum+ 5 Next Text1.Text=Sum 4 0 1 1 03Text1 Text2 Text3 Text1 Private Sub Command1_Click() Randomize n=cint(text1.text) n1=0 n2=0 For i=1 To 6 r=int(rnd*2) If r= 7 Then n1=n1+1 Else n2=n2+1 End If Next Text2.Text=n1 Text3.Text=n2
2004 9 299 5 Option Base 1 Private Sub Form_Click() Dim a(3) As Integer Print " "; For i=1 To 3 a(i)=inputbox("") Print a(i); Next Print If a(1)<a(2) Then t=a(1) a(1)=a(2) a(2)= 8 End If If a(2)>a(3) Then m=a(2) ElseIf a(1)>a(3) Then m= 9 Else m= 10 End If Print " ";m 3 3 6 Command17 5Label1 Label2 Caption Label3 5 Label2
300 4 + Private Sub Command1_Click() Sum = 0 For i=0 To 4 Sum=Sum+ 11 Next 12 =Sum 7 Command1 Command2 a a Option Base 1 Dim a(3,2) As Integer Private Sub Command1_Click() For i=1 To 3 For j=1 To 2 13 =i+j Next j Next I Private Sub Command2_Click() For j=1 To 3 For i=1 To 2 s=s+ 14 Next I Next j Text1.Text= 15
2004 9 301 1 20 2 21 30 3 70 1 B Enabled True False 2 C 3 A 4 A 5 C Visual Basic Case x x=1 3 1 x>4 2 x Else2 Else C 6 D MsgBox1 7 7A MsgBox type B MsgBox MsgBox C MsgBox D 7 D 8 B x y x y 3 Command1 x y x = 4 y = 2 x = 8 y = 10 x = 12 y = 18 9 A 10 B
302 4 + B 11 D Visual Basic D 12 A 13 C Value0 20 12 14 B 5 Mod 3 + 3 \ 5 * 2 = (5 Mod 3) + (3 \ 5) * 2 = 2 + 0 * 2 = 2 B 15 D ((x < y) And (Not(y > z))) or (z < x) True False False False False 16 A String(3,a$)a3 String(3,a$) = VVV 17 B 18 B KeyPressKeyAsciiAscii A a Ascii 0 9Ascii KeyPress Ascii Ascii KeyDown KeyUp KeyCode A a 0 9KeyDown KeyUp B 19 D Print $
2004 9 303 00., D 20 D FileName Filter FilterIndex Filter *.Doc DialogTitle Action 1 D 21 B Visual Basic Form Control x = 10y = 100g Form2 Caption 100 22 D ByVal x1 y1 f1x yd 23 C GetArrayn CInt() b(i) / 2 = b(i) \ 2 b(i)b(i) 24 B a = Array(1,2,3,4,5)a Dim a Dim a()a Ubound()1 5
304 4 + B 25 C 24 26 A FileName Shell(File.FileName,1) 1 File.FileName 1 x = Shell(File.FileName,1) x ID ID Shell(File.FileName,1) DblClick Shell 27 A Label1.Left < Width Width TimerLeft20 Left 0 28 B z X Y Z i=2x = Mid(a,i,i) = bb Y = Left(a,i) = ab z = Right(a,i) = ba z = UCase(X&Y&z) = BBABBA 29 D 30 C Main Model2 Model2Model1 S1S1S2 S2Form1 Model2 Model1 Form1 2 30 1 "Shanghai" Mid 2 InStr(a$,"g")+1 g S Mid3 b$shanghai 2 3 While num1 While num = 3
2004 9 305 3 List1.AddItem i 4 List1.ListCount-1 5 List1.List(i) 17AddItem List1.AddItem i 2 ListCount 0 ListCount 1 3 List1.List(i) 6 n 7 1 n = Cint(Text1.Text) r = Int(Rnd * n) 0 10 1 20 1 8 t 9 a(3) 10 a(1) 3 a(1) < a(2)tt a(2) a(2) > a(3) a(2)m a(2) a(1) > a(3)a(3) a(3)m a(1) a(1)m 11 label1(i).caption 12 label2.caption 13 a(i,j) 14 a(j,i) 15 s Command1_Click Command2_Click i j
2004 9 Visual Basic 1 12 15 30 C:\WEXAM\26200101 Visual Basic 1 Forml HScrolll 1~100Labell Label2 1100 sjt1.vbp sjt1.frm 2 Forml Shapel 1000 1000Commandl Command2 Click &HFF& &HC000& sjt2.vbp sjt2.frm
2004 9 307 22 20 40 C:\WEXAM\26200101 1sjt3.vbp Commandl Command2 3 Optionl Option2 Option3 1in3.dats 2 3s 4 Click Dim s As String Private Sub Command1_Click() Open "in3.dat" For Input As #1 s = Input$(LOF(1), #1) Close #1 Private Sub Command2_Click() ' Private Sub Form_Unload(Cancel As Integer) Open "out3.dat" For Output As #1 Print #1, Option1.Value, Option2.Value, Option3.Value, Text1.Text Close #1
308 4 + 2 sjt4.vbp Picturel Picture2 Dim m As Integer Private Sub Command1_Click() Picture1.Visible = False Picture2.Visible = True ' Timer1.Enabled =? Private Sub Command2_Click() Picture2.Visible = False Picture1.Visible = True Timer1.Enabled = False Private Sub Command3_Click(Index As Integer) ' m =? Private Sub Timer1_Timer() ' Select Case? Case 0: Picture3.Move Picture3.Left + 10 Case 1: Picture3.Move Picture3.Left - 10 Case 2: Picture3.Move Picture3.Left, Picture3.Top - 10 Case 3: Picture3.Move Picture3.Left, Picture3.Top + 10 End Select
2004 9 309 31 30 C:\WEXAM\26200101 a b a b sjt5.vbp 3 Text1 Text2 Text3 3 Commandl Command2 Command3in5.dat xtextl a b a x batext2 btext3 Text2 Text1 Text3 isprime(x)x True FalseClick out5.dat Private Sub Command1_Click() Dim x As Integer Open "in5.dat" For Input As #1 Input #1, x Close #1 Text1 = x Private Sub Command2_Click() ' Private Sub Command3_Click() Open "out5.dat" For Output As #1 Print #1, Text2, Text3 Close #1 Function isprime(x As Integer) Dim k As Integer, flag As Boolean k = 2 flag = True While k <= Int(x / 2) And flag
310 4 + If Int(x / k) = x / k Then flag = False Else k = k + 1 End If Wend isprime = flag End Function 2 12 15 30 C:\WEXAM\26200102 Visual Basic 1Forml Op Dis Clea sjt1.vbp sjt1.frm 2FormlLabl L1 sjt2.vbp sjt2.frm ` 22 20 40 C:\WEXAM\26200102 1 sjt3.vbp,,f1
2004 9 311 F2,F1Op1 Op2 F2Op3 Op4 Textl sjt3.vbp,sjt3.frm Private Sub Form_Unload(Cancel As Integer) Open "out3.txt" For Output As #1 Print #1, Op1.Value, Op2.Value, Op3.Value, Op4.Value, Text1.Text Close #1 2 sjt4.vbp Text1 Text2 Lab13752000 Op1 Op2 Text1 Text2 Text1 Text2 Text1 Text2 sjt4.vbp sjt4.frm
312 4 + Private Sub Form_Unload(Cancel As Integer) Open "out4.txt" For Output As #1 Print #1, Op1.Value, Op2.Value, Text1.Text, Text2.Text, Lab1.Caption Close #1 31 30 C:\WEXAM\26200102 sjt5.vbp Form1 3C1 C2 C3 ReadData1 ReadData2datain1.txt datain2.txt 20 Arr1 Arr2 n nn n 1 2 20 WriteDatadataout.txt dataout.txt Option Base 1 Dim Arr1(20) As Integer Dim Arr2(20) As Integer Sub ReadData1() Open App.Path & "\" & "datain1.txt" For Input As #1 For i = 1 To 20 Input #1, Arr1(i)
2004 9 313 Next i Close #1 Sub ReadData2() Open App.Path & "\" & "datain2.txt" For Input As #1 For i = 1 To 20 Input #1, Arr2(i) Next i Close #1 Sub WriteData(Filename As String, Num As Integer) Open App.Path & "\" & Filename For Output As #1 Print #1, Num Close #1
314 4 + 1 1. 1 1 100Min Max 1 100 Caption 1 100 2 Shape 3-Circle Heigth Width 1000 1000 Caption Command1_Click() Command2_Click()BorderColor Private Sub Command1_Click() Shape1.BorderColor = &HFF& Private Sub Command2_Click() Shape1.BorderColor = &HC000& 2. 13 Command2_Click() Value True Mid$(s, i, 1) s i 1 If Then ElseIf For Next Private Sub Command2_Click() Dim count As Integer count = 0 If Option1.Value = True Then For i = 1 To Len(s) If Mid$(s, i, 1) >= "A" And Mid$(s, i, 1) <= "Z" Then count = count + 1 End If Next i
2004 9 315 ElseIf Option2.Value = True Then For i = 1 To Len(s) If Mid$(s, i, 1) >= "a" And Mid$(s, i, 1) <= "z" Then count = count + 1 End If Next i Else For i = 1 To Len(s) If Mid$(s, i, 1) = " " Then count = count + 1 End If Next i End If Text1.Text = count 2 4 Index Move Object.Move left,top,width,height left Dim m As Integer Private Sub Command1_Click() Picture1.Visible = False Picture2.Visible = True Timer1.Enabled = True Private Sub Command2_Click() Picture2.Visible = False Picture1.Visible = True Timer1.Enabled = False Private Sub Command3_Click(Index As Integer) m = Index Private Sub Timer1_Timer() Select Case m Case 0: Picture3.Move Picture3.Left + 10 Case 1: Picture3.Move Picture3.Left - 10 Case 2: Picture3.Move Picture3.Left, Picture3.Top - 10 Case 3: Picture3.Move Picture3.Left, Picture3.Top + 10 End Select
316 4 + 3. Click Whilei i 11 i Command1_Click() x Dim Command2_Click()Text1.Text Val Command2_Click() 2 Private Sub Command2_Click() Dim x As Integer Dim i As Integer x = Val(Text1.Text) i = x While Not isprime(i) i = i - 1 Wend Text2.Text = i i = x + 1 While Not isprime(i) i = i + 1 Wend Text3.Text = i 1. 1Print [.]Print [][, ;] Cls [.]Cls Private Sub dis_click() Print "" Private Sub clea_click() Cls
2004 9 317 2 ListCount Caption DblClick()Lab1.Caption = L1.ListCount Private Sub L1_DblClick() Lab1.Caption = L1.ListCount 2. 1 If4 If Then ElseIf If Then Click() Private Sub Text1_Click() If Op1.Value = True And Op3.Value = True Then Text1.Text = " " + Op1.Caption + " " + Op3.Caption ElseIf Op1.Value = True And Op4.Value = True Then Text1.Text = " " + Op1.Caption + " " + Op4.Caption ElseIf Op2.Value = True And Op3.Value = True Then Text1.Text = " " + Op2.Caption + " " + Op3.Caption ElseIf Op2.Value = True And Op4.Value = True Then Text1.Text = " " + Op2.Caption + " " + Op4.Caption End If 2If Height Width375 2000 Click() Private Sub Form_Click() Dim str As String If Op1.Value = True Then str = Text1.Text Text1.Text = Text2.Text Text2.Text = str Lab1.Caption = "" ElseIf Op2.Value = True Then Lab1.Caption = Text1.Text + Text2.Text End If 3. Visual BasicCall
318 4 + Sum 3 Dim Sum As Integer Private Sub C1_Click() Call ReadData1 Call ReadData2 Private Sub C2_Click() Dim Arr3(20) As Integer Sum = 0 For i = 1 To 20 Arr3(i) = Arr1(i) \ Arr2(i) Sum = Sum + Arr3(i) Next i Print Sum Private Sub C3_Click() WriteData "dataout.txt", Sum