Professional Documents
Culture Documents
10.1 Introduction
Visual Foxpro has two commands for organizing records in a table namely Sort and Index. We can
perform Sorting and Indexing tasks at the command level from Command Window or through the
menu.
10.2 Sort
Sorting means grouping records in a particular order say ascending or descending order based on a
key field of the records.
Ascending order means that the names in the record of a table will be arranged beginning with the
letter A at the top and Z at the bottom. On a numeric field, the smallest number comes first and on a
date field, the record with the earliest date comes first.
Descending order is just the reverse of it. This means, that names in a table will be arranged with the
letter Z at the top and A at the bottom. This is particularly useful for date fields, where you often
want the most recent date to come first.
10.3 Index
Indexing is a process of arranging records in a particular order. In indexing, original record numbers
do not change.
If the file is indexed by menu name, than the program could find a name very quickly. The index
would list just the names in alphabetical order and would contain pointers showing where each name
was in the actual table. It is possible to search this sort of ordered list very quickly and retrieve
records from large tables without a noticeable delay.
a. Single Index Files: Visual FoxPro version 1 supported only one type of index, the Single Index
file. Each index was kept in a separate file, with the extension .IDX. If the index file is kept opened,
they automatically get updated regardless of the operation performed.
1. Compact: The compact index files are faster to access and occupy less disk space due to reduced
size and this makes more efficient.
Syntax: Use <Table>
Index On <expr> To <.idx file>
Compact
b. Compound Index Files: Compund index are identified by the .CDX extension. Unlike the IDX
files, each of which can hold only one index, compound Index Files can hold multiple indexes in
single file, which are identified by names called tags. The exact number of tags you can include in a
.CDX index file is limited only by the available main memory of the machine you are using.
Compound Index Files are of two types:
1. Structural: One special type of compound index file is called Structural Compound Index, which
is opened automatically whenever you open a table.
A structural compound index is automatically given the same name as the table file with the
extension .CDX.
To create a compound structural index file:
Syntax: Use <Table>
Index On <expr> TAG < tagname>
2. Independent: Compound Indexes other than Structural Compound Index are called Independent
Compound Indexes. These can have any name with extension .CDX. However, these files cannot be
given the same name as the table.
• Index command also allows you to add new records keeping original order of records intact.
Open the table in the Browser window and click Table menu. Choose Properties to open the Work
Area Properties dialog box.
Type the remainder of the expression, or choose an operator from the Logical drop-down list, choose
the type of string from the String drop-down list and type the condition.
Type the new expression: or choose the desired parameters from the Functions drop- down lists and
type the new condition.
Click OK.
Select Table menu and choose Properties option. The Work Area Properties box will be displayed.
Click all fields in the work area radio button below the Allow across to box.
Select Remove all Button to move the selected fields back to All fields box.
Click OK twice.
A memo field can store any type of data namely, keyboard symbols, graphics, or special symbols.
Memo field can also store data such as scanned image, digitized sound, binary objects, executable
programs and any other data as well. The only limitations in using Memo fields are the amount of
disk space available in the computer. Dat stored in Memo fields do not form part of the database and
are not stored in the file with extension. DBF.Foxpro stores them in a separate file with extension.
DBF.Foxpro stores them in a separate file with the same name as original database file but with an
extension of ,FPT.
To enter data in Memo field, move the cursor to the memo field and press Ctrl+PgDn and click
memo field with a mouse This activates the Visual FoxPro editor. To view information type LIST at
the command window to view records in the currently created file.
Command window is used to enter the commands to create, modify, display, list, edit, sort
etc.
CREAT A NEW TABLE
Create <tablename>
To insert records
Insert or Append
To modify the structure of the table
Modify Structure <tablename>
Or
Modi struct <tablename>
Use student
Browse
Or
Browse fields name,roll_no
Note: Delete comand puts a physical marker to the record, which we want to delete.Records
remain in the table and can be called by RECALL command
• PACK: It permanently deletes the records marked for deletion from the table
• ZAP: ZAP command is used to delete or remove all the records from the current table
This is equivalent to delete all followed by PACK after entering ZAP records are lost forever and
cannot be recalled anyway.
Both are used to view the records when working with command window.
DISPLAY command shows the contents of the current directory or file on the screen , unless you
specify the number of records to be displayed whereas LIST command display the contents of the
entire table on the screen
Use employee
Example:
List all
List for city=“DELHI”
Use employee
Display
Or
Display all
or
Display next 4
Questions:
Q1. What is sorting?
Q2. What is indexing?
Q3. Differentiate between: