Foxpro Notes
Foxpro Notes
__________________________________________________________
FOXPRO
DBMS stand for Data Base Management System. In this system you can create files, reports, labels etc.
The database is the collection of records related to person. The DBMS packages are Dbase III plus,
Dbase IV, FoxBASE, FoxPro etc.
FoxPro is a database management system. It means that using this software we can handle the
data in different way. The activity include in DBMS system are
1] Create a database or format structure to store data.
2] Add records in database.
3] Modify records, Edit records.
4] Search particular records.
5] Arrange records in particular order (ascending or descending order).
6] Delete records
7] Delete Database or modify structure.
8] Prepare Reports and Labels.
The three important terms are
1] Field :- It is the unit or information related to person. Or it is a heading of column in database.
2] Record :- It is the collection of fields or a complete row of table is called record.
3] Database :- The collection of records is called file.
In FoxPro there are different data types are available. These are
1] Character :- Allowed alphabets (A to Z, a to z) number (0 to 9) and special character and space.
2] Numeric :- Allowed digits (0 to 9) and decimal point also contain + or - sign.
3] Float :- Same as Numeric.
4] Date:- the date data type use to define or enter date value.
5] Memo :- The memo data type is same as character data type having unlimited width.
6] General :- it is use for OLE object.
2] Use Command:
This command is use to open an existing file and also to close current file.
Syntax :- Use [File name]
e.g. to open data file
Use Data
_______________________________________________________
Page no.:- 1 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
3] Append
This command is use to add new records
Syntax
Append [blank]
[from <filename>]
[filed <field list>]
[for <expL>]
e.g.
1] to add records in append window
use data
Append
2] To add blank record without opening append window
append blank
3] To add new records in a current file from file name "student"
append from student
4] To add only though records having city "shegaon" of "student" file
append from student for city = "shegaon"
4] Browse: This command is most popular or useful in FoxPro which let you to add new records, delete
records or modify records in browse window.
Syntax:-
Browse [Scope]
[Fields <fieldlist>]
[For <expL>]
[While<expL>]
[noappend] [nomodify]
[nodelte] [noedit]
e.g
1] To open browse window
Browse
2] To browse only fields Title author and cost only
browse fields Title,Author,Cost
3] To browse only records having cost greater than 300
browse all for cost >300
4] To browse records but not able to add, modify or delete records in browse window
browse all noappend nodelete nomodify
5] List :- this command use to list reocrds on screen, file or to send out put to printer
Syntax:- List [off] [scope]
[field <field list>]
[for<expL>]
[While<expL>]
e.g.
1] To list all records
list
2] To list records without record number
List off
3] To list record only 1 to 3
go top
list next 3
4] To list only fields title and cost
List fields title,cost
5] To list only record of author E. Balguruswami
List all for author="E.balguruswami"
6] To list only title and author of title FoxPro
List fields title, author for title = "FoxPro"
5] Display :- this command use to Display reocrds on screen, file or to send out put to printer
Syntax:-
Display [off] [scope]
[field <field list>]
[for<expL>]
_______________________________________________________
Page no.:- 2 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
[While<expL>]
e.g.
Display: to display only current record
To Display all records
Display all
8] Pack:- This command is use to delete records permanently marked for delete.
Syntax:- Pack
e.g. delete all record.
_______________________________________________________
Page no.:- 3 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
use stud & pack
9] Zap:- This command is use to delete all record permanently of currently
open .dbf file.
e.g
To delete all record of data file
use data
zap
10] Go to:- This command lets you to move record pointer in a dbf file.
Syntax:-
e.g
use stud
goto 3
11] Locate :- This command is use to search the record sequentially that matches given expression.
Locate sequentially search the current table for the first record that matches a logical expression. The
table doesn't have to be indexed.
If locate find the record it display it's Record no else place the record pointer to EOF.
Syntax:-
Locate [scope]
For <expL>
[While<expL>]
e.g
To locate records having city shegaon
use stud
Locate all for city = "shegaon"
12] Continue :- Continue command is used after LOCATE succeeds in finding a record, to continue the
LOCATE operation. CONTINUE moves the record pointer to the next record for which the logical
expression specified in the previous LOCATE evaluates to true <.T.>
13] SORT :- Sort command sort the current table and outputs the sorted data to a new table.
Syntax:-
SORT TO <file> ON <field1> [/A | /D] ,
<field2> [/A | /D]
[ascending] [descending]
[scope]
[for <expL>]
[while<expL>]
To sort the current table on field name and store it to temp table but in descending order
Use stud
Sort to temp on name desc
_______________________________________________________
Page no.:- 4 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
14] Index:- This command is used to arrange the records in ascending or descending order. There are
two types of indexing compound indexing (.cdx) containing multiple entries called tag and simple index
(idx) containing single index entry.
Syntax
Index on <field exp>
[to <idx file>]/[tag <tag name>]
[for <expL>]
[compact] [ascending | descending]
<field exp> : include fields on which you want to index file (not allowed different data type fields if u
want to use then first convert its data type using function.)
e.g
use lib
index on name,dtoc(dofp) tag a additive
for <expL> Only records that satisfy the filter expression <expL> are available for display and
access.
Compact create a compact .idx file.
ASCENDING | DESCENDING .cdx files can be built in ascending or descending order. By default
tag are created in ascending order.
e.g
to index file on name in ascending order
use abc
index on name tag a
16] SEEK:- SEEK command is similar to FIND search record in index table. In
this expression is allowed.
e.g.
use lib
index on cost tag a
c=234
seek c
_______________________________________________________
Page no.:- 6 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
q) SET FILTER TO
Specifies a condition for the current database file. This display only those records which satisfied
the given condition.
e.g.
use stud
set filter to course=”ADCSSAA”
browse
tip:- to remove the filter give command SET FILTER TO ALL
r) SET INDEX TO
Open one or more index files for use with current database file. You can open both .IDX or
.CDX files with this command.
e.g.
use stud
index on name to name
index on rollno to roll
set index to name
s) SET ORDER TO
Select a specified index file or tag as the controlling index file/tag for the current or specified
file.
e.g.
use stud
index on name tag name
index on rollno tag roll
set order to name
u) SET RELATION TO
Create the relation with more than one file using this command.
e.g.
suppose the two files are created with name & fields as
emp_c emp_v
code code
name post
dob salary
doj city
tip:- you must remember that you must take one filed comman in both file. Here is code.
Now set the relation as:-
select 1
use emp_c
index on code to code
select 2
_______________________________________________________
Page no.:- 7 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
use emp_v
index on code to code1
select 1
set relation to code into emp_v
browse fields code,name,emp_v.post,emp_v.salary
w) SET PROCEDURE TO
Opens the procedure file. Only one procedure file is opened at time.
DATE FUNCTIONS
1) DATE():- Returns the current system date, which is controlled by the operating
system.
Syntax & e.g. :-
?DATE( )
Returns date:-
02/14/01
tip:- if century is on then year displayed in yyyy format.
2) DAY() :- Returns the numeric day of the month for a given date expression.
DAY( ) returns a number from 1 through 31.
Syntax :-
DAY(<expD>)
e.g. ?DAY({01/11/99})
Returns value :- 10
5) DOW():- Returns the numeric day of week from given date expression.
The value returned by DOW( ) ranges from 1 (Sunday) through 7 (Saturday).
Syntax:-
DOW(<expD>)
e.g. ?DOW({date())
return value :- 1.
e.g. ?Dow({02/14/2001})
Return value :- 4
6) CDOW():- Return the character day of week from given date expression.
Syntax:-
CDOW(<expD>)
e.g. ?CDOW({02/14/2001})
Return :- Wednesday
7) YEAR():- Return the year from given date expression. SET CENTURY ON/OFF
command will not affect this function it always displayed in YYYY format.
Syntax:-
YEAR(<expD>)
e.g. ?YEAR({01/01/99})
Return:- 1999
_______________________________________________________
Page no.:- 8 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
11) DMY():- Returns a specified date expression in Day Month Year format.
Syntax:- DMY(<expD>)
e.g. ?DMY({02/10/2001})
Returns:- 10 February 01
Tip:- if SET CENTURY OFF then year displayed in yy format otherwise in YYYY format.
12) MDY():- Returns the specified date expression in Month Day Year format.
Syntax :- MDY(<expD>)
e.g. ?MDY({02/14/2001})
Returns:- February 14, 2001
NUMERIC FUNCTIONS
4) ASIN():- This trigonometric function returns in radians the arc sine of the numeric
expression <expN>.
Syntax :- ASIN(<expN>)
e.g. ?ASIN(-1)
Returns:- -1.57
Tip:-The value of <expN> can range from +1 through -1, and the value returned by ASIN( ) can range from -pi/2
through +pi/2 ( -1.57079 to 1.57079).
5) ATAN():- This trigonometric function returns in radians the arc tangent of a numeric
expression.
Syntax :- ATAN(<expN>)
e.g. ?ATAN(1.3)
Returns:- 0.92
Tip:- the value returned by ATAN( ) can range from -pi/2 through +pi/2 ( -1.57079 to 1.57079). The numeric
value returned by ATAN( ) is in radians.
_______________________________________________________
Page no.:- 9 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
Syntax:- COS(<expN>)
e.g. ?cos(45)
Returns.53
Tip:-the value returned by COS( ) ranges between -1 and 1. <expN> is given in radians.
7) DTOR():- Converts the value of a numeric expression given in degrees to an
equivalent value in radians.
Syntax :- DTOR(<expN>)
e.g. ?DTOR(180)
Returns:- 3.14
8) EXP() :- Returns the value of e^x where x is a specified numeric expression.
The value of e, the base of natural logarithms, is approximately 2.71828.
Syntax:- EXP(<expN>)
e.g. ?EXP(2)
Returns:- 7.39
9) FLOOR():- Returns the nearest integer that is less than or equal to the specified
numeric expression.
Syntax:- FLOOR(<expN>)
e.g:- ?FLOOR(19,90)
Returns:- 19
e.g. ?FLOOR(-19.99)
Return:- -20
TIPS:- FLOOR( ) rounds a positive number with a fractional portion down to the integer portion of the number,
and rounds a negative number with a fractional portion down to the next lowest integer.
10) INT():- Evaluates a numeric expression and returns the integer portion of the
expression.
Syntax :- INT(<expN>)
e.g. :- ?INT(20.99)
Returns:- 19
11) MAX():- Returns the expression with the highest ASCII or numeric value or the
latest date from a list of character, numeric or date expressions.
Syntax :- MAX(<expr1>, <expr2>[, <expr3> ... ])
e.g. ?max(12,22,10)
Returns:- 22
12) MIN():- Returns the expression with the lowest ASCII or numeric value or the
earliest date in a list of character, numeric or date expressions.
Syntax :- MIN(<expr1>, <expr2>[, <expr3> ...])
e.g. ?min(10,9,8)
Returns:- 8
15) SQRT():- Returns the square root of the specified numeric expression.
Syntax :- SQRT(<expN>)
e.g. ?SQRT(121)
Return :- 11
16) VAL():- Returns a numeric expression from a specified character expression
composed of numbers.
Syntax:- VAL(<expC>)
e.g. a=’12’
?VAL(a)
Return:- 12.00
_______________________________________________________
Page no.:- 10 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
CHARACTER FUNCTIONS
1) ALLTRIM():- Returns the specified character expression with leading and trailing
blanks removed.
Syntax:- ALLTRIM(<expC>)
e.g. ?’”HELLO FRIEND”,ALLTRIM(“ THIS IS TEST “,” example”
Return:- HELLO FRIEND THIS IS TEST example.
Tip:- ALLTRIM( ) removes leading and trailing blanks from the specified character expression and returns the
trimmed expression as a character string.
2) ASC():- Returns the ASCII code for the leftmost character in a character expression.
Syntax :- ASC(<expC>)
e.g. ?ASC(‘a’)
Returns:- 97
Tip:-Every character has a unique ASCII value in the range from 0 to 255.
3) AT():- Returns the beginning numeric position of the first occurrence of a character
expression or field within another character expression or field, counting from the leftmost character.
Syntax:- AT(<expC1>, <expC2>[, <expN>])
Here ,<expC1> - is the character whose position you want to see.
<expC2)- is the text in which you want to search.
<expN>- is the number of occurrence.
e.g.:- ?at(‘A’,’DATA POINT’,2)
Return:- 4
4) CHR():- Returns the character associated with the specified numeric ASCII code.
Syntax :- CHR(<expN>)
e.g. ?CHR(97)
Return:- a
5) ISALPHA():- Returns true (.T.) if the leftmost character in the specified character
expression is an alphabetic character; otherwise, false (.F.) is returned.
Syntax :- ISALPHA(<expC>)
e.g. ?ISALPHA(“12data point”)
Returns:- .F.
7) ISDIGIT():- Returns true (.T.) if the leftmost character of the specified character
expression is a digit (09); otherwise, false (.F.) is returned.
Syntax:- ISDIGIT(<expC>)
e.g. ?ISDIGIT(“12 data “)
Return:- .T.
8) ISLOWER():- Returns true (.T.) if the leftmost character in the specified character
expression is a lower-case alphabetic character.
Syntax :- ISLOWER(<expC>)
e.g. ?ISLOWER(“DATA POIN”)
Return:- .F.
_______________________________________________________
Page no.:- 11 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
e.g. ?LOWER(“DATA POINT”)
Return:- data point
13) LTRIM():- Returns the specified character expression with leading blanks removed.
Syntax :- LTRIM(<expC>)
e.g. ?’FoxPro programming is easy‘,LTRIM(“ friends”)
Return:- FoxPro programming is easy friends”)
15) RIGHT():- Returns the specified number of rightmost characters from a character
string.
Syntax :- RIGHT(<expC>, <expN>)
e.g. ?RIGHT(“data point”,3)
Return:- int
16) RTRIM():- Returns the specified character expression with all trailing blanks
removed.
Syntax:- RTRIM(<expC>)
e.g. :- ?”HELLO FRIENDS” ,RTRIM(“WEL-COME “),” TO LEARN” FOXPRO””
Return:- HELLO FRIEND WEL-COME TO LEARN
18) SUBSTR():- Returns a specified number of characters from the given character
expression or field.
Syntax:- SUBSTR(<expC>, <expN1>[, <expN2>])
. e.g. ?SUBSTR(“Foxpro is DBMS package”,11,4)
Return:- DBMS
Here, <expC> :- The character expression from which characters are extracted is .
<expN1> :- starting position of character , where character extraction be
begins.
<expN2>:- specifies the number of characters to be extract from the
character expression.
19) TRIM():- Returns the specified character expression with all trailing blanks
removed. TRIM( ) is identical to RTRIM( ).
Syntax:- TRIM(<expC>)
e.g. :- ?"HELLO FRIENDS" ,TRIM("WEL-COME ")," TO LEARN"
Return:- HELLO FRIENDS WEL-COME TO LEARN
_______________________________________________________
Page no.:- 13 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
[FILL <expC6> | FILL FILE <bmp file>]
12) SCAN…ENDSCAN:- Moves the record pointer through the current table/.DBF and
executes a block of commands for each record that meets the specified conditions.
Syntax:-
SCAN
[<scope>]
[FOR <expL1>]
[WHILE <expL2>]
[<statements>]
[LOOP]
[EXIT]
ENDSCAN
13) DO CASE…. ENDCASE:- Executes the first statement block after DO CASE and
before END CASE whose associated conditional statement evaluates to true (.T.).
Syntax:-
DO CASE
CASE <expL1>
<statements>
[CASE <expL2>
<statements>
...
CASE <expLN>
<statements>]
[OTHERWISE
<statements>]
ENDCASE
16) FOR…ENDFOR:- Executes the commands after FOR and before ENDFOR within
a loop a specified number of times.
_______________________________________________________
Page no.:- 14 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
Syntax:-
FOR <memvar> = <expN1> TO <expN2> [STEP <expN3>]
<statements>
[EXIT]
[LOOP]
ENDFOR | NEXT
e.g.
FOR mcount = 1 TO 10
? mcount
ENDFOR
19) INPUT:- Inputs data from the keyboard into a system memory variable or an array
element.
Syntax:-
INPUT [<expC>] TO <memvar>
e.g. Input “Enter Number A” To A
?A
22) READ:- Activates objects created with @ ... GET and @ ... EDIT commands.
_______________________________________________________
Page no.:- 15 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
Syntax:-
@ <row, column> SAY <expr>
[FUNCTION <expC1>]
[PICTURE <expC2>]
[SIZE <expN1>, <expN2>]
[FONT <expC3>[, <expN3]]
[STYLE <expC4>]
e.g. @12,2 say “WEL-COME TO DATA POINT” style “BI”
24) @…GET –(Check Box):- You can create the control buttons. To create check box
you required the numeric variable
Syntax:- @<row>,<col> get mvariable FUNCTION “*C <titleof button>”
e.g. STORE 0 TO CH
@3,4 GET CH FUNCTION “*C ADD”
Return:- ADD
Tip:- you can use PICTURE insteade of FUNCTION like @3,3 get ch PICTURE “@*C ADD” the value of
check box is 1 when it is checked otherwise 0. to define hot key “/<” sign is used before the charcter.
27) @…GET-(Popup):- To create the popup control you need numeric or character
variable. You use ^ symbol as the function code or @^ as picture code.
Syntax:- :- @<row>,<col> get mvariable FUNCTION “^ <title>;<title>;..”
e.g. STORE 0 TO CH
@3,4 GET CH FUNCTION “^Graduate;MBA;BA”
tip:- to activate the check box,radio buttion,popup,push button READ or READ CYCLE
command is used.
30) ON PAD :- Specifies the menu popup or menu bar that is activated when you choose
a specific menu pad.
Syntax:- ON PAD <pad name> OF<menu name1>
[ACTIVATE POPUP <popup name>| ACTIVATE MENU <menu name2>]
31) ON SELECTION PAD :- Specifies a command that execute when you choose a
specific menu bar pad.
Syntax:- ON SELECTION PAD <pad name> OF <menu name>
_______________________________________________________
Page no.:- 16 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
Memo field used to store the long textual information. Suppose we considered that you need to create a
dbf having information as book_name, authour_name, & book_summary. Here we store
book_name,authour_name in character field, but we can’t use the character field for summary, because character
field can’t be wider than 254 character. So you use the MEMO
field for storing the summary.
When a memo field used with in database file ,the actual information in memo field stored in auxiliary
database file. Foxpro automatically create the auxiliary file (.fpt) when you create the memo field in dbf.
For example if you create a database file like data.dbf having memo field foxpro create two files data.dbf
& data.fpt which is auxiliary file.
ADVANTAGE of MEMO FIELD:-
A memo field occupies only 10 bytes of space in database record. You
can store any amount of text for each record.
As actual data for the memo field stored in auxiliary file, the size of main dbf
Reduced.
_______________________________________________________
Page no.:- 17 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
Now you will see the format on your window.
CREATING LABEL:-
Foxpro provid another facility for desiging & printing the mailing label. The extension of .LBX
To create label format file CREATE LABEL command is used. When you create label you must
open the dbf file for which you create the label.
Steps:-
1. Open the database file as USE EMPLOYEE
2. Then give the command CREATE LABEL EMPL
3. It display the window here the default size is 3 ½” X 15/16” X 2 you can also change it manually.
4. then move the cursor to the WIDTH & give the width .
5. move cursor to Number Across- it menas how many labels placed in one row .
6. move cursor to Space Between – it indicate that how many space left between the labels.
7. move cursor the Lines Between- it indicate that the vertical distance between two label.
8. you can set the height of label.
9. to entered the field expression press ^F it display the box select the field & press ^W.
10. In this way you can add number of fields in label , if you add the self text/prompting then type the
text in “ ” symbol.like "Name:-".
11. Then to see the preview press ^I. To save the label press ^W.
_______________________________________________________
Page no.:- 19 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
EXIT LOOP
There is another way to terminate the loop using LOOP is another statement used
EXIT command within DO WHILE …ENDDO
statement. When foxpro encountered the EXIT
in DO WHILE ..ENDDO
command ,no more commands from the loop is statement. LOOP is specified
executed. It exit the loop & executed the statement within IF …ENDIF. When foxpro
next to the ENDDO statement. The EXIT command encountered the LOOP
is normally used in IF …ENDIF statement. command,the control pass to the
DO WHILE statement,the
For e.g. remaining commands( upto
For e.g. ENDDO ) can’t executed. It again
Store 0 to x,sum,y check
store the condition & execute
0 to x,y,sum
Do while x<=5 Do while x<=5
Input “Enter No.” to y Input “Enter The No.” to y
If y<0 If y<0
Exit LOOP
Else else
Sum=sum+y sum=sum+y
Endif endif
X=x+1 x=x+1
?’sum of no. is’,sum ?’sum of no. is’,sum
_______________________________________________________
Page no.:- 20 SST
Notes for foxpro Data Point ,Shegaon
__________________________________________________________
SCAN …ENDSCAN:-Moves the record pointerthrough the current DBF file & execute the
block of commands for each record that meets the specified condition.
Syntax:-
SCAN [SCOPE]
[FOR <expL>]
[LOOP]
[EXIT]
ENDSCAN
For e.g.
USE address
ACCEPT “ENTER CITY:-“ TO MCITY
SCAN FOR CITY=MCITY
?NAME
?CITY
?DIST
?
ENDSCAN
What is TEXT-ENDTEXT?
When you need to display the text use ?/?? instead of this you can use TEXT-ENDTEXT to
display long message. You don’t require to use quotations ,you can type several lines. You can also print
the text on PRINTER.
For e.g.
@2,1 say “Display The menu”
TEXT
1 Add Record
2 Modify Record
3 Delete Record
4 Exit
ENDTEXT
The above command display the matter on screen from text..endtext.
_______________________________________________________
Page no.:- 22 SST