26
1 Revision on Foxpro Commands Print command (?) e.g. ? 6/2 * 3 9 SET DECIMAL TO integer e.g. SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g. ? SET (‘DECIMAL’) 4

1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

Embed Size (px)

Citation preview

Page 1: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

1

Revision on Foxpro CommandsPrint command (?)

e.g. ? 6/2 * 3

9

SET DECIMAL TO integer

e.g. SET DECIMAL TO 4

? 2 / 3

0.6667

SET( ) function

e.g. ? SET (‘DECIMAL’)

4

Page 2: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

2

SET FIXED ON|OFF

e.g. SET DECIMAL TO 3

SET FIXED ON

? 3 * 2

6.000

+ , - , * , / , ^ , % mathematical operators

e.g. ? -7^2

49.00

? -14%4 or ? MOD(-14,4)

2

Page 3: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

3

+ concatenation, - concatenation

e.g. ? ‘Chan ‘ + ‘Tai ’ - ‘Man’

Chan TaiMan

SET CENTURY ON|OFF

e.g. ? {12/20/1999} + 30

01/19/00

SET CENTURY ON

? {12/20/1999} + 30

01/19/2000

Page 4: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

4

SET CENTURY TO

e.g. SET CENTURY TO 19 ROLLOVER 50

SET CENTURY ON

? {12/24/20}

12/24/2020

? {12/24/65}

12/24/1965

SET (‘CENTURY’)

e.g. ? SET (‘CENTURY’)

ON

Page 5: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

5

SET DATE TO (DMY|MDY|YM)

DATE ( ) system date function

e.g. SET DATE TO DMY

? DATE( )

25/12/99

=, !=or<>or #, <, >, <=, >=, = = relational operators

SET EXACT ON|OFF

e.g. ? ‘123’ = ‘12’

.T.

? ‘123’ = = ‘12’

.F.

Page 6: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

6

e.g. SET EXACT ON

? ‘123’ = ‘12’

.F.

SET (‘EXACT’)

ON

SUBSTRING ($) operator

e.g. ? ‘an’ $ ‘Chan’

.T.

e.g. STORE ‘Hello’ TO x ? x

Hello

Page 7: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

7

?? Print Command

e.g. ? ‘Hello!’

?? ‘Hi!’

? ‘How are you?’

Hello!Hi!

How are you?

LEN ( ) ~ returns the number of characters

e.g. ? LEN(‘How are you?’)

12

Page 8: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

8

UPPER ( ), LOWER ( )

e.g. ? LOWER(‘Chan Tai Man’)

chan tai man

? UPPER(‘Chan Tai Man’)

CHAN TAI MAN

SPACE ( )

e.g. ? ‘Hello!’+SPACE(3)+’Hi!’

Hello! Hi!

Page 9: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

9

LTRIM( ), RTRIM( ) / TRIM( ), ALLTRIM( )

e.g. X=‘ Hello! Hi! ’

? LTRIM(X)

Hello! Hi! (with trailing spaces)

? RTRIM(X)

Hello! Hi!

? ALLTRIM(X)

Hello! Hi!

LEFT( ), RIGHT( )

e.g. ? LEFT(RIGHT(‘How are you?’, 8), 3)

are

Page 10: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

10

SUBSTR( ) ~ returns specified numbers of characters

e.g. ? SUBSTR(‘How are you?’, 2, 4)

ow a

STUFF( ) ~ returns a string with certain replaced char

e.g. ? STUFF (‘How are you?’, 1, 3, ‘Who’)

Who are you

AT( )

e.g. ? AT(‘o’,’How are you?’)

2

Page 11: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

11

VAL( ) ~ converts string to numeric value

e.g. ? VAL(‘2’)+VAL(‘3’)

5.00

? VAL(‘-1234E-3’)

-1.234

STR( ) ~ converts numeric value to string

e.g. ? STR(1234.567,7,2)

1234.57

? STR(1234.567,3,2)

***

Page 12: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

12

ASC( ), CHR( )

e.g. ? ASC(‘APPLE’)

65

? CHR(66)

‘B’

ROUND( ), INT( )

e.g. ? ROUND(-123.456,2)

123.46

? INT(-456.789)

456

Page 13: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

13

ABS( )

e.g. ? ABS(-12.34)

12.34

FLOOR( ), CEILING( )

e.g. ? FLOOR (123.4)

123

? CEILING(123.4)

124

? CEILING(-123.4)

-123

Page 14: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

14

SQRT( )

e.g. ? SQRT(16.000000)

4.000000

DAY ( ), MONTH( ), YEAR( )

e.g. ? DAY ({12/25/2000})

25

? MONTH({12/25/2000})

12

? YEAR({12/25/02})

2002

Page 15: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

15

DOW( ), CDOW( ), CMONTH( )

e.g. ? DOW({01/01/2000})

7

? CDOW({01/01/2000})

Saturday

? CDOW({02/30/2000})

*bad date*

? CMONTH ({12/25/2000})

December

Page 16: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

16

CTOD( ) ~ converts string to date expression

e.g. ? CTOD(‘02/29/2000’)

02/29/2000

DTOC( ) ~ converts date expression to string

e.g. ? DTOC ({12/25/2000})

12/25/2000

IIF( ) function

e.g. mark=65

? IIF(mark>=50, ‘passed’, ‘failed’)

passed

Page 17: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

17

CREATE <dbf file> ~ create a table

USE <dbf file> ~ open a table

USE ~ close a table

CLOSE DATABASES ~close all opened tables

CLOSE ALL ~ close all tables and windows

MODIFY STRUCTURE ~ design table structure

SET DEFAULT TO <drive letter>

SET PATH TO <path>

e.g. SET DEFAULT TO a:

SET PATH TO a:\trading

Page 18: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

18

LIST

LIST FIELDS <fieldName,…>

LIST FIELDS <fieldName,…>FOR<condition>

LIST [FIELDS ……] [ FOR… …] [TO PRINT]

BROWSE

BROWSE FIELDS <fieldName,…>

BROWSE FIELDS <fieldName :R,...>

BROWSE FIELDS …… FOR <condition>

BROWSE FIELDS…… FOR…… NOEDIT

BROWSE [FIELDS [:R],…] [FOR…] [NOEDIT]

Page 19: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

19

EDIT

EDIT FIELDS <fieldName,…>

EDIT FIELDS <fieldName :R,...>

EDIT FIELDS …… FOR <condition>

EDIT [FIELDS [:R],…...] [FOR…...]

DIR <drive letter> ~ view the names of tables

DISPLAY STATUS

GO/GOTO <record number>

GOTO TOP, GOTO BOTTOM

Page 20: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

20

BOF( ) & EOF( ) functions ~ check whether the record pointer is at the beginning or at the end

e.g. GOTO TOP

? BOF( )

.F.

SKIP -1

? BOF ( )

.T.

GOTO BOTTOM SKIP 1

? EOF( )

.T.

Page 21: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

21

RECNO( ) ~ returns the record number of the current record

RECCOUNT( ) ~ returns the total number of records

SET FIELDS TO <fieldName>, … | ALL

~ restricts access to specified fields only

e.g. SET FIELDS TO name, class, class_no

SET FILTER TO <condition>

~ restricts access to specified rows only

e.g. SET FILTER TO class=‘3A’ AND mark>0

Page 22: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

22

REPLACE <fieldName> WITH <expression>,... ~ replace the data of certain fields

REPLACE … WITH … [ADDITIVE]

~ append text to memo field

REPLACE … WITH … [FOR <condition>]

REPLACE … WITH … [ALL]

e.g. REPLACE term WITH ‘1’,;

mark WITH (test+exam)/2 ;

FOR class=‘6S’

Page 23: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

23

BLANK ~ clears all fields of the current record

BLANK [FIELDS <fieldName>,...] [ALL]

BLANK [FIELDS…] [ALL] [FOR <condition>]

e.g. BLANK FIELDS mark,conduct FOR term=‘2’

APPEND

APPEND BLANK

APPEND FROM <table> FIELDS <fieldNames>

APPEND FROM…FIELDS…[FOR <condition>]

e.g. USE class6A

APPEND FROM class6S FIELDS name;

FOR sex=‘M’

Page 24: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

24

APPEND FROM … FIELDS TYPE DELIMITEDAPPEND FROM … FIELDS TYPE SDFe.g. of delimited file“Peter”, “M”, 14, 60“Paul”, “M”, 13, 62“Mary”, “F”, 15, 61e.g. of SDF filePeter M 14 60Paul M 13 62Mary F 15 61DELETE [ALL]DELETE FOR <condition>e.g. DELETE FOR leave=“Y”SET DELETE ON/OFFRECALL ALL

Page 25: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

25

DELETED( ) ~ returns boolean to indicate whether the current record is marked as deletedPACK ~ kills all records marked as deletedDELETE ALL + PACK = ZAPCOPY FILE <table1> TO <table2>COPY TO <table> [FIELDS <fieldName>,…]COPY TO … [FIELDS …] [FOR <condition>]e.g. USE class6S

COPY TO pass_6S FIELDS name, mark;FOR mark>=40

COPY TO … TYPE DELIMITEDCOPY TO … TYPE SDFCOPY STRUCTURE TO ... [FIELDS…]~ copy the fields structure to a new table

Page 26: 1 Revision on Foxpro Commands Print command (?) e.g.? 6/2 * 3 9 SET DECIMAL TO integer e.g.SET DECIMAL TO 4 ? 2 / 3 0.6667 SET( ) function e.g.? SET (‘DECIMAL’)

26

TOTAL TO <table> ON <field> FIELDS <fieldList>

e.g. MARK.DBF

Subject Grade QtyMath A 2Math B 1Eng A 3Eng C 4

e.g. TOTAL TO stat ON subject FIELDS qty

USE stat

BROW

Subject Grade QtyMath A 3Eng A 7