This presentation is the property of its rightful owner.
Sponsored Links
1 / 74

本 章 内 容 PowerPoint PPT Presentation


  • 92 Views
  • Uploaded on
  • Presentation posted in: General

第七章 程序设计基础. 本 章 内 容. §7.1  程序文件的建立与运行 §7.2  结构化程序设计初步 §7.3  程序设计基本语句 §7.4  顺序结构 §7.5  选择结构 §7.6  循环结构. §7.7  过程 §7.8  参数传递与变量作用域 §7.9  自定义函数. Visual FoxPro 的工作方式分为 交互方式 和 程序方式 两大类 命令 1       程序 .prg 响应 1 命令 2 响应 2 …… …… …… 命令 n 响应 n. 命令 1 命令 2 命令 3 …… …… …… 命令 n.

Download Presentation

本 章 内 容

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


4051024

7.1

7.2

7.3

7.4

7.5

7.6

7.7

7.8

7.9


4051024

Visual FoxPro

1.prg

1

2

2

n

n

1

2

3

n


4051024

7.1

1

2

VFP.prg.fxpVFP

VFPVFPVFPSQL


4051024

7.1.1

1

1

3

1

2


4051024

3

1MODIFY COMMAND [<>]

2MODIFY FILE [<>]

11.PRG2.TXT

21.TXT2.PRG

3


4051024

2

3


4051024

2

1

3

1

2


4051024

3

MODIFY COMMAND [<>][<>][<>]

2

3

Ctrl+W

ESC


4051024

7.1.2

1

2


4051024

3

DO [<>][<>]<>

1

2.EXEVFP.APPVFP.FXP.PRG

3DO.qpr.mpr.app


4051024

7.2

7.2.1

1

2


4051024

3


4051024

7.2.2

1

3

2

1

2


4051024

7.3

7.3.1

1

CLEAR

VFP

2

SET TALK ON|OFF

1VFPSET TALK ON

2SET TALK OFF


4051024

3 .

SET SAFETY ON|OFF

1VFPSET SAFETY ON

2SET SAFETY OFF


4051024

4

1* <>

2NOTE <>

3&&<>

1

2

3* <>

4&&<><> &&<>


4051024

7.3.2

1

1INPUT

INPUT [<>] TO <>

1MG

2<>

73


4051024

CLEAR&&

USE Zgjk&&

INPUT "" TO gz&&

LIST FOR >=gz &&

74

74 73


4051024

2ACCEPT

ACCEPT [<>] TO <>

1C

2

3


4051024

3WAIT

WAIT [<>] [TO <>] [WINDOW] [TIMEOUT <>]

1C

2

3

4WINDOWVFPWINDOWWAIT

5TIMEOUT<>


4051024

745

CLEAR

CLOSE ALL&&

USE Zgjk

ACCEPT TO NAME&&

LOCATE FOR =NAME&&

IF !EOF()&&

?+ &&,

?""+

?+DTOC() &&

?""+STR(,7,2)

ELSE

WAIT "" WINDOW TIMEOUT 5 &&,5

ENDIF


4051024

75

75 74


4051024

2

? | ?? [<>]

1?

2??

3?

75[74]


4051024

1[74][75]

2

CLEAR

USE Zgjk

ACCEPT "" TO NAME &&

LOCATE FOR =NAME&&

IF !EOF()&&

?""+&&

??+ &&

?""+DTOC() &&

??""+STR(,7,2)&&

ELSE

WAIT "" WINDOW TIMEOUT 5&&,5

ENDIF


4051024

3

476

76 75


4051024

7.3.3

1

RETURN

1RETURN

2RETURN,

2VFP

QUIT

VFPVFP


4051024

7.3.4

MessageBox(<> [,<>] [,<>])

<>3

<>+<>+<>

MessageBox72


4051024

MessageBox73


4051024

74MessageBox


4051024

7.4

1

77

77


4051024

2

7620018%,2010

Clear

N=2010-2001

V=1*(1+0.08)^N

?"2010",V

Return

20102.00


4051024

7.5

IFCASE

7.5.1

1

IF <>

<1>

ENDIF

1ENDIFENDIF77

77


4051024

77,

CLEAR

INPUT "X=" TO X &&ACCEPTWAIT

INPUT "Y=" TO Y

IF X>Y

T=X

X=Y

Y=T

ENDIF

? "X=",X

? "Y=",Y

78

79 77


4051024

2

IF <>

<1>

[ ELSE

<2>]

ENDIF

1ENDIF2ENDIF710

710 ELSE


4051024

78Zgjk2.dbf10005030!

*

CLEAR

USE Zgjk2

LIST

ACCEPT "" TO Zgh

LOCAT FOR =Zgh

IF FOUND( )

IF <1000

REPLACE WITH +50

ELSE

REPLACE WITH +30

ENDIF

DISPLAY

ELSE

MESSAGEBOX("!")

ENDIF


4051024

711

711 78

79.dbc!


4051024

* SQL

CLEAR

ACCEPT "" TO Zgh

OPEN DATABASE

USE Zgjk

LOCATE FOR = Zgh

IF FOUND( )

SELECTGz.,,,,,,,,;

FROM Zgjk, Gz;

WHERE Zgjk.= Zgh AND Zgjk.=Gz.

ELSE

MESSAGEBOX("!")

ENDIF

CLOSE DATABASE


4051024

712

712 79


4051024

7.5.2

:

DO CASE

CASE <1>

<1>

CASE <2>

<2>

CASE <n>

<n>

[OTHERWISE

<>]

ENDCASE


4051024

OTHERWISEENDCASE

1CASECASE

2OTHERWISE

713

713


4051024

710Zgjk.dbf!

CLEAR

USE Zgjk

INPUT "123" TO Bmh

DO CASE

CASE Bmh =1

BM=""

CASE Bmh =2

BM=""

CASE Bmh =3

BM=""

OTHERWISE

? "!"

RETURN

ENDCASE

LIST FOR =BM


4051024

714

714 710


4051024

7.6

VFP3

1DO WHILEENDDO

DO WHILE <> &&

<>&&

ENDDO&&

7.6.1


4051024

DO WHILE <>DO WHILEENDDOENDDODO WHILEENDDO

715

715


4051024

711S=1+2+3++100

* S=1+2+3++100

CLEAR

S=0&&0

K=1&&1

DO WHILE K<=100

S=S+K&&

K=K+1&&1

ENDDO

? "S=",S

S=5050


4051024

SKS=S+KK=K+1

01S=0+1K=1+1

0+12S=0+1+2K=2+1

0+1+23S=0+1+2+3K=3+1

0+1+2+3++99100S=0+1+2+3++99+100K=100+1


4051024

71220!=1*2*3**20

* 20!=1*2*3**20

Clear

S=1&&1

K=1&&K

Do While K<=20

S=S*K&&

K=K+1 &&1

Enddo

? "S=" , S

S=2432902008176640000


4051024

S K S=S*KK=K+1

1 1 S=1*1K=1+1

1*1 2 S=1*1*2K=2+1

1*1*2 3 S=1*1*2*3K=3+1

1*1*2*3**19 20 S=1*1*2*3**19*20K=20+1


4051024

713Zgjk.dbf

*

CLEAR

USE Zgjk

DO WHILE ! EOF( )

DISPLAY

WAIT ""

SKIP

ENDDO


4051024

716

716 713

714


4051024

? "",A

? "",B

? "",C

? "",D

? "",E

CLEAR

USE

LIST&&EOF

GO TOP&&

STORE 0 TO A,B,C,D,E &&0

DO WHILE !EOF()&&

DO CASE

CASE >=90

A=A+1&&90

CASE >=80

B=B+1&&>=80.AND.<90

CASE >=70

C=C+1&&>=70.AND.<80

CASE >=60

D=D+1&&>=60.AND.<70

OTHERWISE

E=E+1&&<60

ENDCASE

SKIP&&

ENDDO&&


4051024

716

716 714


4051024

2

1

EXIT

ENDDO

2

LOOP

DO WHILE

LOOPLOOP

3LOOPEXIT


4051024

DO WHILE <>&&

< 1>

[LOOP]

< 2> &&

[EXIT]

< 3>

ENDDO&&

LOOPEXIT717

717 LOOPEXIT

715.dbfQ


4051024

CLEAR

USE

DO WHILE .T.

ACCEPT "(Q)" TO XH

IF UPPER(XH)="Q"&&

EXIT

ENDIF

ACCEPT "" TO XM

INPUT "" TO CJ

APPEND BLANK

REPLACE WITH XH, WITH XM,WITH CJ

ENDDO

WAIT "" TIMEOUT 5

LIST


4051024

719

719 715


4051024

7.6.2

FOR-ENDFOR

FOR <>=<> TO <> [STEP <>]

<>

ENDFOR | NEXT

ENDFOR


4051024

720

720

71610


4051024

CLEAR

INPUT "" TO ANY

STORE ANY TO MA, MI&&MA,MI

FOR I=2 TO 10

INPUT "" TO ANY&&210

IF MA < ANY&&ANYMAANYMA

MA = ANY

ENDIF

IF MI > ANY &&ANYMIANYMI

MI = ANY

ENDIF

ENDFOR

?"", MA

?"", MI


4051024

721

71710003153=13+53+33153

721 716


4051024

* 1000

CLEAR

? "1000"

FOR X=100 TO 999

X1=X%10&&

X2=INT(X/10)%10&&

X3=INT(X/100)&&

IF X=X1^3+X2^3+X3^3

? X

ENDIF

ENDFOR


4051024

722

722 717


4051024

7.6.3

SCAN-ENDSCAN

SCAN [<>] [ FOR | WHILE <> ]

<>

ENDSCAN

1

2<>ALL

718


4051024

CLEAR

CLOSE ALL

USE Zgjk

M=0&&0

W=0

SCAN

IF =""

M=M+1&&

ELSE

W=W+1&&

ENDIF

ENDSCAN

? "", M

? "", W


4051024

723

723 718


4051024

719

CLEAR

USE Zgjk

GZ=0&&0

SCANFOR =""&&

GZ = GZ +&&

ENDSCAN

? "",GZ


4051024

724

724 719


4051024

7.6.4

720

* FORENDFOR

CLEAR

FOR A=1 TO 9&&

FOR B=1 TO 9&&

C=A*B

?? STR(A,1)+"*"+STR(B,1)+"="+STR(C,2)+" "

ENDFOR&&

?&&

ENDFOR&&


4051024

724

724 720

7211~100


4051024

* 1100

CLEAR

FOR M=3 TO 100STEP 2

N=INT(SQRT(M)) &&M,SQRT(M)

FOR I=3 TO N&&

IF MOD(M,I)=0&&0MIMIM

EXIT&&

ENDIF

ENDFOR

IF I>N&&NII>NM

?? M

ENDIF

ENDFOR


4051024

726

726 721

722


4051024

*

CLEAR

STORE 0 TO A,B,C,D,E&&0

DO WHILE .T.&& .T.

ACCEPT "(031032)" TO BJ

USE &BJ&&USE 031USE 032

SCAN&&

DO CASE

CASE >=90

A=A+1

CASE >=80

B=B+1

CASE >=70

C=C+1

CASE >=60

D=D+1

OTHERWISE

E=E+1

ENDCASE

ENDSCAN

? "",A

? "",B

? "",C

? "",D

? "",E

WAIT "(Y/N)" TO YN

IF UPPER(YN)="N"

EXIT&&EXIT

ENDIF

?

ENDDO


4051024

727

727 722


  • Login