+ All Categories
Home > Documents > VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2....

VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2....

Date post: 10-Sep-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
130
VB VB 2007/12/24 03:15 PM - VB 828 PDA
Transcript
Page 1: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

VB

VB

2007/12/24 03:15 PM

- VB

828 PDA

Page 2: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

最28

ID

3 40 2

Page 3: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

274

5-1

programming language

5-1.1

5-1

5-2

FORTRAN COBOL Pascal

Visual Basic.NET C++ Java

VBA JavaScript ActionScript

5-1

1 G L 2 G L 3 G L4 G L 5 G L

Page 4: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2755

How are you ? 01011100

5-2

low-level language

machine-dependent

machine language

0 1 5-3

5-3 0 1

Page 5: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

276

assembly language

0 1 "ADD" "SUB" "MUL" "DIV"

mnemonic code

assembler

5-4

126E:0000 LDA 1000

126E:0001 SUB 1001

126E:0010 ADD 1010

126E:0011 PSC 0000

126E:0100 STA 1111

126E:0101 HTL 0000

126E:0110 ES 0000

126E:0111 ES 0000

126E:1000 DW 0100

126E:1001 DW 0010

126E:1010 DW 0110

5-4 1 2 3

Page 6: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2775

high-level language

statement

5-5

1

2

3

N

5-5

compiler interpreter

5-1

5-1

http://content.edu.tw/senior/computer/ks_ks/tag.1.2.4.html

Page 7: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

278

procedural language

5-

2

5-2

FORTRAN 1.2.3.

COBOL 1.2.

BASIC 1.2. GWBASIC

QBASIC Visual BasicPascal 1. Blaise Pascal

2.C 1.

2.3. UNIX C

object-oriented language

class object

5-

6

Page 8: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2795

5-6

5 -7

1.2.3.4.

1.2.3.

1.6 1.5 1.2 m

2.

5-7

Page 9: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

280

C++ Java Visual Basic.NET

5-3

C++ 1. C2.3.

Java 1.2.

Visual Basic .NET 1. Visual Basic

2.

encapsulat ion inheri tance

polymorphism

3

101

101

Page 10: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2815

redefine

3

VBA Office

JavaScript

ActionScript Macromedia

( )1. (A) (B) (C)C (D)

( )2. (A)COBOL (B)Vi-sual Basic.NET (C)FORTRAN (D)BASIC

( )3. (A)DVD (B) VB (C) 110V (D)

KTV

Page 11: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

282

5-1.2

source code

5-8

5-8

linker

e d i t o r

Page 12: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2835

( )1. (A) (B)C++ (C)FORTRAN (D)

Visual Basic

( )2. (A) (B) (C)

(D)

( )3. compilerloader linker editor

(A) (B) (C)(D)

5-9

loader

5-10

5-10

executable object

code 5-9

Page 13: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

284

( )1.(A) (B) (C) (D)

( )2. (A) (B) (C) (D)

( )3. C++ C (A) (B) (C) (D)

( )4.(A)FORTRAN (B)COBOL (C)BASIC (D)C

( )5. (A)FORTRAN(B)COBOL (C)BASIC (D)C

( )6. (A) (B)

(C) (D)

( )7. (A) (B) (C) (D)

5-2 Visual BasicVisual Basic VB BASIC

1991

Visual Basic

icon

Page 14: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2855

5-2.1 Visual Basic

5-11

5-11 Visual Basic / /Microsoft Visual Basic 6.0/Microsoft Visual

Basic 6.0 Visual Basic

Visual Basic

5-

1 2

http://infoserv.com.tw/vb/ Visual Basic VBhttp://dgr.twbts.com/vb/ Visual Basic

Page 15: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

286

5-12 Visual Basic Visual Basic Office

Visual Basic

20

5-13

/

5-13

Page 16: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2875

5-14

5-14 Word /

5-15

1

5-15

Page 17: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

288

5-16 Caption

5-17

Caption" "

Caption Caption

5-16 Caption "Command1" " "

5-17

Page 18: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2895

Visual Basic 3 5-18 3

5-18

"Ch05-2a.vbp"

Page 19: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

290

( )1. Visual Basic (A) (B) (C) (D)

( )2. Visual Basic(A) (B) (C) (D)

( )3. Visual Basic (A) (B) (C) (D)

5-2.2 Visual Basic

3

5-19

*.vbp 1

*.frm

vbp Visua lBasic Project

frm form

5-19

Page 20: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2915

Command1 Click

Private Sub Command1_Click()

' Const pi = 3.14159

Dim r As Single

Dim area As Single

r = Val(Text1.Text)

area = pi * r ^ 2

Text2.Text = area

End Sub

5-19

statements 5-20

Visual Basic

c o n s t a n t v a r i a b l e

reserved word opera tor

comment 5-

20

5-20

Visual Basic

DimCommand1

'

Page 21: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

292

5-20 pi

5-20 r

Dim

VB

*

" R e m "

5-20 2

5-2.3 Visual Basic

5-21 Visual Basic

.exe

T

F

5-21 VB

Page 22: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2935

Visual Basic1

Visual Basic

5-22 Visual Basic

5-22 VB

Page 23: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

294

5-23

B o d yMass Index, BMI

Kg /m2

2.1

1.1

2.2Caption

1.2

1

2

5-23

Page 24: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2955

5-24

Command1 Cl ick

Command2 Cl ick

1

2

5-24

Page 25: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

296

/

*.frm *.vbp

5-25

3

2

1

Visual Basic

*.exe Visual Basic

/ xxx.exe"xxx"

*.exe

5-25 *.frm *.vbp

Page 26: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2975

1 Visual Basic1Visual Basic

1 /

2

1 C o m m a n d B u -tton

Page 27: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

298

2 Command1

Caption" "

2 3

3

C l s

Print

Time( )

Visual Basic

1

Page 28: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

2995

4

5

6

7 "Sp05-2a"

8 "Sp05-2a"

Page 29: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

300

( )1. Visual Basic a. b.c. d. (A)a b d c (B)a

c b d (C)a c d b (D)a d c b

( )2. Visual Basic (A) (B) (C) (D)

( )3. Visual Basic Visual Basic (A) Visual Basic *.zip (B) Visual Ba-

sic *.exe (C) Visual Basic *.vbp (D) Vi-sual Basic *.frm

( )1. Visual Basic (A).cls, .ctl(B).dll, .sys (C).exe, .com (D).vbp, .frm

( )2. Visual Basic (A) (B) (C) (D)

( )3. Visual Basic (A)1 (B)2 (C)3 (D)4

( )4. Visual Basic (A) (B) (C) (D)

( )5. Visual Basic (A) (B) (C) (D)

( )6. Visual Basic (A) (B) (C) (D)

7. "Sp05-2a.vbp" 100= 1 "Sp05-a.vbp" "Sp05-a.frm"

Page 30: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3015

5-3

5-3.1

Visual Basic

5-26

5-26

Page 31: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

302

Print " Visual Basic"Visual Basic

Print ""

Visual Basic value string

Boolean date

Visual Basic 4

5-4 4

5-4

Integer 2bytes -32768 ~ 32767Long 4bytes -2147483648 ~ 2147483647Single 4bytes 1.4E - 45 ~ 3.4E + 38

-3.4E + 38 ~ -1.4E - 45Double 8bytes 4.94E - 324 ~ 1.79E + 308

-1.79E + 308 ~ -4.94E - 324

"E" 10 3.4E38 = 3.4 1038

" 5-27

" "

5-27

Page 32: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3035

A=1B=2

print A<BTrue

print A>BFalse

Visual Basic/

5-28

5-28

True

False 5-29

"True "

A B

"False "

A B

5-29

Print 1+12

Print 2-11

Page 33: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

304

Print " ";#2006/11/5#2006/11/5

Print " ";#16:07:33# 04:07:33

Print

2006 11 5

4 07 33

# 5-30

5-30

constant variable

Visual Basic

5-31

255

Visual Basic

Dim Print Exit For IfVB

Page 34: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3055

. ! @ # $ %

&

5-31

5-5 Visual Basic

5-5 Visual Basic

/HI_BOYyear962AB!CPrint Print Visual Basichr.

VB Variant

Const As =

例 Const pi As Single = 3.14 ' pi

Page 35: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

306

Dim As

Dim +

例 1 Dim r As Single ' r

Dim id As String ' id

例 2 Dim r! ' r

Dim id$ ' id

5-6

5-6

String $Integer % 2Long & 4Single ! 4Double # 8Date 8Boolean 2Variant

Visual Basic

2

0

Page 36: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3075

operator

operand

expression

5-32

Visual Basic

5-7 Visual Basic 8

A + B

5-32

5-7

^ 2 ^ 3 8 1- -6 -6 2* 2 * 3 6 3/ 8 / 6 1.333... 3\ 8 \ 6 1 4

Mod 8 Mod 6 2 5

+ 1 + 2 3 6- 2 - 1 1 6

Page 37: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

308

2 - 1 + 6 * 8 ................ (2 ^ 3 = 8)2 - 1 + 48 ................... (6 * 8 = 48)1 + 48 ............................ (2 - 1 = 1)49

8.5 \ 4 = 8 \ 4 = 2 5

8 0 .5

Print 2-1+6*2^349

Print 2^101024

Print 8.5\42

Print 43.6 Mod 3*38

5-33

"\"

VB

5-33

1.

(1) Print 3 + 9 ^ 0.5 ________________________________________

(2) Print 64 \ 8 - 10 ________________________________________

(3) Print 7 * 4 / 2 ^ 2 _______________________________________

2. Visual Basic

(1)gLp2T = ____________________________________________

(2)a2

ac4bb 2 −+− ________________________________________

(3) 22 ZYX += __________________________________________

Page 38: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3095

Print " " + " " + " "

Print " " & 450450

Print " " + 250

"+" "&"

5-34

5-34 "+" "&"

5-35 "+"

"+"

1.

(1) Print " " & 7 __________________________________

(2) Print "123" + "456" _______________________________________

(3) Print 123 + 456 __________________________________________

Page 39: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

310

Print "Visual" > "Basic"True

Print "Basic" < "Book"True

True T

False F 5-8 Visual Basic 6

5-8

= 1 = 2 F> 1 > 2 F< 1 < 2 T>= 1 >= 2 F<= 1 <= 2 T< > > < 1 <> 2 T

1 ASCII

ASCII 5-36

5-36 ASCII

1 2"a" ASCII 97 "o" ASCII

111 T r u e

"V" ASCII 86 "B" ASCII6 6 T r u e

1.

(1) a = -1 : b = 2Print a > b _______________________________________

(2) Print "Sara" > "Samy" _____________________________

Page 40: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3115

a=1 : b=2 : c=3Print Not a>b-cFalse

Print (c-a)*b>3 And b*c<10True

Print a+b>c Or b+c>aTrue

Visual Basic Not

And Or 3 5-9 3 A B

T

5-9

Not Not A F 1And A And B T 2

TrueOr A Or C T 3

Ture

5-37

N o t

A n d

O r

5-37

1.

(1) Print 2 > 19 Or 7 < 9 ___________________________________

(2) Print 5 > 1 And Not 5 < 3 _______________________________

Page 41: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

312

C = 85

E = 80

M = 75

C = 85

E = 80

M = 75

Avg = (C + E + M) / 3

Class_Avg = 70

Print " " & Avg80

Print Avg > Class_AvgTrue

C = 85

E = 80

M = 75

Avg = (C + E + M) / 3

Class_Avg = 70

2

1C = 85 C

2 E = 80 E

3 M = 75 M

4

5 Class_Avg =70 Class_Avg

6 Print "" & Avg

7 Print Avg >C l a s s _ A v g

T r u eFalse

Page 42: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3135

( )1. 4 Visual Basic (A)AB! (B)B%(C)AB# (D)AB

( )2. 4 Visual Basic (A)Ans& (B)Ans% (C)Ans! (D)Ans$

( )3. Visual Basic (A) -(B) / (C) * (D) Mod

( )4. Visual Basic "Print 2 ^ 3 + 45 / 9 - 0.5 * 8" (A)2 (B)3 (C)5 (D)6

( )5. A = 13 / 2 B = 13 \ 2 A B (A)A (B)B (C) (D)

( )6. Visual Basic "Print (2 ^ 4 - 5) > 10 And 3 * 16 ^ (1 / 2) <= 10" (A)False (B)True (C)1 (D)2

7. " "" "

(1) *ANb.conSTC.A - B

(2) Dim

(3) HI_Girl

8. Visual Basic

(1) Print 10 < 4 * 2 __________________________________________________

(2) Print Not (7 > 15 Mod 2 ) _________________________________________

(3) Print 64 ^ 0.5 = 2 ^ 3 Or 18 \ 6 <> 3 ________________________________

9. VB Print "A B " +80 + " "

______________________________________________________

Page 43: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

314

5-3.2 Visual Basic build-in function

user-defined function Visual Basic

5-6.2

3 3

5-10

5-10

Len( ) Len("Hello") 5Left( , N) N Left("Hello", 2) eRight( , N) N Right("Hello", 2) lMid( , M, N) M N Mid("Hello", 3, 2) llLtrim( ) Ltrim(" Hello") HelloRtrim( ) Rtrim("Hello ") HelloTrim( ) Trim(" Hello ") HelloLCase( ) LCase("Hello") helloUCase( ) UCase("Hello") HELLOString(N, ) N 2 String(3, "A") AAA

N 1 2N ASCII

Space(N) N Space(2) + "Hi" HiStr( ) Str(10) 10

Page 44: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3155

idol$ = "SHE, Selina Hebe Ella"

Print LCase(idol$)she, selina hebe ella

Print String(3, "*") + idol$***SHE, Selina Hebe Ella

Print Space(2) + String(5, "#") #####

Price = 320

Print "CD $" + Str(price)CD $ 320

word$ = " Visual Basic Programming "

Print Len(word$) 27

Print Left(word$,8) Visual

Print Right(word$,12)Programming

Print Mid(word$,10,5)Basic

Print Ltrim(word$)Visual Basic Programming |

例 1 5-38

例 2

5-39

2 3 1

w o r d

w o r d8

w o r d1 2

w o r d 1 05

w o r d

5-38 I

i d o l

3 "*" idol

2 5 "#"

price

5-39 II

Page 45: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

316

1.

(1) Addr$ = " 83 5F"Print Left(Addr$, 5) ______________________________________

Print Mid(Addr$, 4, 5) ____________________________________

Print Len(Addr$) _________________________________________

(2) Print Len(Mid("Civilization", 7)) ____________________________

2. 2 " "

(1) Print ___________________________________

Print ___________________________________

Print ___________________________________

Print ___________________________________

Print ___________________________________

(2) Print ___________________________________

Print ___________________________________

Print ___________________________________

Print ___________________________________

Print ___________________________________

5-11

5-11

Val( ) Val("10") 10Abs( ) Abs(-2) 2Int( ) Int(-3.2) -4Fix( ) Fix(4.8) 4Sqr( ) Sqr(4) 2Rnd( ) 1 >= 0 < 1 Rnd( ) 0.7055475

Page 46: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3175

Print Rnd() 0.7055475

Print Rnd()*10 5.33424

Print Int(Rnd()*10) 5

Print Int(Rnd()*10)+1 3

Print Int(Rnd()*42)+1 13

z1 1

y

z

y

z

x

x = "88"y = 16.6z = -32.5

Print Val(x) 88

Print Abs(z) 32.5

Print Int(y) 16

Print Fix(z)-32

Print Sqr(Int(y)) 4

Print Fix(Int(z)/11)-3

例 1 5-40

0~1

0~9

0~9

1 ~ 1 0

1 ~ 4 2

例 2 Rnd( ) 5-41

5-40 I

5-41 Rnd( )

Page 47: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

318

1.

X = 25.8

Y$ = "-16"

Print Int(X) ________________________

Print Abs(Val(Y$)) _________________

Print Fix(X - Val(Y$)) ______________

2. Rnd( )

(1) 1 1~2______________________________________________________________

(2) 1 1~6 ____________________________________

(3) 1 1~49 ____________________________

(4) 1 10~52 ___________________________

3. 22 BAC +=

(1) Visual Basic

______________________________________________

(2) Visual Basic_____________________________

(3) A = 56 B = 25Print C __________________________

5-12

A C

B

Page 48: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3195

Print Date()2006/11/8

Print Time() 03:30:51

Print Now()2006/11/8 03:31:02

Print Year(Date()) 2006

Print Month(Date()) 11

Print Day(Date()) 8

5-12

Date( ) Date( ) 2006/11/5Time( ) Time( ) 10:58:02Now( ) Now( ) 2006/11/5 10:58:02Minute( ) Minute(#10:58:02#) 58Second( ) Second(#10:58:02#) 2Year( ) Year(#2006/11/5#) 2006Month( ) Month(#2006/11/5#) 11Day( ) Day(#2006/11/5#) 5

Date( ) "yyyy/mm/dd" yyyy mm

dd Time( ) "ap hh:mm:ss" ap

hh 12 mm ss

例 5-42

5-42

Page 49: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

320

( )1. Visual Basic A$ 1 (A)A$ = Left(A$, 1) (B)A$ = Right(A$, 1) (C)A$ = Mid(A$, 1)

(D)A$ = Right(A$, Len(A$) - 1)

( )2. Visual Basic (A)DIC(B)ONA (C)TIONA (D)ICT

A$ = "DICTIONARY"

B$ = MID$(A$, 2, 7)

C$ = RIGHT$(B$, 3)

PRINT C$

( )3.(A)Val( ) (B)Rnd( ) (C)Abs( ) (D)String( )

( )4. Visual Basic 1~42 (A)Int(Rnd * 40) (B)Int(Rnd * 41)

(C)Int(Rnd * 42) (D)Int(Rnd * 42) + 1

( )5. Visual Basic X = INT(RND * 10) + 2 X (A)2 (B)9 (C)11 (D)13

5-3.3

Visual Basic InputBox Print

MsgBox

InputBox

InputBox

Page 50: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3215

UserID = InputBox(" ", " ")

= InputBox [, ][, ]

InputBox

5-43 InputBox InputBox

5-43 InputBox "s8806024" User ID

Print

Print 5-13

5-13 Print

Print " " Print " Visual Basic" Visual BasicPrint Print 1+ 2 3

= Pi = 3.14Print Print Pi 3.14

Page 51: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

322

Print "Visual", "Basic"Visual Basic

Print "Visual"; "Basic"VisualBasic

Print "Visual"; "Basic"; "6"VisualBasic6

Print "Visual"; "Basic"; 6VisualBasic 6

Print ,

; 5-

44 Print

" " Print

5-45

5-44 Print

5-45 Print

MsgBox

MsgBox

Page 52: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3235

MsgBox " ", vbCritical + vbOKOnly, " "

MsgBox [, ][, ][, ]

VB

5-14 5-15

5-14

VBvbCritical 16vbQuestion 32vbExclamation 48vbInformation 64

5-15

VBvbOKOnly 0vbOKCancel 1vbYesNoCancel 3vbYesNo 4

5-46 MsgBox

5-46 MsgBox

Page 53: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

324

Form Activate

Private Sub Form_Activate()

Dim Name As Single

Name = InputBox(" ", " ")

End Sub

Form Activate

Private Sub Form_Activate()

Dim Name As Single

Name = InputBox(" ", " ")

Msgbox "Hello " + Name, 0, " "

End '

End Sub

3

1

2 Acti-vate

3Name

4InputBox

Name

5

6 End

Page 54: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3255

7

"Sp05-3a.frm"

8"sp05-3a.vbp"

9

10 " "

11

Page 55: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

326

( )1. Visual Basic (A) (B) (C) (D)

( )2. A = 2 B = 3 C = 4 Visual BasicTrue (A)B > C (B)NOT A > B AND B < A + C (C)A = C = B+ 4 (D)20 / C + A = B + 2

( )3. I = P(1 + r)t Visual Basic (A)I = P * r + P * t (B)I = P * (1 + r) ^ t (C)I = P ^ t

+ (P * r) (D)I = P + r ^

( )4. Visual Basic "Print Minute(Time())" (A)12 (B)28 (C)56 (D)90

( )5. Visual Basic Print (A), (B)+ (C); (D)@

( )6. Visual Basic Print (A)&(B)? (C)% (D)#

( )7. Visual Basic tckno = InputBox(" ", "", 2) " " 4

(A) (B) (C) (D)

( )8. Visual Basic MsgBox " ", 48, " " " "

(A) (B) (C) (D)

( )9. Msgbox (A)+ (B)& (C)* (D)-

10. InputboxMsgbox

(1) A A = pi * r * r pi

(2) Form Activate

(3) "Sp05-b.frm" "Sp05-b.vbp"

Page 56: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3275

5-4

5-47

Visual Basic

control object

Form Command

Button Label

5-48

5-48 Visual Basic

5-4.1 V i s u a l B a s i c p r o p e r t y

method event 3

courtesy of Motorola &

5-47 PDA

Page 57: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

328

Visual Basic

2

1 5-

4 9

Command1C a p t i o n

"Command1"

"Command1" " "

C a p t i o n

C a p t i o n

5-49

Page 58: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3295

. =

Command1 Label1

Caption " " " "

例 1 Command1.Caption = " "

例 2 Label1.Caption = " "

1. 1 Caption" "

2. Command1 Caption

Visual Basic

.

Page 59: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

330

Print Cls Print

Cls 5-50

例 1 Form1.Print " VB Go Go Go "

例 2 Form1.Cls

1 Pr in t 2 Cls

5-50 Print Cls

Visual Basic

Click 5-51

5-51 Click "Hello "

Click

Private Sub Form_Click() Print "Hello "End Sub

Page 60: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3315

Visual Basic

event procedure

5-52( )

5-

52( )

'

Private Sub Form_Click()

Form1.Caption = " Click "

Form1.Print

Form1.Print " "

Form1.Print

End Sub

C l i c k

5-52

http://yes.nctu.edu.tw/vb/0_Basis/Sect/Sect4.htm Visual Basic

Visual Basic

5-52

Visual Basic event-driven

"Ch05-4a.vbp"

Page 61: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

332

Visual Basic

_

Form_Activate

5-53

5-54

1Form Load

2 3Activate

5-53 Form_Load

1.Form_Click

5 - 6 . 2

Page 62: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3335

( )1. Visual Basic (A) (B) (C) (D)

( )2. (A) (B) (C) (D)

3. Visual Basic

5-54

(1) "Command1" " "

(2) " "

(3)

global variable "Publ ic"

Page 63: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

334

5-4.2 Visual Basic Form

5-55 Form

Label

CheckBox

Frame CheckButtonO p t i o n B u t t o n

Timer

Image

ComboBox

Microsoft Excel

5-55 Visual Basic

Page 64: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3355

Form

CommandButton M S N

OptionButton

TextBox

PictureBox 1

ListBox 2

Line

Visual Basic Microsoft Word

MSN Messenger

1 Image PictureBox Image Stretch Image2 ComboBox ListBox ComboBox

Page 65: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

336

Form CommandButton Label

TextBox 4

Form

Form

5-56 Form

BackColor

Fon t

ForeColor

Name

Height

Width

Capt ion

5-56 Form Caption BackColor Font ForeColor Height Name Width

Page 66: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3375

5-16 Form

5-16 Form

ClsHideShowPrint "?" Print

5-17 Form

5-17 Form

Activate

ClickDblClickLoad

Load

Activate Form1 Form2

Form2 Form2 Activate

VB 1 Load Activate

Load Activate

Page 67: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

338

5-57

1. Form1 Caption

2. Form1 Font 14

"Ch05-4b.vbp"

Click Print

Private Sub Form_Click()

Print '

Print " " '

End Sub

Click

5-57

Page 68: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3395

1. Click "" DbClick " "

CommandButton

CommandButton

5-58 CommandButton

Default

TrueFalse

F o n t

EnabledTrue

False

Capt ion

5-58 CommandButton Caption Default Enabled Font

Cl ick

DbClickCl ick

DbClick

Page 69: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

340

Click CommandButton

Click 5-59

5-59 CommandButton Click

5-60

/

5-60

C l i c k

Page 70: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3415

1. 1 Command1

2. Command1 Caption " " Enabled

False

"Ch05-4c.vbp"

1. Click Command1 Enabled True

2. Command1 Click Cls

Command1 Enabled False

Private Sub Command1_Click() Cls ' Command1.Enabled = False 'End Sub

Private Sub Form_Click() Command1.Enabled = True 'End Sub

1. 1

Page 71: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

342

Label

Label

5-61 Label

BackColor

Caption

ForeColor

Visible T r u e

False

Alignment

BorderStyle0

1

5-61 Label Alignment BackColor BorderStyle Caption ForeColor Visible

5-62

Page 72: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3435

5-62

1. 2 Label1 Label2 1 Command1

2. 5-18

5-18

Form1 CaptionLabel1 CaptionLabel1 ForeColor &H00FF0000&Label2 CaptionLabel2 ForeColor &H000000FF&Command1 Caption

"Ch05-4d.vbp"

1. Form1 Load Label2

Visible False

2. Command1 Click Label2 Visible

True

Visible

True False

Page 73: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

344

Private Sub Form_Load()

Label2.Visible = False ' Label2

End Sub

Private Sub Command1_Click()

Label2.Visible = True ' Label2

End Sub

1.1

4

Page 74: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3455

TextBox

TextBox

5-63 TextBox

Enabled T r u e

F a l s e

Alignment

PasswordChar

ScrollBars 0

12 3

MultiLine

T r u eFa l se

Text

5-63 TextBox Alignment Enabled MultiLine PasswordChar ScrollBars Text

SetFocus TextBox

5-

64 SetFocus

1

Page 75: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

346

Command2_Click

5-64 TextBox SetFocus 21

2 a b

a b 5-65

a b

5-65 a b

Command2 Click

Private Sub Command2_Click() Text1.Text = "" Text2.Text = "" Text1.SetFocusEnd Sub

"Ch05-4e.vbp"

Page 76: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3475

1. 3 Label1 Label2 Label3 2

Text1 Text2 1 Command1

2. 5-19

5-19

Form1 Caption a bLabel1 Caption a =Label2 Caption b =Label3 CaptionText1 TextText2 TextCommand1 Caption

"Ch05-4f.vbp"

1. Command1 Click a b c

2. 2 Text1 Text2

a b

3. c ab

4. Label3 Caption ab

Private Sub Command1_Click() Dim a As Integer, b As Integer, c As Long a = Val(Text1.Text) ' b = Val(Text2.Text) ' c = a ^ b Label3.Caption = a & " " & b & " = " & cEnd Sub

Page 77: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

348

(1) "Ex05-c.vbp"

(2) Label2 ~ Label8MsgBox " ", , " "

(3) "Sp05-c.vbp"

1. Visual Basic3

a. c. e.b. d. f.

2. a b4

3.

Page 78: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3495

5-5

5-66

1 2 3 4

5-66

3

5-5.1 algorithms

Page 79: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

350

5-67

1.

2.

3.

4. 1 ~ 3

1101001

1101002

1101003

1101004

75

62

78

60

( )

73

76

90

85

( )

80

82

88

70

68

77

74

90

74

72

89

75

1101001

1101002

1101003

1101004

75

62

78

60

( )

73

76

90

85

( )

80

82

88

70

68

77

74

90

74

72

89

75

370

369

419

380

5-67

Page 80: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3515

5-20

5-20

Page 81: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

352

BBS

BBS

5-68

BBS T TrueF False

F

T

T

F

pseudocode 5-69 5-68

5-68 BBS

Page 82: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3535

1.

2.

3.

1. BBS

2.

3.

2 4

4. BBS

5-69 BBS

3

sequence structure

5-70(a)

condition structure

5-70(b)

repetition structure

5-70(c)

T

F

N

1

F T

11

( c )( b )( a )

5-70 3

N

1

2

Page 83: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

354

( )1. (A) (B) (C) (D)

( )2. (A) (B) (C) (D)

( )3. 5 (A) (B) (C) (D)

4.

5-71

Page 84: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3555

5-5.2 3 3

Visual Basic 3

5-72 a

b

Dim a As Integer, b As Integer

Dim c As Long

a = InputBox(" a ")

b = InputBox(" b ")

c = a * b

Print a & "*" & b & "=" & c

5-72 a b

1.

(1)

(2) -

(3)

2.

"Ch05-5a.vbp"

Page 85: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

356

5-5.3

KTV

If Select Case

If

If If-Then " " If-Then-

Else " "

If-Then

If-Then

5-73

T

F

5-73 If-Then

If

Page 86: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3575

If-Then

If-Then

1 If Then

2 If Then

End If

1. 1 12

2. If-Then End If

5-74 If-Then

0~2 " "

Dim x As Single

x = InputBox(" ")

If x > 0 And x <= 2.0 Then Print " "

5-74 If-Then

5-75 If-Then

"Yes" 7

"Ch05-5b.vbp"

Page 87: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

358

Dim price As Integer

price = 250

Ans = InputBox(" Y N")

If Ans = "Y" Or Ans = "y" Then

price = price * 0.7 ' 7

Print " " & price

End If

5-75 If-Then

( )1. Visual Basic (A)A = 1, B = 1 (B)A =1, B = 2 (C)A = 2, B = 1 (D)A = 2, B = 2A = 1 : B = 2If A < B Then A = BIf A > = B Then B = A - 1Print "A " A "," "B = " B

2. If-Then

(1) 18Y = InputBox(" ")

If Then Print " "

(2) C5.37~C0.34 °°

x = InputBox(" ")

If Then Print " "

(3) aa = InputBox(" a ")

If Then a = -a

Print a & " " & a

"Ch05-5c.vbp"

Page 88: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3595

1. ThenElse

2. If-Then-Else End If

TF

If Then

Else

End If

5-76 If-Then-Else

If-Then-Else

If-Then-Else

5-76

If

Page 89: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

360

5-77 If-Then-Else

0.8~1.2 " " "

"

Dim x As Single

x = InputBox(" ")

If x > 0.8 And x <= 1.2 Then

Print " "

Else

Print " "

End If

5-77 If-Then-Else I

5-78 If-Then-Else

1 15 " " " "

5-78 If-Then-Else II

Dim d As Integer

d = InputBox(" ")

If d = 1 Or d = 15 Then

Print " "

Else

Print " "

End If

"Ch05-5d.vbp"

"Ch05-5e.vbp"

Page 90: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3615

5-79 If-Then-Else

>= 60

" " " "

F

T

5-80 60

If

If-Then-Else "

" " " 5-79 5-80

Page 91: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

362

Form Activate()

Private Sub Form_Activate()

10 Dim score As Integer

20 score = InputBox(" ")

30 If score >= 60 Then

40 MsgBox " "

50 Else

60 MsgBox " "

70 End If

80 End

End Sub

4

1Form1 Activate

2 score

3 score60

4

2 "55"

3

"Sp05-5a.frm" "Sp05-5a.vbp"

1

Page 92: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3635

1. 75 4

2. If-Then-Else 37

week = InputBox(" ")

If Then

Print " "

Else

Print " "

End If

I f

I fIf If If 5-81 If

PH

ph = InputBox(" PH ")

If ph = 7 Then 'PH 7

Print " "

Else

If ph < 7 Then 'PH 7

Print " "

Else

Print " " 'PH 7

End If

End If

5-81 If PH

Page 93: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

364

Select Case

Select Case

5 - 8 2

5-82 If Select Case income100 40 ~ 99 < 40

If income >= 100 Then

Print " "

Else

If income >= 40 Then

Print " "

Else

Print " "

End If

End If

Select Case income

Case >= 100:Print " "

Case >= 40:Print " "

Case Else:Print " "

End Select

I f Select Case

Select Case 5-83

Select Case

Case Else

N+1

Case N

N

Case 2

2

Case 1

1

5-83 Select Case Case

Page 94: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3655

Select Case

Case 1

1

Case 2

2

Case 3

3

Case N

N

Case Else

N+1

End Select

1. 1 12 2

2. N+1

3. Select Case Case

(1) Case 1 Case 2, 3, 4 Case "A", "B"

(2) Case 1 To 10 Case 15 To 25

(3) Case Is > 2 Case Is = 1

4. Case Else

Page 95: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

366

Dim age As Integer

age = InputBox(" ")

Select Case age

Case Is < 6 ' 6

Print " "

Case Is < 12 '6~11

Print " "

Case Is < 18 '12~17

Print " "

Case Else '18

Print " "

End Select

Dim ph As Single

ph = InputBox(" PH ")

Select Case ph

Case Is = 7 Print " " 'PH 7

Case Is < 7 Print " " 'PH 7

Case Is > 7 Print " " 'PH 7

End Select

5-84 Select Case I PH

5-85 Select Case

5-85 Select Case II

5-84 Select Case PH

P.363 If

"Ch05-5f.vbp"

"Ch05-5g.vbp"

Page 96: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3675

Select Case

4 Select Case

5-86 5-87

5-86 Select Case

" " " " " " " " " " "

"

=

>= 90 >= 70 >= 60 < 60>= 80

5-87 90 80~89 70~79 60~6960

< 0 or > 100

Page 97: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

368

Form Activate()

Private Sub Form_Activate()

10 Dim score As Integer

20 score = InputBox(" :")

30 Select Case score

Case 90 To 100: MsgBox " "

Case 80 To 89: MsgBox " "

Case 70 To 79: MsgBox " "

Case 60 To 69: MsgBox " "

Case Is < 60: MsgBox " "

Case Else: MsgBox " "

40 End Select

50 End

End Sub

5 "Ex05-5b.vbp"

1

2 30~70

30~40score

2 "90"

3

"Sp05-5b.frm" "Sp05-5d.vbp"

1

Page 98: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3695

1. 5

(1)

(2)

(3)

(4)

2.

(1) 45 -59

(2) 60 -74

(3) 75 -90

(4) 91

3. "Ex05-d.vbp" If-Then-Else SelectCase BMI

"Sp05-d.vbp"

(1) BMI = / ( )2

(2) If-Then-Else 2.5300

(3) Select Case BMI BMI20~25 19~24

Page 99: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

370

+

5-5.4 4000

400 10

Visual Basic For-Next While-Wend

For-Next

For-Next

5-88

T

F

=

?

5-88 For-Next

Page 100: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3715

For = To Step

Next

1. 1 For-Next

2. For-Next

3. Next

N = InputBox(" ")S = InputBox(" ")R = 0.02 ' 2%For i = 1 To N S = S * (1 + R)Next iPrint " = " & S

sum = 0 ' sumFor i = 1 to 10 Step 1 ' Step 1 sum = sum + iNext iPrint "1 + 2 + 3 + + 10 = " & sum

5-89 For-Next I 1 10

5-90 For-Next

5-90 For-Next II

5-89 For-Next 1 10

"Ch05-5h.vbp"

"Ch05-5i.vbp"

Page 101: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

372

For-Next

For-Next

5 1~20

5-91 5-92

5

5-92 5 For-Next 5 1 ~ 20

1~20

5-91 5 1~20

i 1

i > 5 T

F

Page 102: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3735

Form Activate()

Private Sub Form_Activate()

' N

10 Dim N As Integer, i As Integer

' rec 5

20 Dim rec As String

'

'

30 rec = "": N = 0

40 For i = 1 To 5

50 N = Int(Rnd * 20) + 1

60 rec = rec + " " + Str(N)

70 Next i

80 MsgBox " 5 1~20 " _

& rec

90 End

End Sub

565

1Form1 Active

2 N i

3 r e c

4 rec N

5 For-Next5 1

1~20

rec

6 5

7

2 5

"Sp05-5c.frm" "Sp05-5c.vbp"

1

Page 103: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

374

For-Next

1. 6

6 1~42

2. For-Next 40

sum = 0 chi = 0 avg = 0

For i = To

chi = InputBox(" " & i & " ")

sum = sum + chi

Next i

avg = sum / 40

Print " " & avg

For i = 1 To 9

For j = 1 To 9

Print i & " " & j & " = " & i*j;

Next j

Print '

Next i

5-93 i j

Page 104: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3755

While-Wend

While-Wend

5-94

F

T

While

5-94 While-Wend

While

Wend

1.

2.

3.endless loop

Page 105: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

376

i = 1 : sum = 0 'While i <= 10 sum = sum + i i = i + 2WendPrint "1 + 3 + 5 + + 9 = " & sum

5-95 While-Wend I 1 10

5-95 While-Wend 1 10

i = 1 : power = 1N = InputBox(" N ", " 2 N ")While i <= N power = power * 2 i = i + 1WendPrint "2 " & N & " = " & power

5-96 While-Wend II 2 N

5-96 While-Wend 2 N

While-Wend

6

While-Wend Select Case

4

0 ~ 9

5-97 5-98 5-97

"Ch05-5j.vbp"

"Ch05-5k.vbp"

Page 106: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3775

i <= 4F

i =

i 1

T

4321

5-98 While-Wend Select Case 4

Text11

Text22

Text33

Text44

Page 107: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

378

Form Activate()

Private Sub Form_Activate()

' N

10 Dim N As Integer, i As Integer

20 N = 0 : i = 1

'VB

'

30 Randomize

40 While i <= 4

50 N = Int(Rnd * 10)

60 Select Case i

Case 1: Text1.Text = N

Case 2: Text2.Text = N

Case 3: Text3.Text = N

Case 4: Text4.Text = N

70 End Select

80 i = i + 1

90 Wend

End Sub

7 "Ex05-5d.vbp"

1

2 20~30

20~30

3 4040

While

4 50~70

50~90

0~9

2

"Sp05-5d.frm" "Sp05-5d.vbp"

1

Page 108: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3795

Do-Loop

While-Wend Do-Loop Do-Loop

Do-Loop Do-Loop 5-21 2

5-21 Do-Loop

Do-Loop 1 1 0

1 sum = 0

Do While i = 1

Do While i <= 10

Loop Sum = sum + i

i = i + 1

Loop

Print "1 + 2 + 3 + + 10 = " & sum

2 sum = 0

Do Until i = 1

Do Until i > 10

Loop Sum = sum + i

i = i + 1

Loop

Print "1 + 2 + 3 + + 10 = " & sum

1 sum = 0

Do i = 1

Do

Loop While Sum = sum + i

i = i + 1

Loop While i <= 10

Print "1 + 2 + 3 + + 10 = " & sum

2 sum = 0

Do i = 1

Do

Loop Until Sum = sum + i

i = i + 1

Loop Until i > 10

Print "1 + 2 + 3 + + 10 = " & sum

Page 109: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

380

1. 7

(1) InputBox

(2) Select Case

2. While-Wend

(1) a1 + a2 + a3 + + ab

a = InputBox(" a ")

b = InputBox(" b ")

i = 1 : sum = 0 : power = 1

While

power = power * a

sum = sum + power

i = i + 1

Wend

Print sum

(2) An A1 = 2 r = 5

A1 = 2 : r = 5 : i = 1

An = A1

n = Int(InputBox(" n ", " An"))

While

An = An * r

i = i + 1

Wend

Print "An = " & An

Page 110: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3815

( )1. Visual Basic "#" (A)6 (B)7(C)8 (D)9

For i = 19 To 1 Step -3

Print "#";

Next i

( )2. ( ) " " Visual Basic( ) (A)i - 1 (B)i (C)i + 1 (D)i * 2

For i = 1 To 5

Print Space( );

Print i

Next I

( )3. Visual Basic "100" (A)5 (B)6 (C)64 (D)128

n = 0

a = InputBox("input data")

While a > 0

a = a - 2 ^ n

n = n + 1

Wend

Print n - 1

( )4. Visual Basic (A)12345 (B)5234344 (C)51234234 (D)523434

X$ = "234" Y$ = "5" I = 3

While I >= 1

Y$ = Y$ + Right(X$, I)

I = I - 1

Wend

Print Y$

123

45

Page 111: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

382

5-6

structured programming

GoTo

5-99

a

b

c

End

5-99

a

End a

c

End c

b

End b

a

goto b

c

b

goto a

goto c

Page 112: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3835

5-6.1

top-down programming

modular programming

5-

100

5-100

~~ ~~ ~~ ~~ ~~ ~~

Page 113: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

384

module

5 - 1 0 1

50

GoTo

5-102

F T

TF

GoTo

GoTo

5-102 GoTo

1

2

n

5-101

Page 114: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3855

( )1. (A) (B) (C) (D)

( )2. (A)(B) (C)

GoTo (D)

( )3. (A) (B)(C) (D)

( )4. GoTo (A) (B) (C) (D)

GoTo

GoTo 5-103GoTo

a = 1

TWO:Print a

a = a + 1

If a <= 10 Then GoTo TWO

Print "end"

GoTo

:

5-103 GoTo

Page 115: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

386

5-6.2 Visual Basic

subprogram user-defined function

Sub End Sub

call 5-104

Sub A....

End Sub

.

.

.Call A

.

.

.

.

.

.

5-104

Sub [( 1 [As ], 2 [As ], )]

End Sub

Page 116: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3875

1.

2.Visual Basic

3. Subformal parameters Call

actual parameters

4. Call Call

Call [( 1, 2, )]

Sub Change_temp(F As Integer) 'F

Dim C As Integer

C = (F - 32) * 5 / 9

MsgBox " " & F & " = " & C & " ", , " "

End Sub

Private Sub Form_Activate( )

Dim F_temp As Integer

F_temp = InputBox(" ", " ")

Call Change_temp(F_temp) 'F_temp

End Sub

5-105

5-105

"Ch05-6a.vbp"

Page 117: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

388

1.

(1) = * 9 / 5 + 32

Sub Change_temp(C As Integer)

Dim F As Integer

F =

Print " " & C & " = " & F & " "

End Sub

Private Sub Form_Activate( )

Dim X As Integer

X = InputBox(" ", " ")

Call

End Sub

(2) 2 12

Sub Check_Id(S_id As String)

Dim sex As Integer

sex = Int(Mid(S_id, 2, 1))

If Then ' If-Else-If VB

Print " " ' If

ElseIf Then '

Print " "

End If

End Sub

Private Sub Form_Activate( )

Dim id As String

id = InputBox(" ", " ")

Call

End Sub

Page 118: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3895

Visual Basic

Function End Function

5-106

VB

5 - 3 . 2

100V

Function A( ) As Integer....

A( ) = 100

End Function

.

.

.V = A( )

.

.

.

.

.

.

.

5-106

Function [( 1 [As ], 2[As ], )] As

= End Function

Page 119: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

390

1.

2.Visual Basic

3. Function

4. Function

= [( 1, 2, )]

Function Cal_Circle(r As Single) As Single 'r

Const pi = 3.14159

Cal_Circle = r ^ 2 * pi

End Function

Private Sub Form_Activate( )

Dim X As Single

Dim area As Single

X = InputBox(" ", " ")

area = Cal_Circle(X) 'X

MsgBox " " & X & " = " & area, , " "

End Sub

5-107

5-107

"Ch05-6b.vbp"

Page 120: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3915

1.

(1)

Function Cal_Cycle(r As Single) As

Const pi = 3.14159

Cal_Cycle = 2 * pi * r

End Function

Private Sub Form_Activate( )

Dim x As Single, p As Single

x = InputBox(" ", " ")

MsgBox " " & x & " = " & p

End Sub

(2)

Function Cal_Rnd(lower As Integer, upper As Integer) As

Cal_Rnd = Int(Rnd * (upper - lower + 1)) + lower

End Function

Private Sub Form_Activate( )

Dim n1 As Integer, n2 As Integer

Dim n As Integer

n1 = InputBox(" ", " ")

n2 = InputBox(" ", " ")

Print n

End Sub

Page 121: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

392

( )1.(A) (B) (C)

(D)

( )2. Visual Basic (A)0 (B)512 (C)-1024 (D)1024

Sub SUM(X As Integer, Y As Integer)TOTAL = -X ^ YPrint TOTAL

End Sub

Private Sub Form_Activate( )Call SUM(2, 10)

End Sub

( )3. 1 TOTAL = -X ^ Y TOTAL = X^ 2 * (-Y) (A)-40 (B)40 (C)-200 (D)200

( )4. Visual Basic (A)1 + 2 + 3 + + x (B)(1 + 2 + 3 + + x)2 (C)12 + 22 + 32 + + x2 (D)1x + 2x + 3x + + xx

Sub Cal(x As Integer)Dim sum As Long, i As Integersum = 0For i = 1 To x

sum = sum + i ^ 2Next iPrint sum

End Sub

( )5. Visual Basic FNA(4,18)(A)9 (B)10 (C)16 (D)32

Sub FNA(X As Integer, Y As Integer)ANS = (X ^ 2 + Y Mod 7) / 2Print ANS

End Sub

Page 122: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3935

Windows

http://toget.pchome.com.tw/ PChome Online -http://www.softking.com.tw/ http://www.teagames.com/games/funkytruck/play.php flash

_______________________

_____________________

________________________________

________________________________

_____________________

________________________________

_______________________

_____________________

________________________________

________________________________

_____________________

________________________________

1.2.

Flash_______________________

_____________________

________________________________

________________________________

_____________________

________________________________

_______________________

_____________________

________________________________

________________________________

_____________________

________________________________

Page 123: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

394

(1) machine language

(2) assembly language0 1

assembler

variable constant

(1) source code

(2)

Visual Basic

^ 1

- 2

* 3

/ 3

\ 4

Mod 5

+ 6

- 6

Page 124: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3955

Visual Basic

(1) InputBox = InputBox( [, ][, ])

(2) PrintPrint " " Print Print

(3) MsgBoxMsgBox [, ][, ][, ]

Visual Basic attribute methodevent

(1) Caption

(2) Print

(3)Click

algorithms

(1)

(2)

sequence condition repetition 3

T

F

N

1

F T

11

N

1

2

Page 125: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

396

=

?T

F

+

If-Then-Else

If Then

True

Else

False

End If

Select Case

Select Case

Case 1

1

Case 2

2

Case 3

3

Case N

N

Case Else

N+1

End Select

For-Next

For = To Step

Next

While-Wend

While

Wend

T

F

Select Case?

Case N

N

Case Else

N+1

Case 2

2

Case 1

1

Page 126: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3975

GoTo

GoTo

modulesubprogram

user-defined function

call

Sub ( 1 As , 2 As , )

End Sub

Call ( 1, 2, )

Sub formal parameters Callactual parameters Visual

Basic

built-in function user-defined function

Function ( 1 As , ) As

=

End Function

( 1, 2, )

Visual Basic

Page 127: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

398

( )1.(A) (B) (C) (D)

( )2. (A) (B) (C) (D)

( )3. Visual Basic NOT (A) (B) (C) (D)

( )4. (A) (B) (C) (D)

( )5.VB

(A)Int( ) (B)Rnd( ) (C)Str( ) (D)Val( )

( )6. Print Year(Data( )) - 1989 2006/05/14 (A)15 (B)16 (C)17 (D)18

( )7. A BC VB

YN A B C3 (A)YN = (A And B) Or C (B)YN = A And (B

Not C) (C)YN = (A Or B) EQV C (D)YN = (A Xor B) and C

( )8. Visual Basic 47.3 \ 6.8 + 47.3 Mod 6.8 (A)12(B)11 (C)10 (D)9

( )9. Visual Basic (A)Label (B)

TextBox (C)CommandButton (D)Form

( )10. If-Then-Else (A) (B) (C) (D)

( )11. Visual Basic (A)If-Then-Else (B)For-Next (C)Select Case (D)While-Wend

Page 128: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

3995

( )12. Visual Basic (A)error (B)large (C)medium (D)small

Private Sub Form_Activate( )

X = 5 \ 2

Select Case X

Case 1

print "small"

Case 2

print "medium"

Case Else

print "large"

End Select

End Sub

( )13. Visual Basic (A)18 (B)20 (C)22 (D)24

a = 1 b = 10

While b < 20

b = b + 2 * a

a = a + 1

Wend

Print b

( )14. Visual Basic (A)-2 (B)-1 (C)0 (D)1

Private Sub Heart(m As Integer)

m = m ^ (m + 2)

End Sub

Private Sub Form_Activate( )

Dim C As Integer

C = -1

Call Heart (C)

Print C

End Sub

Page 129: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

400

( )15. T (A)40 (B)30 (C)20 (D)10

Function FNP(X)

FNP = X * X + X

End Function

Private Sub Form_Activate( )

For K = 1 To 4

T = T + FNP(K)

Next K

Print T

End Sub

( )16. Visual Basic (A)5 (B)3 (C)a > b (D)a < b

a = 5 b = 3

If a > b Then

Print "a > b"

Else

Print "a < b"

End If

1. 3

A. B. C.

(1) 50%

(2)

(3) 3

2. For-Next While-Wend Do-Loop If-Then-Else "Sp05-e.vbp"

Page 130: VB203.72.185.33/elong/webclass/A05231C/A05231C05.pdfVisual Basic .NET 1. Visual Basic 2. encapsulation inheritance polymorphism 3 101 101 5 281 redefine 3 VBA Office JavaScript ActionScript

4015

(1) InputBox( )"op5e4"

(2) 3

(3) For-Next "Exit For" For-Next

3. C.C "Sp05-f.vbp"

(1) InputBox( ) C.C.

(2)

C.C.50

51~250

251

(3) MsgBox( )


Recommended