Foxpro Programming: What Is Data?
Foxpro Programming: What Is Data?
Foxpro Programming: What Is Data?
FoxPro Programming
What is Data? Data can be anything like a name of person rollno of student or name of
a city.
What is Information? When Data is in meaning full way or related with each other its called
Information.
What is DBMS? DBMS stands for Database Management System. The system which
collect data from user and manage that data properly, is called
Database Management system.
What is RDBMS? RDBMS stands for Relational Database Management System. RDBMS
is advance feature of DBMS. RDBMS provide the facility to create a
relation between two tables.
What is FILE ?:- In FoxPro File is a collection of records and fields. Row represent
record and column represent field.
What is RECORD ?:- Data is stored in one horizontal line of database is called record. In
other words Record is a collection values in fields of table.
What is FIELD ?:- Field is a basic part of any database column is also called field but in a
perfect way Field is a collection of data of same type and nature.
What is Col. Width? The number of digit you specify with each fieldname is called column
width.
DBMS RDBMS
1. DBMS stands for 1. RDBMS stands for
Database Management System. Relational Database Management System.
2. In DBMS we cannot create relation 2. RDBMS provide facility to create relation
between two tables. between two tables.
3. DBMS may satisfy less than 7 to 8 rules of 3. DBMS may satisfy more than 7 to 8 rules of
Dr.E.F.Codd. Dr.E.F.Codd.
4. In DBMS there is no security of data. 4. In RDBMS there are multilevel of security.
(1) Logging in at o/s Level (2) Command Level
(3) Object Level
5. Each table is given extension of DBMS 5. Many tables are grouped in one database in
RDBMS.
6. DBMS use a 3GL. 6. DBMS use a 4GL.
7. Ex. of DBMS are Dbase, FoxBASE, Foxpro 7. Ex. of RDBMS is Oracle, Access, SQL server.
7. General :-
General field is use only for FoxPro for window version. In general field we can store textual
data, picture, sound etc.
Note :- In FoxPro picture field type is not used.
Functions of FoxPro
1. Numeric Function 2. String Function
3. Date & Time Function 4. Array Function
1. Numeric Function:-
(1) Abs():- This function returns the absolute value of the specified numeric expression.
Syntax : Abs(<expN>)
Function Returns : Numeric
Example : Abs(-25)
Output : 25
(2) Int():- This function returns the Ineger value from the specified numeric expression.
Syntax :- Int(<expN>)
Function Returns :- Numeric
Example :- Int(25.25)
Output :- 25
(3) Floor():- This function returns the nearest integer value that is less than or equal to the
specified numeric expression.
Syntax : Floor(<expN>)
Function Returns : Numeric
Example : Floor(51.85)
Output : 51
(4) Ceil():- This function returns the nearest integer value that is greater than or equal to the
specified expression.
Syntax:- Ceil(<expN>)
Function Returns:- Numeric
Example:- Ceil(27.35)
Output:- 28
(5) Mod():- This function returns the remainder value by moduling expression1 to expression2.
Syntax :- Mod(<expN1>,<expN2>)
Function Returns :- Numeric
Example :- Mod(5,2)
Output :- 1
(6) Round():- This function Return a numeric expression rounded to a specified number of decimal
places.
Syntax:- Round(<expN1>,<expN2>)
Function Returns:- Numeric
Example:- Round(25.49) Round(25.51)
Output:- 25 26
(7) Min():- This function 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(<expN1>,<expN2>[<expN>……])
Function Returns:- Numeric,date,Character
Example:- Min(10,20,5,85,50)
Output:- 5
(8) 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(<expN1>,<expN2>[<expN>……])
Function Returns:- Numeric,date,Character
Example:- Min(10,20,5,85,50)
Output:- 85
(9) Sqrt():- This function Return the square root of specified expression.
Syntax:- Sqrt(<expN1>)
Function Returns:- Numeric
Example:- Sqrt(25)
Output:- 5
(10) Log():- This function Return the simple natural loqarism value of specified numeric expression.
Syntax:- Log(<expN>)
Function Returns:- Numeric
Example:- Log(10)
Output:- 2.30
(11) Log10():- This function Return the simple natural log base10 value of specified numeric exp.
Syntax:- Log10(<expN>)
Function Returns:- Numeric
Example:- Log10(10)
Output:- 1.00
2.Array Function:-
(1) Asort():- This function is use to Sorts elements in an array in ascending or descending order.
Syntax:- ASORT(<array>[, <expN1>[, <expN2>[, <expN3>]]])
Function Returns:- Numeric
All elements included in the sort must be of the same data type (character, numeric, date or logical).
One-dimensional arrays are sorted by their elements; two-dimensional arrays are sorted by their
rows. When a two-dimensional array is sorted, the order of the rows in the array is changed so the
elements in a column of the array are in ascending or descending order.If the sort is successful, 1 is
returned; otherwise -1 is returned.<array> specify the name of array memory Vriable. <expn1>
specifies the starting element number from where to start sorting,<expn2>specifies the number of
array how many records are to be sorting,<expn3>specifies sorting order(0 for ascending order and 1
for descending).
Example : declare m1[4]={'c','b','d','a'}
?asort(m1,1,4,1)
Output : 1
(2) Alen():- This function Returns the number of elements, rows or columns in an array.
Syntax:- ALEN(<array>[, <expN>])
Function Returns:- Numeric
<array> If you include only the array name <array>, ALEN( ) returns the number of elements in the
array. <expN> can be 0, 1 or 2. If <expN> is 0 function returns the total no.of element if the <expN> is
1 function returns the total no.of rows in an array and if the <expN> is 2 returns the total no.of column
in an array.<expN>is use when array is two dimensional.
Example:- declare m1[4]={'c','b','d','a'}
?Alen(m1)
Output:- 4
Example:- declare m2[2,5] declare m2[2,5]
?Alen(m1,1) ?Alen(m1,2)
Output:- 2 5
(3) Aelement(): This function Returns the number of an array element from the element's
subscripts. This function is commenly used in two dimensional array.
Syntax:- AELEMENT(<array>, <expN1>[, <expN2>])
Function Returns:- Numeric
<array>Include the name of the array whose element number you want to return. <expN1> Specify
the row subscript with <expN1>. If the array is one-dimensional, AELEMENT() identically returns
<expN1>. <expN2> Specify the column subscript with <expN2>. If the array is two-dimensional,
include both <expN1> and <expN2>. If you include just <expN1>, the element number is returned
(5) Acopy(): This function is use to Copies elements from one array to another array.This function
returns the number of elements copied to the destination array.
Syntax:- ACOPY(<array1>, <array2>[, <expN1>[, <expN2>[,<expN3>]]])
Function Returns:- Numeric
(2) Year():- Year function returns the numeric year from the date expression.This function is
always display the year with century. Foxpro display the as set above in computer.
Syntax:- Year(<exprDate>)
Example:- ? Year(date())
Output:- 2008
Function returns: Numeric
(3)Month():- Month function returns the numeric month from the date expression. Foxpro display
the month as set above in computer.
Syntax:- Month(<exprDate>)
Example:- ? Month(date())
Output:- 1
Function returns: Numeric
(4)Cmonth():- Cmonth function returns the name of month in character from the date expression.
Foxpro display the monthname as set above in computer.
Syntax:- Cmonth(<exprDate>)
Example:- ? Cmonth(date())
Function returns: Character
Output:- January
(5)Day():- Day function returns the numeric day value from the date expression. Foxpro display
the day as set above in computer.
Syntax:- Day(<exprDate>)
Example:- ? Day(date())
Output:- 21
Function returns: Numeric
(6)CDOW():- CDOW means character day of week.This function returns the character day from the
date expression. Foxpro display the day as set above in computer.
Syntax:- CDOW(<exprDate>)
Example:- ? CDOW(date())
Output:- Monday
Function returns: Character
(7)DOW():- DOW means Day of Week. This function returns the Numeric day value from the date
expression. Foxpro display the day as set above in computer.(0 for Sunday and 6 for
Saturday)
Syntax:- DOW(<exprDate>)
Example:- ? DOW(date())
Output:- 1
Function returns: Numeric
(8) Gomonth():- Gomonth function Returns the date that is a specified number of months before or
after a given date.Foxpro display the day as set above in computer.
Syntax:- Gomonth(<exprDate>,<expN>)
Example:- ? Gomonth(date(),3)
Output:- 04/21/08
Function returns: Date
(9)DtoC():- DtoC means Date to character. This function is use to change date to char format.
Syntax:- DtoC(<exprDate>)
Example:- d1=date()
Disp memo like d1 (oputput:-d1 date ‘01/21/08’)
D1=DtoC(d1)
Disp memo like d1 (oputput:-d1 Character ‘01/21/08’)
Function returns:- Character
(10) CtoD():- CtoD means Character to Date. This function is use to change character type date in
date format.
Syntax:- CtoD(<expC>)
Example:- d1=’05/11/07’
Disp memo like d1 (oputput:-d1 Charater ‘05/11/07’)
D1=CtoD(d1)
Disp memo like d1 (oputput:-d1 Date ‘05/11/07’)
Function returns:- Date
(11) Time():- Time function always return the current time as set in computer. This function Returns
the current system time in 24-hour, eight-character string (HH:MM:SS) format. This
function is use to print the time of printout in reports.
Syntax:- Time()
Example:- ?Time()
Output:- 08:52:25
Function returns:- Character
(12) Second():- Second function always return the seconds that were passed between 12pm to
current time as set in computer.This function returns the value in floating point.
Syntax:- Second()
Example:- ?Second()
Output:- 32128.830
Function returns:- Numeric
(13)Sys(2):- Sys function always return the seconds that were passed between 12pm to current
time as set in computer.This function returns the value in Integer format.
Syntax:- Second()
Example:- ?Second()
Output:- 32128
Function returns:- Numeric
4. String Function:-
(1) Chr():- This function Returns the character associated with the specified numeric ASCII code.
Syntax:- Chr(<exp N>)
Example:- ?Second(65)
Output:- A
Function returns:- Character
(2) Asc():- This function Returns the ASCII code for the leftmost character in a character express
Syntax:- Asc(<exp C>)
Example:- ?Second(‘a’)
Output:- 97
Function returns:- Numeric
(3) Val():- This function Returns a numeric expression from a specified character expression
composed of numbers.
Syntax:- Val(<exp C>)
Example:- d1=”55”
Disp memo like d1 (oputput:-d1 Character ‘55’)
D1=val(d1)
Disp memo like d1 (oputput:-d1 Numeric 55 )
Function returns:- Numeric
(4) Str():- This function Returns the character string equivalent to a specified numeric express.
Syntax:- Str(<exp N>)
Example:- d1=55
Disp memo like d1 (oputput:-d1 Numeric 55 )
D1=Str(d1)
Disp memo like d1 (oputput:-d1 Character ‘55’)
Function returns:- Character
(5) Left:- This function Returns a specified number of characters from a character expression,
starting with the leftmost character.
Syntax:- Left(<exp C>,<exp N>)
Example:- ?Left(‘computer’,4)
Output:- comp
Function returns:- Character
(6) Right:- This function Returns the specified number of rightmost characters from a char string.
Syntax:- Right(<exp C>,<exp N>)
Example:- ?Right(‘computer’,4)
Output:- uter
Function returns:- Character
(7) Upper :- This function is use to convert specified character string in UPPERCASE format.
Syntax:- Upper(<exp C>)
Example:- ?Upper(‘computer’)
Output:- COMPUTER
Function returns:- Character
(8) Lower:- This function is use to convert specified character string in lowercase format.
Syntax:- Lower(<exp C>)
Example:- ?Lower(‘COMPUTER’)
Output:- computer
Function returns:- Character
(9) Proper:- This function is use to convert specified character string in Proper case format.
Syntax:- Proper(<exp C>)
Example:- ?Proper(‘this is a computer’)
Output:- This Is A Computer
Function returns:- Character
(17) Substr():- This function Returns a specified number of characters starting from specified
character to specified no.of character the given expressions.
Syntax:- Substr(<exp C>,<exp N1>[,<exp N2>])
Example:- ?Substr(‘computer’,1,5)
Output:- compu
Function returns:- Character
(18) Space():- This function Returns a character string composed of a specified number of spaces.
Syntax:- Space(<exp N1>)
Example:- ?Space(10)
Output:- [Ten blank space]
Function returns:- Character
(19) Version():- This function Returns a character string containing the FoxPro version number you
are using.
Syntax:- Version()
Example:- ?Version()
Output:- 2.6
Function returns:- Character
(21) Fsize():- This function Returns the size, in bytes, of a specified field.Before using this function
its necessary that the fieldsize that you want to know its database file must opened.
Syntax:- Fsize(<exp C>)
Example:- use student
?Fsize(“sname”)
Output:- 15
Function returns:- Numeric
(22) Fullpath():- This function Returns the fullpath of specified database file in expression.
Syntax:- Fullpath()
Example:- ?Fullpath(“student”)
Output:- c:\fpw26\student
Function returns:- Character
(23) Between():-This function checks if the expression1 is lies between two another expression of
same datatypes.This function returns true if it find else it return false.
Syntax:- Between(<exp R1>,<exp R2>,<exp R3>)
Example:- ?Between(5,2,10)
Output:- .t.
Function returns:- Logical
(24) Replicate():- This function Returns a character string that contains a specified character
expression repeated a specified number of times.
Syntax:- Replicate(<exp C>,<exp N>)
Example:- ?Replicate(‘*’,10)
Output:- **********
Function returns:- Character
(25) Inlist():- This function checks whether or not an expression matches one in a series of
expressions of the same data type. INLIST( ) returns true if it finds the expression in the set of
expressions. If it doesn't find the expression in the set of expressions, INLIST( ) returns false.
Syntax:- Inlist<expr1>, <expr2>[, <expr3> ...])
Example:- ?Inlist(5,10,15,25,35,45,5)
Output:- .t.
Function returns:- Logical
(26) Difference():- This function Returns an integer, 0 through 4, representing the relative phonetic
difference between two character expressions.
Syntax:- Difference(<exp C1>,<exp C2>)
Example:- ?Difference(“rush”,”rooos”)
Output:- 4
Function returns:- Numeric
(27) Padl():- This function Returns a character string from a character expression padded to a
specify length. This function insert padding in leftside.If you not specify padded character
computer padded by blank space.
Syntax:- Padl(<expr>, <expN>[, <expC>])
Example:- ?Padl(“Jay”,20,”_”)
Output:- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ jay
Function returns:- Character
(28) Padr():- This function Returns a character string from a character expression padded to a
specify length. This function insert padding in right side. If you not specify padded
character computer padded by blank space.
Syntax:- Padr(<expr>, <expN>[, <expC>])
Example:- ?Padr(“Jay”,20,”_”)
Output:- jay_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Function returns:- Character
(29) Padc():- This function Returns a character string from a character expression padded to a
specify length in center. This function insert padding in bothsize .If you not specify padded
character computer padded by blank space.
Syntax:- Padc(<expr>, <expN>[, <expC>])
Example:- ?Padl(“Jay”,20,”_”)
Output:- _ _ _ _ _ _ _ _ jay_ _ _ _ _ _ _ _ _
Function returns:- Character
Above example will create a new textfile name as my file and stores all the records of student
database file
Memory Variable
⇒ Memory variable is also know as a public variable.
Method of Creating Memory Variable:-
We can create memory variable by following three method.
Store:-
Syntax:- Store <expR> to <variablename>
Example:- Store 0 to m1,m2
Store {24/01/08} to tdate
Space:-
Syntax:- <variablename>=space(<expN>
Example:- name=space(15)
=
Syntax:- <variablename>=<expR>
Example:- name=”Rushabh”
Ch=.t. (For logical value storage)
PICTURE <expC1>:= If the PICTURE clause is present, the result of <expr1> is displayed according
to the format specified by <expC1>. <expC1> can consist of function codes, picture codes or a
combination of both.
AT <expN1> :- AT clause is used to specify the column number <expN1> where the output is
displayed. The numeric expression <expN1> can be a UDF that returns a numeric value.
(2) If ..else….endif :-
The if..else.. statement is a another powerful decision making statement and it is used to
control the flow of execution of statement. It is a two way decision statement and it used in
conjunction with an expression.
Syntax:- if (condition)
Statements
Endif
Example:- per=45
If(per>34)
? ”Pass”
Else
? “Fail”
endif
Do case…..Endcase
The Do case structure allows you to select one set of command from many alternatives.In
If..endif you can specify only two alternative while Do case structure allows you to specify as many
alternatives as you like.
Syntax:- Do case
Case <expL1>
<statements>
<break>
Case <expL2>
<statements>
<break>
……….
……….
Case <expL n>
<statements>
<break>
otherwise
<statements>
Endcase
When foxpro enters in Do case..endcase structure it will check the case statements in sequence
when it find true condition ,it execute the corresponding command set. If foxpro does not find any
case statements as true and structure include the otherwise statements it execute the command
given between otherwise and endcase.
Example :- Write a program to check whether the input character is vowel or not.
Ch=space(1)
Input “Enter only one charater” to ch
Do case
Case ch=’a’ or ch=’A’
?”Enter character is vowel”
Case ch=’i’ or ch=’I’
?”Enter character is vowel”
Case ch=’e’ or ch=’E’
?”Enter character is vowel”
Case ch=’o’ or ch=’O’
?”Enter character is vowel”
Case ch=’u’ or ch=’U’
?”Enter character is vowel”
otherwise
?”Enter character is not vowel”
Endcase
Looping Constructs
Foxpro provide various types of looping constructs as shown below.
(1) For……endfor
(2) Do while ……enddo
(3) Scan………endscan
(1) For……endfor :
The For…..Endfor executes a set of statements within a loop specified number of times .A
memory variable or an array element is used as a counter to specify how many times the statements
inside the loop are execute.
(2) Do while……enddo:-
Do while command is very powerful and flexible set of command and it is used to execute the
command repeatedly. Do while command executes a block of statements within a conditional loop.
Syntex:- DO WHILE <expL>
<statements>
[LOOP]
[EXIT]
ENDDO
A set of statements is placed between Do while and enddo are execute as long as the logical
expression <expL> remains true. Do while statement must have a corresponding enddo statement.
<exp L> specifies the logical expression. The statement placed between do while and enddo
are execute as long as this <exp L> evaluates to true.
<Loop> Loop can be placed anywhere between Do while…..enddo. Loop Returns the control
directly back to Do while.
<Exit> Exit can be placed anywhere between Do while…..enddo. Exit sends the control to out
of the Do while loop and first statement after the enddo.
Arrays
An array is a set of related data item.
An array is a group of variable having same name but with different index value.
There are three types of array
1. One dimensional Array
2. Two dimensional Array
3. Multi dimensional Array
Note:- In Foxpro you have to learn only one and two dimensional arrays. And the simple concept of
multidimensional array.
⇒ You can create any Array variable using ‘Declare’ keyword or using ‘Dimension’ keyword.
⇒ In foxpro the index value of array is start with 1 not with 0.
⇒ In foxpro you not have to declare the Data type of array variable.
⇒ Datatype of array variable is depends on its value.
⇒ We can use ‘[ ]’ bracket of ‘()’brackets to declare the size of array variable.
⇒ The default datatype of array variable is logical
⇒ We can change the size of array at any time like increment after declaration.
(2) EOF():- This function checks whether the cursor is at the end of database file or not. If it found
the cursor at the end of file it return true (.T.) as answer else it return False(.F.) as answer.
Example:- use student
?EOF()
Output:- .t.
Return:- Logical
(3) Found():- This function returns true (.T.) if continue, find, locate or seek is successful otherwise it
return false.
Syntax:- Found([<expN> | <expC>])
Return:- Logical
(4) Afield() :- This function is use to store table structure information into an array variable.
AFIELDS( ) places information about the structure of the current table into an array and
returns the number of fields in the table. AFIELDS( ) stores each field name, type, length, and
the number of decimal places in numeric fields.
Syntax:- AFIELDS(<array>)
Returns:- Numeric
(5) Fcount():- This function returns the number of fields in the current or specified table/.DBF.
We can use combine @..say .. command and @ ..Get command into a single command. If
both the SAY and GET clauses are included, specify a single set of coordinates <row, column>
where @ ... SAY output begins. A space is automatically inserted between the @ ... SAY output and
the @ ... GET text editing region.
DEFAULT <expr1>
If you specify a memory variable for the @ ... GET editing region that doesn't exist, it is automatically
created and initialized if you include DEFAULT .However,an array element isn't created if you specify
an array element in a DEFAULT clause. The DEFAULT clause is ignored if the memory variable
already exists or you specify a field.
Note:- If the DEFAULT clause isn't included and the memory variable <memvar> doesn't exist, the
error message "Variable not found" is displayed.
The DEFAULT expression <expr1> determines the type of memory variable created and its
initial value.
Diplay List
1. Default scope of Display command is current 1. Default scope of List command is all
record. record.
2. Display command displays the record pagewise. 2. List command does not displays the record
page wise.
3. Display command displays the field headings 3. List command does not displays the field
when there are more than one page record. headings when there are more than one page
record.
4. Display command displays the records which 4. List command displays the records which
are marked for deletion when set deleted is on. are marked for deletion when set deleted is
on.
Edit Browse
1. Edit command will display the output in the 1. Browse command will display the output in
format of Row wise that is like a append screen. the format of Row and column wise that is
like a table.
2. The edit command does not have width option. 2. The browse command have width option.
3. Edit command is little bit difficult because for 3. As you can show all the record at a time, it
each and every modification you need to reach is easy process for modification.
to a particular record. So it is time consuming.
4.Edit command does not support toggle delete or 4. Browse command allows you to delete
to insert a new record. record as well as to append record.
Sorting Indexing
1. Sorting a database file create a new database 1. Indexing a database file creates an index
file. file.
2. Sorting help us to search the desired information 2.The indexfile helps us to search information
quickly. where a particular record is available.
3. Sort command is automatically attached with 3. Index command is depand on type to
‘.dbf’ extension. attached with ‘.ecx’ or ‘.idx’ extension,
4. The sort file is bigger in size than the index file. 4.The index file is smaller in size than the
sorted file.
5. Sorting is a slow process. 5. Indexing is a faster process.