You are on page 1of 72

ABI 201

Business
Systems
ACeL
A computerized business system consists of computer hardware,
computer software, data processing ,procedures, computer personnel,
end user or a non technical individual. Set of manual and/or Amity
computerized components for gathering, storing, and processing
business data items and for converting such data items into useful
University
information
Table of Contents
Preface .......................................................................................................................................................... 6
CHAPTER 1: INTRODUCTION TO BUSINESS DATA PROCESSING ................................................................... 7
1.1 Overview Of Business System ................................................................................................................. 7
1.1.1 Management Functions ................................................................................................................... 7
1.1.2 Levels of Management ..................................................................................................................... 8
1.1.3 Information Requirements- ............................................................................................................. 9
1.2 Profile of data in business system........................................................................................................... 9
1.2.1 Large Volumes of Data and Data Handling ...................................................................................... 9
1.2.2 Identification of Relevant Data ...................................................................................................... 10
1.2.4 Classification of Data by Source ..................................................................................................... 11
1.2.5 Primary and Secondary Data Key ................................................................................................... 11
1.2.6 Historical Data for Reference and Analysis .................................................................................... 11
1.2.7 Need For Ensuring Accurate, Reliable and Timely Processing of Data .......................................... 11
1.2.8 Basic Tasks in Business Data Processing ........................................................................................ 12
1.2.9 Examples of Business Data Processing and Applications............................................................... 12
1.3 Computer System as a Potent Tool for Business Data Processing Needs ............................................ 12
1.3.1 Facilities available in computerized Systems for Data Capture ..................................................... 12
1.3.2 Validation of Data Processing and Output ..................................................................................... 13
1.3.3 Transmission .................................................................................................................................. 13
CHAPTER 2: Concepts of Files ..................................................................................................................... 17
2.1 Files ....................................................................................................................................................... 17
2.1.1 Contents of Master File.................................................................................................................. 17
2.1.2 Transaction file and its Organization ............................................................................................. 17
2.1.3 Sequential, Relative and Indexed File ............................................................................................ 17
2.1.4 Modes of Processing ...................................................................................................................... 18
CHAPTER 3: PRINCIPLES AND TECHNIQUES OF PROGRAMMING ............................................................... 19
3.1 Introduction to Programming ............................................................................................................... 19
3.2 Program Definition................................................................................................................................ 19
3.3 Characteristics of Good Program .......................................................................................................... 19
3.4 File Handling.......................................................................................................................................... 20
3.5 Introduction to Flowchart ..................................................................................................................... 21
3.5.1 Flowchart Symbols ......................................................................................................................... 21
3.5.2 Advantages of Flowcharts .............................................................................................................. 21
3.5.3 Limitations of Flow charts .............................................................................................................. 22
3.6 Psuedocode ....................................................................................................................................... 22
3.7 Programming Paradigms ....................................................................................................................... 22
3.7.1 Procedural programming ............................................................................................................... 22
3.7.2 Modular Programming ................................................................................................................... 22
3.7.3 Structured Approach to Programming .......................................................................................... 23
3.8 Top-Down Approach ......................................................................................................................... 23
3.9 Bottom-Up Approach ........................................................................................................................ 23
CHAPTER 4: CONCEPTS OF DBMS ............................................................................................................... 24
4.1 Databases defined ................................................................................................................................ 24
4.1.1 Introduction ................................................................................................................................... 24
4.1.2 Fundamental Concept of Database ............................................................................................... 24
4.2 Relational Databases defined ............................................................................................................... 24
4.3 Visual FoxPro 5.0 ................................................................................................................................... 24
4.4 Starting Visual FoxPro ........................................................................................................................... 25
4.5 File Type In Visual FoxPro ..................................................................................................................... 26
4.6 Toolbar .................................................................................................................................................. 27
4.7 Command Window and View Window ................................................................................................. 28
CHAPTER 5: INTRODUCTION TO VISUAL FOXPRO 5.0................................................................................. 29
5.1 Introducing Visual FoxPro 5.0 ............................................................................................................... 29
5.2 Starting Visual FoxPro ........................................................................................................................... 29
5.3 Data types in Visual Foxpro................................................................................................................... 29
5.4 Creating a Database .............................................................................................................................. 30
5.5 Inserting and Deleting Fields................................................................................................................. 31
5.6 Modifying a Table.................................................................................................................................. 31
5.7 Opening a Table .................................................................................................................................... 32
5.8 Editing Data ........................................................................................................................................... 32
5.9 Quit Visual FoxPro ................................................................................................................................. 32
CHAPTER 6: USING QUERIES ....................................................................................................................... 34
6.1.1 Creating a query using Query Designer ......................................................................................... 35
6.1.2 Moving or Hiding Toolbars ............................................................................................................. 35
6.1.3 Selecting Fields to include in the Query......................................................................................... 36
6.1.4 Running the Query ......................................................................................................................... 36
6.1.5 Arranging the Results of Query ...................................................................................................... 36
6.1.6 Changing Output of Query (Query Destination) ............................................................................ 36
CHAPTER 7: DESIGNING AND PRINTING REPORTS...................................................................................... 39
7.1 Introduction: ......................................................................................................................................... 39
7.2 Creating A Report Using Report Designer............................................................................................. 40
7.3 Saving the Report .................................................................................................................................. 42
7.4 Printing the Report................................................................................................................................ 42
CHAPTER 8: USING FORMS ......................................................................................................................... 43
8.1 What is a Form? .................................................................................................................................... 43
8.2 Autoforms ............................................................................................................................................. 43
8.3.1 The Form Wizard............................................................................................................................ 45
8.3.2 Choosing Fields .............................................................................................................................. 45
8.3.3 Choosing a Style ............................................................................................................................. 45
8.3.4 Generating the Form...................................................................................................................... 45
8.4 Using the Form's Control Panel............................................................................................................. 46
CHAPTER 9: MAILING LABELS...................................................................................................................... 48
9.1 Introduction .......................................................................................................................................... 48
9.2 Using Label Wizard ................................................................................................................................ 48
9.3 Printing Mailing Label ........................................................................................................................... 49
CHAPTER 10 : SORTING AND INDEXING...................................................................................................... 50
10.1 Introduction ........................................................................................................................................ 50
10.2 Sort ...................................................................................................................................................... 50
10.3 Index.................................................................................................................................................... 50
10.3.1 Types of Index .............................................................................................................................. 50
10.4 Sorting Vs Indexing.............................................................................................................................. 51
10.5 Setting a Filter Command ................................................................................................................... 52
10.5.1 Creating a Filter Condition ........................................................................................................... 52
10.5.2 Changing a Filter Condition .......................................................................................................... 52
10.5.3 Removing a Filter Condition......................................................................................................... 52
10.6 Use of Macro(s) ................................................................................................................................... 53
10.7 Memo Field Handling .......................................................................................................................... 53
CHAPTER 11: PROGRAMMING AND DEVELOPING APPLICATIONS USING FOXPRO. .................................. 56
11.1 An Overview of Programming ............................................................................................................. 56
11.1.1 Creating Files ................................................................................................................................ 56
11.1.2 Running the Program from the File. ............................................................................................ 56
11.2.1 Variables....................................................................................................................................... 64
11.2.2 Creating Array Variables .............................................................................................................. 66
11.2.5 @..SAY..GET Command ........................................................................................................... 67
11.3 Picture Clause...................................................................................................................................... 67
Preface
This book on Business Systems will help in learning the Fundamentals of Business Systems. This book is
also designed to provide standard reading material especially for the students of BCA, BSc.(IT),Diploma
and Degree courses in IT. This book will satisfy the need of the students who are pursuing a E-learning
and Distance Learning Programme in information technology.

The book mainly lays emphasis on:

The concepts of Files and relational database


Managing database using Computers.
Different techniques of Programming
Detailed study of Visual .FoxPro and Programming in Visual FoxPro

The text of the book relies on standard works on the subject. I am deeply indebted to my Family ,
colleagues as well as Head Of Department ,for inspiring me to write this book.

To cap it all, my special thanks to the Director and the respected staff of Amity Institute of E-learning for
their kind cooperation.

Ms Laxmi Ahuja

Asst Professor
CHAPTER 1: INTRODUCTION TO BUSINESS DATA
PROCESSING

1.1 Overview Of Business System

A computerized business system consists of computer hardware, computer software, data processing
,procedures, computer personnel, end user or a non technical individual.
Set of manual and/or computerized components for gathering, storing, and processing business data
items and for converting such data items into useful information

Elements of Computerized Business System :

A computerized business information system can be viewed as a system of the following major six
components:

1. Computer hardware, meaning computer equipment and its peripherals.

2. Computer software, meaning programs that instruct a computer how to manipulate data and
documentation that explains how these programs should be used.

3. Data Are facts that are to be processed by the computer hardware and software.

4. Procedures that govern the activities and treatment of the above items.

5. Computer personnel who prepare data items for computerized input. They write computer
programs, monitor computer operations and distribute the output.

6. End user, a non-technical individual who employs computer resources for performing daily tasks.

1.1.1 Management Functions

Planning is the ongoing process of developing the business' mission and objectives and determining
how they will be accomplished. Planning includes both the broadest view of the organization, e.g., its
mission, and the narrowest, e.g., a tactic for accomplishing a specific goal.
Organizing is establishing the internal organizational structure of the organization. The focus is on
division, coordination, and control of tasks and the flow of information within the organization. It is
in this function that managers distribute authority to job holders.
Staffing is filling and keeping filled with qualified people all positions in the business. Recruiting,
hiring, training, evaluating and compensating are the specific activities included in the function. In
the family business, staffing includes all paid and unpaid positions held by family members including
the owner/operators.
Directing is influencing people's behavior through motivation, communication, group dynamics,
leadership and discipline. The purpose of directing is to channel the behavior of all personnel to
accomplish the organization's mission and objectives while simultaneously helping them accomplish
their own career objectives.
Controlling is a four-step process of establishing performance standards based on the firm's
objectives, measuring and reporting actual performance, comparing the two, and taking corrective or
preventive action as necessary.

1.1.2 Levels of Management

Top or Strategic Level Management

Middle Level Management.

Techno Structure or Specialist Staff

Operating Staff

Supporting Staff
Top or Strategic Management
|
Middle Level Management
|
|---------------------------|-----------------------|
Specialist Staff Operating Staff Supporting Staff

Top or Strategic Level Management- responsible for all the planning and operations of the
firm.

Middle Level Management-assures that the directions of the top management are carried
out by the operating staff faithfully.

Techno Structure or Specialist Staff-carries out the research and analysis for the design
work so that the profits are optimized in the organization.

Operating Staff- will carry out designed task or work appointed by the specialist staff.

Supporting Staff- these people support the works carried out by operating staff

1.1.3 Information Requirements- For taking certain decisions toplevel managers need
proper information. They have to deal with all aspects of functioning of the organization.

1.2 Profile of data in business system

1.2.1 Large Volumes of Data and Data Handling- A computer can perform work
repeatedly effectively, efficiently , extremely fast and possibly cheaper. The ability to remember
and retrieve information is accurate in computer.
Top or Strategic Management
|
Middle Level Management
|
|---------------------------|-----------------------|
Specialist Staff Operating Staff Supporting Staff

Top or Strategic Level Management- responsible for all the planning and operations of the
firm.

Middle Level Management-assures that the directions of the top management are carried
out by the operating staff faithfully.

Techno Structure or Specialist Staff-carries out the research and analysis for the design
work so that the profits are optimized in the organization.

Operating Staff- will carry out designed task or work appointed by the specialist staff.

Supporting Staff- these people support the works carried out by operating staff

1.2.2 Identification of Relevant Data


There are two types of data that must be inputted when processing transactions:

a) Variable data- These are data items that change for each transaction handled or decision mode.

b) Identification data- This is the element of data that uniquely identifies the item being processed.

1.2.3 Classification of Data elements by function


Data elements can be classified by the function performed on them. Thus, data records are of the
following types:

Mater Data Record- A master data record is a set of data for an individual subject such as a
customer, employee or vendor.
Transaction Data Record- Transaction data record is used to update the data in master
records in a master file, which contain the subjects of the organization.

Control Data Record- Control data record is a checkpoint record containing data used to
initiate, modify, or stop a control operation or determine the manner in which data items are
processed.

Data security- Data security is the protection of data against unauthorized access. Programs
and data can be secured by issuing identification numbers and passwords to all authorized users
of the system.

Data checking-Data checking is an operation used to verify data quality or data integrity.
The three types of checks that can be performed on the input data:
1.2.4 Classification of Data by Source

Source data are the original data that are handwritten or printed on a source document or typed into
the computer system from the keyboard or terminal.
It can be of the following two types:

c) Raw data . Raw data is a term for data collected on source which has not been subjected to
processing or any other manipulation. (primary data), it is also known as primary data. They are
those data items that have not been processed or manipulated

d) Derived data- Derived data are the data values that are obtained from the values of various other
data items by using a specified algorithm. After processing of Raw Data Derived data is obtained

1.2.5 Primary and Secondary Data Key

Primary Key- The record key that is unique to each record is called the primary record key.

Secondary Key- Secondary record keys are not necessarily unique.

1.2.6 Historical Data for Reference and Analysis

The form of data that gives an idea of the history of an organization or the formation of a
document comes under historical data for reference and analysis.

Historical data are stored in archive files.

These files record data in a serial manner which means that you can retrieve data fields one
after the other in a serial manner.

Validation Checks

Checking the accuracy of data

Confirming the relevance of data

1.2.7 Need For Ensuring Accurate, Reliable and Timely Processing of Data

Computer records must be changed with care in order to protect information.


The business information so achieved should have the following characteristics:

Brevity

Accuracy

Timeliness
Completeness

Relevant to the receiver

Relevant to decision making

1.2.8 Basic Tasks in Business Data Processing

Business data processing uses electronic machines for fast and accurate manipulation of data. The
main purpose of business data processing is to do complex jobs of processing at incredible speed.
A business processing cycle consists of three basic steps:

a. Input cycle- In this cycle we manipulate or combine the inputted data with a storage medium most
suitable for entry into processing machine.

b. Processing cycle- In this cycle we manipulate or combine the inputted data with other data as per
the instructions.

c. Output cycle- Once data are processed, the results are to be bought out in a form most suitable for
the user

1.2.9 Examples of Business Data Processing and Applications

Accounting: The art of recording, classifying, and summarizing in a significant manner and
in terms of money, transactions and events which are, in part at least, of financial character, and
interpreting the results thereof.

Payroll: It is the sum of all financial records of salaries, wages, bonuses and deductions.

Inventory: Inventory management is a comples business activity which includes not only
stock replenishment but also merchandising.

1.3 Computer System as a Potent Tool for Business Data Processing


Needs

1.3.1 Facilities available in computerized Systems for Data Capture


An input device converts input data into binary from acceptable to a computer. The commonly used
input device is keyboard. Several input devices which do not require typing of input information
have been developed. They include:
Mouse, joystick, lightpen, graphic tablet, touch screen and track balls.

1.3.2 Validation of Data Processing and Output


Accuracy of input data is verified either manually or by a computer programme.
Some of the technique used for this purpose are described below:

Data Validation:

Using Control tools

Using built-in checks by the Computer Program

Processing and Output:

Missing Numbered Document

Output

1.3.3 Transmission

The marriage of computers with data communications equipments is one of the most exciting
developments in data. Communication refers to the transfer of information from one computer to
another one. It is a major technology that requires special expertise in both the network and related
hardware and software that controls it.

Facilities available in Computerized Systems for a Data Capture:

Information in the form of raw data is entered into the computer through input devices.

Such input devices produce digital signal.

There are two types of devices:

1.Online devices

2. Offline devices

Online devices:

The devices used to capture data online are:

1. Keyboard
2.Light pen
3.Touch screen
4.Mouse
5. Microphone and Voice Recognition
6. Scanner

1)Keyboard: Programs and data are entered into a computer through a keyboard which is attached to
microcomputer or the terminal of a mini or large computer. It contains alphabets, digits, special
characters, and some control keys. When a key is pressed, an electronic signal is produced which is
detected by an electronic circuit called keyboard encoder.

Light pen: A light pen is a pointing device. It is used to select displayed menu option on the CRT.It
is a photosensitive pen like device. It is capable of sensing a position on the CRT screen when its tip
touches the screen.

Touch Screen: It is a computer screen designed or modified to recognize the location of a touch on
its surface. By touching the screen, the user can make a selection or move a cursor.
The simplest type of touch screen is made up of a grid of sensing lines, which determine the location
of a touch by matching vertical and horizontal contacts.

Microphone and Voice Recognition Software:


This is an input device, consisting of a microphone or telephone that converts human speech into
electrical signals. A signal pattern obtained in this manner is transmitted to the computer where it is
matched against pre-stored patterns to identify the input. These systems are used where a person
wants to input data to a computerized system in situations where his hands are busy, or his eyes have
to remain fixed on a measuring instrument or some other objects.

Mouse (Puck): A mouse is also a pointing device. It is held in one hand and moved across a flat
surface. Two rotating wheels or the underside of the mouse detects its movement and direction of the
movement. When a user moves the mouse across the flat surface, the cursor on the CRT screen also
moves in the direction of the mouses movement.

Scanners: Scanners are a kind of input devices. They are capable of entering information directly
into the computer. The main advantage of direct entry of information is that users do not have to key
in the information. This provides faster and more accurate data entry.

Magnetic Ink Character Recognition:(MICR):

Magnetic Ink Character Recognition, or MICR, is a character recognition technology used primarily
by the banking industry to facilitate the processing of cheques. The technology allows computers to
read information (such as account numbers) off of printed documents. Unlike barcodes or similar
technologies, however, humans can easily read MICR codes.

Optical Character Reader (OCR):


These scanning devices are capable of detecting alphabetic and numeric characters printed on paper.
These characters may be either typewritten or printed on paper. In case of handwritten characters,
special care has to be taken to ensure that the characters are of standard size, lines making up the
characters are connected and no stylish loops etc. are used.
Offline devices: Offline data entry involves devices through which data are recorded on some media
and then fed or transferred into the computer later.

Offline devices are:

1.Key-to-Tape

2. Key-to- Floppy

3. Key-to- Disk

Key to tape:
A key to tape device, also known as magnetic tape encoder is designed to record keyed data directly
onto magnetic tape. An operator keys in the source data electronically using a typewriter like
keyboard. The data are stored temporarily by the device and typically displayed on a CRT for visual
checking of the correctness of entered data before being transferred to magnetic tape. Magnetic tape
encoders are available for recording data magnetically on reels, cassettes and on tap cartridges.

Key- to Floppy:
These data entry machines have been introduced as low-cost data recording systems. They are used
to store data directly on flexible risks, called diskettes or floppies that are inexpensive and reusable.
A key- to floppy data entry system consists of a typewriter keyboard with additional control keys
and a display screen, which displays each character keyed in.

Key to disk:
Key to disk devices are used as data recording stations in systems where data from different
points has to be recorded for processing at one point. Typically, from 8 to 64 keyboard stations are
linked to a small special-purpose computer to record source data on a disk. Each station has a
keyboard and a monitor display

Payroll:
A paycheck is traditionally a paper document issued by an employer to pay an employee for services
rendered. In recent times, the physical paycheck has been increasingly replace by electronic direct
deposit to bank accounts. In most countries with a developed wire transfer system, using a physical
check for paying wages and salaries has been uncommon for the past several decades. Some
company payrolls both the paper check and stub, in which case an electronic image of the stub is
available on an Internet website.

Inventory:
Inventory is a list for goods and materials, or those goods and materials themselves, held available in
stock by a business. It is also used for a list of the contents of a household and for a list for
testamentary purposes of the possessions of someone who has died. In accounting inventory is
considered an asset.
Inventory is required at different locations within a facility or within multiple locations of a supply
network to protect the regular an Inventory management is primarily about specifying the size and
placement of stocked goods.
Financial Accounting:
Financial accountancy (or financial accounting) is the field of accountancy concerned with the
preparation of financial statements for decision makers, such as stockholders, suppliers, banks,
employees, government agencies, owners, and other stakeholders. The fundamental need for
financial accounting is to reduce principal-agent problem by measuring and monitoring agents'
performance and reporting the results to interested users.Financial accountancy is used to prepare
accounting information for people outside the organization or not involved in the day to day running
of the company.

Questions:

1) What is Business Data Processing?

2) What is difference between merging and sorting?

3) Why is Data Validation necessary? Explain various types of data validation checks that are kept in
a programme.
CHAPTER 2: Concepts of Files

2.1 Files
In computer operations, a file is collection of related data that is created as a single unit on a
peripheral device. A file can be of following two types:

1. Master file

2. Transaction file

2.1.1 Contents of Master File


Master file: A file of related master records is a master file. Master record is data that is relatively
permanent; like name, sex, d.o.b.

2.1.2 Transaction file and its Organization

Transaction file: A transaction file is a file in which the current data are stored for subsequent
processing usually in combination with a master file.
Transaction data may be collected automatically or may initially be recorded on source documents
and later converted to a machine readable format. This leads to the creation on transaction records
that are stored in transaction file.
A transaction file contains the records that are used to update the records of the master file. It is very
important that the transaction file should contain records with the fields and their names in the same
order and size and type as that of the master file.

2.1.3 Sequential, Relative and Indexed File

Sequential file: Sequential file is one in which the records are stored some sequence or order.
For example: A students file may be kept in the order of ascending roll number.
Advantages of Sequential File Organization:

a. File design is simple.

b.Location of records requires only the key record .

c.When the activity rate is high, simplicity of the accessing method makes processing efficient.

d.Low-cost file medium such as tapes can be used.

Drawbacks of Sequential File Organization

a. Updating requires that all transaction records to be first sorted in the key record sequence.
b.A new master file, physically separate and exclusive is always created as a result of sequential
updating.

c.Information on the file is not always current. Addition and deletion on records are not simple tasks

Relative file: Relative files are other types of disk files that also permit random access. Relative file
does not use an index to access records randomly. Rather the key field of each record is used to
calculate the records relative location in the file stored on the disk.. With the relative files the key
field is converted to an actual address.

Index file: An indexed file is one that has an index for looking up locations of records on a disk. This
index enables the user to access a disk file randomly.Index files are very useful for processing where
a user communicates directly with the computer using a key field he or she is entering( not
necessarily enter in sequence).Once the address of the disk record is obtained from an index the
access mechanism can move directly to that address on the disk where that record is located. Hence
the method of accessing record will be faster.

2.1.4 Modes of Processing

There are several methods of processing data depending on the type of data and the time available for
the processing and getting results:

a. Batch processing: Batch processing is one of the oldest methods of running programs that is still
being employed by many data processing centres for processing their jobs.

It is based on the idea of automatic job-to-job transition facility prepared by almost al operating
systems.
Batch processing is also known as serial, sequential, off line or stacked job processing.

b. On-line processing: Online processing permits transaction data to be fed directly into secondary
on-line storage devices.

Here the access to, retrieval of, any record is quick and direct.
Online processing systems feature random and rapid input of transactions and immediate and direct
access record contents as and when needed.

c. Real-time processing: Real time means immediate response from the computer. A system in
which a transaction accesses and updates a file quickly enough to affect the original decision making
is called a real-time system.

Here files are updated each minute, and enquiries are answered by split-second access to up-to-the-
minute records.

Questions:
Q1. Explain types of files.
Q2. Explain modes of processing.
CHAPTER 3: PRINCIPLES AND TECHNIQUES OF
PROGRAMMING

3.1 Introduction to Programming


Programming is the art and science of creating computer programs. Programming begins with
knowledge of one or more programming languages such as C,C++,C#.
Programming requires a similarly logical approach to designing, writing, testing and debugging a
program.

Program Life Cycle


Every computer based system just as living organism has a life cycle. Commercial program such as
Payroll, Inventory control and other software share a common life cycle pattern. To keep up with
new technology, a program may become inadequate to meet future needs. At this point of time,
investigations are made, requirements are analyzed and new specifications are proposed and a new
system is developed. The life cycle of new system thus starts again. Once a new system is
operational, the development team is dispersed. But one last task should be completed before person
involve in the project are assigned to other activities-review of the system .A report might review the
need for recycling and listing reasons for schedule and budget slippage and outline liaison and
communication problem that occurred during development. Mistakes should be identified and an
analysis made of reasons for the mistake and how they could have been avoided. Such a document
will help future development teams avoid similar pitfalls and lead to improved development
procedures

3.2 Program Definition


Program: A program is a collection of instructions that control the computer what to do. A program
is called software, hence, program, software and instructions are synonymous.
A program is made up of :

Instructions: Instructions are the directions that the computer will follow and a particular
sequence of instructions is called the programs logic.

Buffers: Buffers are reserved spaces in the computer memory that will accept and hold the data
while it is being processed.

Constants: Constants are fixed values within the program that are used for comparing.

3.3 Characteristics of Good Program


Programming style should have the following three important qualities:
a. Readability: The source code or the program should be written in high level language so that it is
readable to you and others.

b. Portability: Write the code using high level language so that it is easy to transfer the program to
other machines as well.

If possible, avoid non-standard features an also use the standard library runtime routines rather than
writing your own and thus save time.

c. Maintainability: While writing the program think about how you might want to change or extend
it in future.

For example, put data structure definitions in header files where changes will automatically broadcast
to all source files that include the header file.
Guidelines for Good Programming:

1. Use a few standard control structures.

2. Use goto in a disciplined manner.

3. Hide data structure b behind access function.

4. Avoid null statements

5. Use parenthesis, backspaces when needed.

6. Do not use an identifier for multiple purpose.

7. Nesting of program constructs should nor exceed five levels.

8. Provide standard documentation.

3.4 File Handling


File handling refers to several levels of managing data. They are:

a) File handling is the part of the operating system that manages the physical storage and retrieval of
data on a floppy disk or other storage device.

b) File handling refers to the software that allows for the creation, storage, retrieval and manipulation
of files interactively at a terminal or personal computer.

c) File handling is the management of all files or data and information within an organization and
includes data administration, the standards for defining data and the way in which people perceive
and use it in their day-to- day tasks.
d) File handling is a function within an organization that manages the file.

3.5 Introduction to Flowchart


Flowchart: A flowchart is a graphical representation of the sequence of operations in an information
system or program. Program flowchart shows the sequence of instructions in a single program or
subroutine.
Flowchart uses boxes of different shapes to denote different types of instructions.

3.5.1 Flowchart Symbols

The American National Standards Institute (ANSI) has standardized flowchart symbols
The symbols are:

1. Processing: A processing symbol is used in flowchart to represent arithmetic and data movement
instructions. Rectangle

2. Flow lines: Flow lines with arrowheads are used to indicate the flow of operation, that is, the exact
sequence in which the instructions are to be executed. Straight and horizontal Lines

3. Decision: The decision symbol is used in a flowchart to indicate a point at which a decision has to
be made and a branch to one of two or more alternative points is possible. Diamond

4. Connector: Whenever a flowchart becomes too complex that the number and direction of flow
lines is confusing or it spreads over more than one page, it is useful to utilize the connector symbol as
a substitute for flow lines. This symbol represents an entry from, or an exit to another part of the
flowchart. Small circle

5. Terminal - rectangle like with two rounded sides

6. Input/Output - rhombus

3.5.2 Advantages of Flowcharts

Conveys meaning better

Analyzes the problem effectively

Effective joining the Parts of a system

Efficient Coding

Systematic Debugging

Systematic Testing
3.5.3 Limitations of Flow charts

Takes more time to draw.

Difficult to Make Changes.

Non- Standardization

3.6 Psuedocode
Pseudocode is program analysis tool that is used for planning program logic. It is an imitation of
actual computer instructions and these are written in ordinary natural language such as English.
Examples of Pseudocode:

Example 1: Working with Masala Dosa Mincer

Pseudocode:
BEGIN
Turn Mincer On
Mince Dosa Masala
Turn Mincer Off
END

Operation on File:

The following are the basic operations performed on files:

1)Inputting or Writing to a file.


2)Outputting from a file or Reading afile
3)I/O and Deleting a file:

3.7 Programming Paradigms

3.7.1 Procedural programming

Procedural programming is based on the procedures. In the procedural programming, all the
returning sequences if statements placed in main program. A procedure call is used to invoke the
procedure. After the execution of statements, flow of control return after the position where the call
was made.

3.7.2 Modular Programming


Modular Programming is the splitting up of the programs/problems into series of self contained
modules. A module should not exceed about 100 or so lines and should preferably be short enough to
fit on single page.

3.7.3 Structured Approach to Programming


Structured programming can be seen as a subset or sub discipline of imperative programming, one
of the major programming paradigms. It is most famous for removing or reducing reliance on the
GOTO statement.

3.8 Top-Down Approach

Top-Down Design is the technique of breaking problem down into the major tasks to be performed.
Each of these tasks is the further broken down into separate subtasks, and so on till each subtask is
sufficiently simple to be written as a self contained module or procedure. The program then consists
of a series of simple modules.

3.9 Bottom-Up Approach


When faced with a large and complex problem, it may be difficult to see how the whole thing can be
done. It ma be easier to attack parts of the problem individually, taking the easier aspects first and
thereby gaining the insight and experience to tackle the more difficult tasks, and finally to try bolt
them all together to form the complete solution. This is called a Bottom-Up Approach.

Questions:
Q1. What are the characteristics of good programming?
Q2. What is a flow chart? Explain its symbols?
Q3. What is Pseudocode?
Q4. Explain types of Programming.
CHAPTER 4: CONCEPTS OF DBMS

4.1 Databases defined

4.1.1 Introduction
Database: A database is an organized collecton of facts or data items. In other words it is a
collection of information arranged and presented to serve an assigned purpose.

4.1.2 Fundamental Concept of Database

Computer uses database by using a set of well defined rules. A database contains records, each of
which in turn has fields in it.

Field: The smallest piece of meaningful information in a file is called a data item or field. A data
item is generally used for a group of alphanumeric characters.

Record: A collection of related fields is called a record.

File or table: A collection of related records that are used for getting information is called a file
or a table.

4.2 Relational Databases defined

Relational Database: Relational database means joining multiple tables used in an information
retrieval process according to some relationship specified by the user.
Visual FoxPro is a relational database manager, and gives you the choice to use one or more than one
files a time.
It enables to define relationships between two or more files.

4.3 Visual FoxPro 5.0

Visual FoxPro is a powerful and flexible database management system package. It includes a
programming language, an engine for relational database and an integrated development environment
(IDE), which allows developers to do absolutely everything they need. Visual FoxPro has an
excellent compatibility: a code written 5 years ago and still can with a minimum of work to be
maintained and improved. Visual FoxPro is also a tool for rapid development (and sustainable)
application (RAD) that enables developers to design applications sophisticated appearance with
minimal effort. Visual FoxPro is a leading database Management System. It is windows based
Graphical User Interface (GUI) RDBMS. The database is a broader concept in Visual FoxPro in
which the information is stored in related tables.

4.4 Starting Visual FoxPro

In order to start with Visual FoxPro, you must ensure that Visual FoxPro system is already installed
on your computer. To invoke Visual FoxPro, Double click the My Computer Icon on the Desktop
Window. Then double click C: drive. Now, click on Program Folder and then Microsoft Visual
Studio. Now double click the Microsoft Visual FoxPro icon as shown

Start->Program->Microsoft Visual FoxPro->Microsoft Visual FoxPro 5.0

Visual FoxPro Window Elements:

Title bar: Located at the top of a window, it displays the window name and the application window
title bar displays the name of the program.
Application window: It provides an interface between the user and the program.

Command Window: Command window is normally placed at the bottom right corner of the screen.
It is used for typing commands

Maximize/Restore button: It is located in the upper-right corner of each window. It controls size of
the window.

Minimum Button: Located in the upper right corner of each window. It reduces the window to an
icon.

Close Button: It closes the Visual FoxPro main window and returns to window desktop icon.

Menu bar: Located below the menu bar. It contains buttons for performing the most common
actions in Visual FoxPro
Standard Bar: Located below the menu bar. It contains buttons for performing the most common
actions in Visual Foxpro.

Status Bar: Located at the bottom of the application window. It displays various types of the
information related to the window that is currently opened..

4.5 File Type In Visual FoxPro

1. Project - used to hold other files such as tables, forms, reports, etc.

2. Database - collection of data files

3. Table - Table is a file used to store data


4. Query - help you ask questions about tables

5. Connections, View and Remote View

6. Form - Customize the way you view and edit table data

7. Report - enables you to group, summarize and print table data

8. Label - help create mailing labels

9. Program - Plain text file to hold Visual FoxPro programming code

10. Class - used in object oriented program

11. Text - plain text file

12. Menu - custom menu for application

4.6 Toolbar

1. New

2. Open

3. Save

4. Print

5. Print Preview

6. Spelling

7. Cut

8. Copy

9. Paste

10. Undo

11. Redo

12. Run
4.7 Command Window and View Window
You can issue commands by typing commands into the command window. View window is a quick
way of open
Modify Command is the standard Text Editor of the Visual FoxPro.
In short it is also called modi comm. It allows you to create and modify text. Using this text editor
you can code or modify a Visual FoxPro program.

Questions:
Q1. What is Database?
Q2. Explain:

a. Field

b. Record

c. Table

Q3. What is relational database?


CHAPTER 5: INTRODUCTION TO VISUAL FOXPRO 5.0

5.1 Introducing Visual FoxPro 5.0


Visual FoxPro: Visual FoxPro is a powerful and flexible database management system (DBMS)
package. In many aspects it is a strong industrial DBMS.
It is a relational database manager, and hence gives the choice to use one or more than one files/
tables at a time. It enables you to define relationships between two or more files/tables.

5.2 Starting Visual FoxPro


Before starting Visual FoxPro, it must be installed on your hard disk. If Visual FoxPro is already
installed, then follow the steps to start FoxPro:

Turn on the computer. After a brief internal self check, the operating environment will
automatically load itself and well get Windows desktop.

Click on Start button, start menu appears.

Now click on the program sub menu choose Microsoft Visual FoxPro and then choose
Microsoft Visual FoxPro 5.0

5.3 Data types in Visual Foxpro


Type specifies the data type that the field can store. A field type can be of 13 types.

1. Character: Character fields store 1 to 254 alphanumeric characters such as letters, numbers,
symbols or spaces. It is the default field type and it is not used for calculations.

2. Currency: This field is used to store money values. Its contents are accurate to four decimal
places.

3. Numeric: Numeric field is used to store numbers, with or without decimal places. Numbers can be
up to 20 digits in length, including and optional plus/minus sign and a decimal point.

4. Float: Float type of field can have a width up to 20 including an optional plus/minus sign and
decimal places.

5. Date: Date field is stored in American Format of MM/DD/YY. Here MM represents month, DD
represents day and YY represents year. On selecting date type, Visual FoxPro will automatically
show the standard width 8 characters including the slashes.
6. Date Time: Date Time fields contain a combination of the date and time. The value is stored in the
format yyyy/mm/dd/hh/mm/ss.

7. Double: Double data type of fields allow you to store data that requires a higher degree of
precision. This is most often used in scientific and engineering applications.

8. Integer: The integer type is used for non-decimal numeric values where performance and table
storage limitations are especially important. In tables the integer field is stores as a 4-byte binary
value.

9. Logical: Logical Field is a single character field representing a true or false value. The letters T
and Y represent true, and F and N represent false.

10. Memo: Memo field is also a type of character field but it can store large blocks of text unlike a
character field.

11. General: The most common use for General Fields is to store graphics. General, which stores
OLE objects whose size is limited only by available memory.

12. Character Binary and Memo Binary: The character binary and memo binary fields work
similar to the ordinary character and memo fields except that the data is not translated for different
code pages.

5.4 Creating a Database

Creating a Table: In Visual FoxPro tables can be created through the Command window or from
Table Designer or through the Table Wizard. Tables are stored in its own files with .dbf extension or
are stored in a database with .dbc extension.

Creating a new table

Visual FoxPro tables can be free or contained in a database. A database (.dbc) file can contain one or
more tables, views, connections, and stored procedures. You can access the data in a free table from
anywhere, even from one or more databases. You can only access data in a database-contained table
from within the database that contains it.

Tables can be created using the command window or from Table Designer or through Table Wizard.

1. From the File menu, select Open.


2. In the New dialog box, select Table, and then click either the New File button or Wizard
button.

Note If the table is contained in a database, the Open command opens the table and
the containing database.
Creating Table using Table Designer
File->New->Table-> Ok

5.5 Inserting and Deleting Fields


From the table designer we can insert and delete fields in a table as described in the following:
Insert:

To insert a new field, position the insertion point on the row where we want to insert the new
field and choose Insert button.

A field named New Field with character type and a default width of 10 is added before the
selected field.

To insert more fields, choose Insert again, Fields are added and named as NewFld1, NewFld2
and so on.

We can then modify the name and type etc as desired.

Delete:
To delete a field from the Table Designer, position the insertion point on the desired field and
choose the Delete button.

You will see the selected field is removed and all remaining fields shift up one position in the
structure.

Select the No button. Selecting No button completes the table definition procedure.

5.6 Modifying a Table

Modifying the structure of data table is done in the same way as creating it.

You can modify the structure through menus by selecting Table Designer from the View menu
or from Window menu, select Data session.

Data Session dialog box is displayed, click on Properties button.

It again displays a Work Area Properties dialog box, now choose Modify..button.

Using any of the above methods displays the Table Designer, allowing you to modify the
structure of a table.

While modifying structure you can add or remove fields, change width and data types and create
indexes.
5.7 Opening a Table
Once a file is been created it can be opened number of times by performing following steps:

From File menu choose Open... to access the Open dialog box.

From the Files of type: text box, select Table (*dbf) to display the available table files. Notice
that table files end with extension .dbf.

If necessary, scroll until the Employee.dbf file name is visible.

Once the desired table is found click on it and the selected file name is now displayed in the File
name: text box.

Click on the OK button to open the selected table. The status bar displays the name of the table
you have opened.

5.8 Editing Data


The term editing refers to making changes in the existing data in a table. The editing commands are
used to make changes in the existing tables in Visual Foxpro.
Editing data may require:

5.9 Quit Visual FoxPro


To exit Visual FoxPro , you can use the File menu and Choose Exit command, or you can type quit
command at the Command window, or you can simply double-click on the application windows
Control menu button.
To exit Visual FoxPro:
Double click on the application windows Control menu button. You are returned to the Windows
environment. You may now start up another program from Windows, or turnoff your computer.

Questions:
Q1. How to delete a record while in Browse mode?
Q2. How to open a table in Visual FoxPro?
Q3. How many data types are there in Visual FoxPro? Explain them.
1. Insert data: To insert data click the mouse button to the place of an insertion point where
you want the new data to appear, then type of the data.
Saving The Table Designer Structure
After the table structure of file has been correctly specified click on the OK button in the dialog box.
An alternative method is to press Ctrl+W.

2.Once you saved your file, a dialog box appears containing two buttons Yes or No and initially Yes
button is selected.

2. Replace a character: To replace a character, place the insertion point to the left of the character to
be replaced, Press lns key, type the replacement character, press lns key again.

3. Replace the selected data: Select the data to be replaced and type the new data.

4. Delete the selected data: Select the data the press Del or Backspace button.
CHAPTER 6: USING QUERIES

Query is the most powerful feature of any database. A Query is a set of instructions in a logical order,
required to produce the output based on Table (s) in a particular fashion. Query can be created based
on complex conditions. In visual FoxPro data can be retrieved in the following four ways:
Using Command Window
Using SQL Commands
Using Query Designer
Using Query Wizard

Creating a Query

Using a Query Designer or Query Wizard, we can display data in a table in whatever way it is most
useful for us. Query lets to control the following items.

a. Which fields of a table are displayed?

b. Which records of a table are displayed?

c. The order in which records are displayed

Query Wizard

To create a query with Query Wizard, choose New option from File menu or click the New tool.
Choose Query radio button and then click Wizard push button.
. Click the File menu and choose New. or click the New button on the Standard toolbar. It displays
New dialog box.

2. Select the Query radio button.

3. Now select either the Query wizard or the Query Designer.

File-> New... -> Query or type "Create Query" in the command window
6.1.1 Creating a query using Query Designer
Creating a query with Query Designer is relatively straightforward. To open the query designer
window do one of the following:

Select File menu and choose New. New Dialog Box appears. Select Query radio button from the
New dialog Box and click on New file.

You can also start a new query from the Command Window by typing Create Query and
pressing enter key.

STEPS:

1. In the Query Designer, click the Fields tab.


2. In the Available fields list, select a field, and click Add. To select multiple fields, press
the SHIFT key while selecting fields, and then click Add.
3. To specify the order in which fields appear in output, click and hold the vertical double arrow
button appearing to the left of the field you want to move in the Selected fields list. Move
your mouse to position the field the way you want.

To customize or define query further in the Query Designer by performing the following tasks:

Change the join condition of the selected tables in the Join tab.
Filter results by field in the Filter tab.
Organize results by field in the Order By tab.
Group results by field in the Group By tab.
Select a different type of output in the Miscellaneous tab.

6.1.2 Moving or Hiding Toolbars


To move a toolbar, do this:

1. Place the mouse pointer on the title bar of the toolbar.

2. Drag the toolbar to its new location.

If the toolbar is displayed at the top of the screen, we can move it by placing the mouse
pointer on the toolbar between any two buttons and dragging the toolbar down.
To hide or display a toolbar, do this:

1. Place the mouse pointer anywhere on the toolbar.

2. Click the right mouse button to display a list of toolbars. A check mark indicates that the toolbar is
currently displayed.
3. Select the name of the toolbar you wish to hide (or display).

6.1.3 Selecting Fields to include in the Query


After selecting the table from which to retrieve the information, here are the steps to select the filed
in the query result:
(Fields tab is already selected and all the fields of Employee table are listed in the Available Fields:
list box)

From the Available Fields: list box, select the desired field name(s).

Click on Add> to include the filed(s) in the selected output list.

6.1.4 Running the Query


To run a query, one of the following four steps can be followed:

By selecting the Run Query from the Query menu or

By pressing Ctrl + Q keys together to run the Query or

By right click on the table window in the query window and select Run Query option from the
menu. By default the result will be displayed in Browse window, or

By clicking on the ! mark on the Standard toolbar to run the query.

6.1.5 Arranging the Results of Query


To arrange the results of Query:

Click on the Order By tab in the Query Designer window.

In the Selected output: list box, select the Field(s) by which we wish to order the query result.

Click on Add> button.

Under Order options, click on Ascending or Descending.

By default Visual FoxPro uses Ascending order for selected field.

6.1.6 Changing Output of Query (Query Destination)


By default the result will appear in Browse window. We can also specify where we want Query
results to be displayed.

Click on the Query Destination button in the Query Designer toolbar. The query Destination
dialog Box appears.
In the Query Destination dialog box, select the desired output option.

There are seven query output options:

1. Browse: It displays query results temporarily in a Browse window, This is the default option,
which we use to show query results.

2. Cursor: It temporarily stores query results in read-only form. When we click on Run, the query
runs and the temporary table name appears in the Status Bar. But the Query Designer remains active.
We can browse the query results from the View windows also. When we close the cursor, the
temporary table is no longer available for use.

3. Table: It stores query results in a table.

4. Graph: It starts the Microsoft Graph program, if it is on PC.

5. Screen: It shows the query output in the main Visual Foxpro window.

6. Report: It displays query results in either an existing or a new report form.

7. Label: It displays query results in an existing or a new label form.

Cross-Tab Wizard
What is a Cross-Tab?

A cross tab or cross tabulation is a very powerful way of summarizing data in rows and columns. The
cross tab is a spreadsheet like numeric summary of set of data records., if you had a table that records
sales made by different salesman to customers in different regions say East,West,North and South.
For example you might want to create a cross-tab showing total sales by each salesman on each
region. The cross tabulation could have a salesman name at the left of each row and region. at the top
of each column and each cell of the cross tab could show the total sales made by that salesman in that
region. Instead of calculating sum, you could use the cross-tab to calculate the average sales for each
salesman in each region or the maximum or minimum sales by each salesman in each region.

Create the following Sales table with the structure as follows:

1. Click on New button from the standard toolbar. The New dialog box is displayed.
2. Click on Table radio button and choose New File button to create a new table file. Visual Fox
Pro opens the Create dialog box
3. Type sales.dbf in the enter table list box and then click save button.
4. Table Designer dialog box appears. Create the structure and click on OK
5. A message box appears to insert the records click on Yes
6. Visual FoxPro opens the Sales table in Append mode to add the records
7. After adding click Ctrl+W to save the records.
8. From View menu choose Browse to view records in the browse window
Creating Cross-Tabs

Tools->Wizards->Query->Cross tab and follow the directions to create query


1. Select Query radio button and click wizard button
2. Visual FoxPro displays the wizard selection dialog box and select Cross Tab wizard.
3. Select table sales and ok
4. Select fields from field box
5. Click on Next button to move to next step
6. Next step let you lay out the cross-Tab by clicking and dragging fields-one for the column
headings, one for the row headings and one that is used as the basis of the calculations in the
cells. For example, if you want to calculate total sales by each salesman in each region, you
can select the region to be used as the column heading, the salesman (Name) to be used as the
Row heading and the sales amount(Sales) field ,to be used as basis of the calculation in the
cell.
7. Your cross tab query results will display a column for each unique value that exists for the
table field that you drag to the data box.
8. Click on Next button
9. Add a column that contains summary informationand subtotals by selecting the appropriate
radio button from the summary and subtotals report
10. Now create the query and click on Finish
11. Press Esc key to view the result in the Browse button

Questions:
Q1. Write the steps how to create a Query Wizard?
Q2. Explain Order By option of Query Designer window with example.
Q3. Explain all the seven Query Destination options.
CHAPTER 7: DESIGNING AND PRINTING REPORTS

7.1 Introduction:
Report: A report is the collection of facts and figures with page numbers and headings.
Visual Foxpro offers three tools for producing reports. They are:

Auto Report

Report wizard

Report designer

Auto Report: Auto Report are adequate when columnar listing of data selected is needed in the
fields.

Report wizard: Report wizards are used for reports that you want to create and manage data. It helps
you to produce report quickly.

Report Designer: Report designer is a visually oriented interface for manually designing reports.
through Report designer we can create a report by placing several objects ,such as fields,text,graphics
and expressions onto the report, wherever required

CREATING REPORT WITH REPORT WIZARD

Reports can be created using:


(i) Report Wizard
(ii) Report Designer

REPORT WIZARD

Reports can be created easily by using a report wizard. The report wizards help to set up and create a
report layout using answers to a series of questions. You can use the Report Wizard to create reports
with single tables, for example, to create a list of names and addresses from a customer table. User
can use the One-To-Many Report Wizard to create reports with tables that have a parent-child
relationship, for example, to create a list of orders for a customer from a customer table and an orders
table.
7.2 Creating A Report Using Report Designer

Report Designer begins the report design process with a blank report layout.

In the File menu, click New.

1. In the New dialog box, select Report, and click the New File button.
2. In the Report menu, select Quick Report

The Report Designer opens.

A report can be created through menu selections or by typing commands in the Command Window.
Before the report is been created, the table that is to be used should be first opened

1. From Command Window, type Use Employee to open the employee table.

2. Now type Browse at the Command window to view the records in the employee table.

3. Press Esc to close the browse window.

3. Type Create Report in the Command window or Select New or Ctrl + N from the file menu,
choose Report radio button and then click on a New file.

You can also start a new blank report from the File menu by clicking New and in the New dialog
box, click Report and then New File.

You can open the Report Designer programmatically using the CREATE REPORT and MODIFY
REPORT commands. For more information, see CREATE REPORT Command and MODIFY
REPORT Command.

To create an Auto report

Open a table and then click the Auto report Wizard button on the Standard Toolbar,

Auto reports include all the fields of the table and use the field names as labels.

Reports are saved with the extension.frx


Create a new report form by typing:
CREATE REPORT Press <RETURN> key in the command window.
A Report Layout Window appears with default title name. You can also type
CREATE REPORT <filename> Press <RETURN> key in the command window to get a new
report form named filename.frx in the Report Layout.
Choose Quick Report. Option from the Report menu
Report Layout

To create Report Using Report Designer

We can create report through menu selections or by typing commands in the command window. but
before creating a report format open table for the report.
1. From Command Window, type USE EMPLOYEE to open employee table
2. Now type BROWSE at the command window to view the records on the employee table
3. Press Esc to close the browse window.
4. Type CREATE REPORT in the command window or select New or Ctrl+N from the File
menu, choose Report radio button and click on New File.
5. Visual FoxPro displays the opening screen
6. In Visual FoxPro, we can create reports by placing objects, such a s text, fields, lines and
rectangles in the horizontal sections or bands of Report Designer Window.

The Screen is divided into three parts Page Header, Detail and Page Footer, These are called
bands and they Page Footer as boxes.

Page Header Page Header band is used to identify the header of the report. It contain the report title,
report column headings or description.etc.

Detail band is used to define fields that will form the actual report or the body of the report. We can
use all or selected fields in any order.

Page Footer Page Footer band is similar to Page Header part except that it appears at the bottom of
the each page. It is also used for printing total, date, page number etc.

Report Designer Window


7.3 Saving the Report
To save the Report:

Click the file menu and choose Save As. Option

Type the desired file menu.

Specify the desired drive and /or directory in which you wish to save the report.

Click on Save.

7.4 Printing the Report


Visual FoxPro reports are saved in two files. One file has the extension .FRX, and the other .FRT
extension. Both the files have the same first name, which the user assigns. As with Visual FoxPro
table files, each report file contains different information about the same report. Therefore, in order
to print the report both file should reside in the same disk directory.

To print the report:

With the desire report displayed, choose File menu and choose Printor Press Ctrl + P keys together
to open the Print dialog box.

Click on OK to begin printing.

Close the Report Designer Window by pressing Esc Keys.

Questions:
Q1. How a report is designed with the report designer?
Q2. How to save a report?
7Q3. How to print the report?
CHAPTER 8: USING FORMS

Forms are very powerful tool. It provides the basic means for inputting data for the
application
Some forms only display information to the users. However, most forms require some degree
of user interaction.
Visual FoxPro stores the information about the form designs in a special data file with the
same name as of the form and an extension of .SCX

8.1 What is a Form?

Forms are used to incorporate custom fields, push buttons, hide sensitive and confidential
data. Forms are the basic interface for the user in Visual FoxPro. FoxPro has a Form Wizard,
which will produce a good-looking form very quickly.We will build a straightforward form
by hand.

8.2 Autoforms
To create autoform open a table and click the AutoForm button of the Standard Toolbar.

Create a form

Click on the Documents tab of the Project Manager then right-click on Forms. Select New
File then New Form from the dialog.
The Form Designer will appear:
Add data

The form has to be connected to a data table. Right-click on the form and select Data
Environment.A directory tree will open so that you can select a table. Click on CD.dbf then
close the Add Table dialog. This should leave you with the form and the Data Environment
windows visible:

Use the mouse to select the six fields from the Data Environment and drag them to the form.
If you do this with a normal left-click then FoxPro will automatically create a grid control for
the fields. Start the drag with a right-click instead. When you drop the files a menu will
appear with the option of showing the fields as a grid or as multiple controls. Select the
Create Multiple Controls Here option. Make sure that you move the mouse to the top-left
corner of the form before you drop the fields. Some of the fields are quite wide and you
might have to make the form a bit larger to accept them it. Just click on the form border and
drag it to the size you want.

Close the Data Environment and leave the Form Designer on screen.

Run the form

There are three ways of running the form. You can:


Click the red exclamation mark on the toolbar
Select Run Form from the Form menu
Use the keyboard shortcut CTRL+E

You will be asked to save the form before you can run it. FoxPro will suggest a name something like
'Form1.Scx'. Change this to 'MyCD.scx' or something more suitable but do not change the file
extension. Form data in Visual FoxPro is stored in a pair of files with 'scx' and 'sct' extensions. The
'scx' file is actually in VFP dbf format and the 'sct' file holds its memo fields in fpt format.

Note: that the file name is not the same as the form name. The form name is a property of the form.

8.3.1 The Form Wizard


Tools->Wizards->Form. Select Form Wizard option and select One-to-many Form Wizard.

The first one, Form Wizard is a simple form based on a single table.
The second is a One-to-Many Form Wizard based on relational databases i.e. using two or more
related tables.
Select the Form Wizard. Select Fields

8.3.2 Choosing Fields


In the Available Fields click on Add All (>>)

8.3.3 Choosing a Style


Under style verify that standard is selected

8.3.4 Generating the Form


Select Save and run for. To run Form
Choose Do option from the Program menu
Choose Run button from the toolbar
Run a form by simply typing the following in the command window
Do Form Student

The One-to-Many Form Wizard is similar to the form Wizard


To create a One-to-Many Wizard, choose New option from File menu

Form Wizard with Two Tables

8.4 Using the Form's Control Panel

13. Top - Moves record pointer to first record

14. Prev - Moves record pointer to previous record

15. Next - Moves record pointer to Next record

16. Bottom - Moves record pointer to last record

17. Print - Prints a report


18. Find - Displays search dialog box
19. Add - Adds a new record to the end of the table

20. Edit - Edit current record

21. Delete - Delete the current record

22. Exit - Closes the form

CREATING A FORM USING FORM DESIGNER

The Form Wizard has its own limitations for developing a form. These limitations are
done away with the help of Form Designer
There are several ways to create a new form:
Select New option from File menu. Select Form radio button and click the New File button. It
shows the open Form Designer work area, in which you can build a visual representation of the
form.
You can also create a Form by typing the command CREATE FORM in the Command Window.
CHAPTER 9: MAILING LABELS

9.1 Introduction

Visual FoxPro has the facility to print these addressed on a pre-printed stationary as labels. These
labels can be separated and fixed on the letters and mailed. This facilitates in mss mailing of letters
without any typing errors. We can create the mailing address file only once in Visual FoxPro and
then print the addressed on the pre-printed stationary as and when required. Visual FoxPro label
generation utility is very flexible and easy to use. It enables to design your own layout to choose
from the predefined layouts.

9.2 Using Label Wizard

To open or Label Layout window:

Open the New dialog box by clicking on New icon on standard toolbar.

Select Label, and click on Wizard to open the Label Wizard dialog box.

The step1- Select tables dialog box appears to select a table for the label.

Click on the Next>button

The Step 2- Choose Label Type Dialog Box appears with listing various Label Layouts according to
the specified companys product number.

Scroll down to select the companys label number.

Click on Next> button. The Label Step-3 Define Layouts window opens.

In the Step-3 Define Layout Dialog Box, add the fields in the order you want them to appear on the
Label. Punctuation, space and new line buttons to format the Label can be used. Use the Textbox to
add text.

Click on Next> button to move to Step 4- Sort records dialog box. Here user can select the fields or
index tag in the order that he/she like to sort the records.

Click on Next>button to move to Step 5- Finish dialog box. We can Preview to verify our choices
before Finishing.

Press Esc key to close the Preview window and return to Finish dialog box.
Click on the Finish Button. The Save as dialog box appears. Type the name to be saved as in Save
Label as: Text box and click on Save button.

9.3 Printing Mailing Label


To print out mailing labels:

Open the required label file.

Insert the appropriate mailing labels in the printers paper tray.

Click on the Print button from the Standard toolbar.

Questions:
Q1. How to open the Label Layout Window?
Q2. How to print out mailing labels?
CHAPTER 10 : SORTING AND INDEXING

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.

Sorting helps in locating required records such as name of subscribers equally.


Sort command Format:
Sort To <new file> ON <field/A/B/C>,<fields>

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.

10.3.1 Types of Index


Visual FoxPRo lets to create two major types of index files. They are:

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.

Single Index files are of two types:

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

2. Non-compact: For creating non compact single index file:

Syntax: Use <Table>


Index On <expr> To <.idx file>

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.

To create a compound independent index file:


Syntax: Use<Table>
Index On <expr> Tag <tagname>
Of <. CDX file>

10.4 Sorting Vs Indexing

An Index file takes less disk space than a Sort file.

The Index command works faster than Sort command.

Index command also allows you to add new records keeping original order of records intact.

Sorting creates a new .dbf(database), indexing creates . idx or .cdx file.


10.5 Setting a Filter Command
Specifying, or setting a filter condition is an efficient way of selecting a group of records from a
table. After you set a filter, you need not worry about adding the criterion to each command. Records
that do not meet your criteria are filtered out indefinitely, until you remove the filter.
Syntax: Set Filter To < logical expression>

10.5.1 Creating a Filter Condition


To create a filter condition:

Open the table in the Browser window and click Table menu. Choose Properties to open the Work
Area Properties dialog box.

Click on the Data filter button

Double-click on the field to be affected.

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.

To verify that the expression is valid, click on verify.

Click OK button to return to the Work Area Properties dialog box.

10.5.2 Changing a Filter Condition


To change the filter condition:

Open the Expression Builder dialog Box again

In the fields list box, Double-click on the desired field.

Type the new expression: or choose the desired parameters from the Functions drop- down lists and
type the new condition.

Click OK.

10.5.3 Removing a Filter Condition


To remove the filter condition:

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.

Click Field Filterbutton. A field Picker dialog box appears.

Select Remove all Button to move the selected fields back to All fields box.
Click OK twice.

10.6 Use of Macro(s)


Macro substitution is a programming technique used in command files. The macro is just like
ordinary memory variable but has an ampersand(&) in front of it namely, & NAME, &FLD etc.
When Visual Foxpro encounters a macro in a command file, it replaces a macro with the contents of
the memory variable.

10.7 Memo Field Handling

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.

Working with command Window

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>

APPEND To display the table in Append mode


Use student
Append
EDIT or CHANGE To display the table in edit mode

Edit 5 (It display record 5 to edit)


Edit fields name ,roll_no
Or
Change fields name ,roll_no
or edit for name=john

BROWSE To display table in Browse mode

Use student
Browse
Or
Browse fields name,roll_no

REPLACE To change the contents in more than one record

DELETE AND RECALL

Delete record record_number


Or
Goto record_number

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

Recall record number


Once the records have been recalled then the physical marker from the record will be
removed.

Recall all : To recall all the records

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.

DISPLAY AND LIST

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

List name, city

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:

a. Sorting vs. Indexing

b. Ascending sorting vs Descending sorting

Q4. Explain Set Filter Condition.


CHAPTER 11: PROGRAMMING AND DEVELOPING
APPLICATIONS USING FOXPRO.

11.1 An Overview of Programming

A computer program is a series of instructions given to computer to execute them, in general one
after the other. These instructions are commands that cause the computer to perform specific
tasks. In Visual FoxPro command file is saved with an extension of .prg. Microsoft Visual
FoxPro is a powerful interactive data management tool, but you also can access the full power of
Visual FoxPro by creating applications.

11.1.1 Creating Files


To create a command file:

1. Click File menu and choose New..From the New dialog box that appears, choose Program radio
button and click on the New file button.

2. A program editor will appear. Alternatively, type and modify command <file name > in the
Command Window.

3. Type your program in this editor.

4. After you have invoke the commands, invoke File menu and select Save As..When Visual Foxpro
displays the Save As dialog box, type the filename to save the current document.

5. Click save button.

11.1.2 Running the Program from the File.

We can execute the program by selecting DO from the Program menu and selecting a program from
the Do dialog box.

Alternatively, type DO <file name> in the Command Window.

Basic Programming Concepts

When you write a program, you can store data and manipulate it with a series of instructions.
Data and data storage containers are the basic building blocks in programs, and you use
commands, functions, and operators to manipulate data and data storage containers.

Storing Data
Visual FoxPro provides numerous storage containers to extend ability to easily manipulate
data.
Data types determine how data is stored and how it can be used. You can multiply two
numbers together, but you can't multiply characters. You can print characters in uppercase,
but you can't print numbers in uppercase. Some of the primary data types in Visual FoxPro
are listed in the following table.

Data Types

Type Examples

Numeric 123 3.1415 7

Character "Test String" "123" "01/01/98"

Logical .T. .F.

Date {1998-01-01}

DateTime {1998-01-01 12:30:00 p}

Data Containers

Data containers allow you to perform the same operations on multiple pieces of data. For
example, you add the hours an employee has worked, multiply them To perform these operations
for every employee If you store this information in containers, and perform the operations on the
containers, you can just replace the old data with new data and run the same program again

Main containers for data in Visual FoxPro

Variables Single elements of data stored in your computer's RAM (Random Access
Memory).Table
To create a variable, store a value to a named Visual FoxPro element using
the STORE command or the =
Records Multiple rows of predetermined fields, each of which can contain a
predefined piece of data. Tables are saved to disk..

To create records, use the INSERT - SQL command or the APPEND command.

Arrays Multiple elements of data stored in RAM.


An array can be created using the DIMENSION or DECLARE command and
assign a value to each element by specifying the element using the array name and
the element's position, or subscript.
Variables:

Variables are referred to by their assigned names so that you cab refer to the required
variables by name and use it in calculations or for some other application.

For naming a variable, follow the same rules as are used for naming a field.

Variable name must contain only letters, numbers, and underscores, and must begin with a
letter.

Although a variable name can begin with the underscore (_) character, it is advisable to avoid
it.

Variable play very important role in programming:

a) Collecting and sorting inputs.

a) Preserving data from a table record.

a) Storing the results of calculations for the future use.

a) Storing individual items of information that must be globally available throughout an


application.

Creating and using Variables:

There are mainly four types of variables used in Visual Foxpro.

Character Variables: Character variables store strings of characters, which can be letters, numbers
of combination of both.

Numeric Variables: Numeric Variables are used to store numeric values such as whole or decimal
numbers.

Date Variables: Date Variables store date values written in MM/DD/YY format

Logical Variables: Logical Variables contain a logical value of True or False or Yes or No.

Creating Variables:

Variable can be created in two ways:

1) Using the STORE Command:


The format for STORE command is:

STORE<expression> TO <variable_name>

For example:

STORE 0 TO AMT

This assigns a numeric value o the variable AMT.

2) With the assignment (=) operator:

The format is:

variable=expression

For example:

AMT=0

This will assign a numeric value 0 to AMT.

For Example

User can use any of the following commands to create a variable Name
Store Patrick to NAME
Store Patrick to NAME
Store {Patrick} to NAME
User can perform the same result in the following format also:
NAME=Patrick
NAME= Patrick
NAME= {Patrick}

Example

Store (11/05/70} to b_day


Or
B_day=11/05/70
Store .T. to choice
Or
choice-=.T.

Displaying and Manipulating Information with ?/?? Commands:

The ? and ?? Commands are used to ask Visual Foxpro to display particular data on the
screen.
You can use ?/?? Commands to display a field, memory variable, a constant, result of a
Visual Foxpro function etc., or even combination of these.

The difference between ? And ?? Command is that the ? Command issues a carriage return
before printing the expression list, so it is positioned one line below the previous item
displayed.
The ?? Command does not include a linefeed and carriage return before the display, so the
subsequent value is displayed on the current line.

For example:
? Enter Name:
?? Name
?Enter Salary
?? Salary

If you type ? Or ?? Commands preceded by a SET PRINT ON command, then the output is
printed by a printer.

For Example:

SET PRINT ON
? Enter Name:
?? NAME
?Enter Salary:
??Salary
Set Print Off

Functions And Operators

OPERATORS

An operator in visual FoxPro specifies an operation to be performed on operands to give value. An


operand is an entity on which an operator acts.
Operators are as follows:

Mathematical Operators: - ^ / * + -

Relational Operators : < <= > >= ==

Assignment Operator : =

String Operators: String operators are used to combine two or more character strings known
as concatenation.
The + is used to combine strings including blanks e.g Raja+ Ram= RajaRam

Logical Operators: .AND. .OR. .NOT.


FUNCTIONS

Functions are one of the fundamental elements of visual basic. They are infact small
programs that perform tasks like testing and processing.
A function is identified by parenthesis the end
For example
Upper() function
FoxPro has more than 300 in-built functions plus user can defined its own functions also
which are known as user defined functions.

In-BUILT Functions

ALLTRIM(): Removes leading and trailing blanks from a character expression.


?AllTRIM(character_string)

ASC(): Returns the asc code


Asc(character_string)
?Asc(A) = 65

CHR(): Returns the character whose ASCII code is same as the value of numeric expression
CHR(numeric_expression)
?chr(65) = A
ISLOWER() : Returns True (.T.) if the first character in a string is a lower case alpha
character
Example ?ISLOWER(john) = .T.

ISUPPER() : Returns True (.T.) if the first character in a string is a Upper case alpha
character
?ISUPPER(John) == .T.

PROPER() : The function returns a character expression capitalized as appropriate for


proper names
proper(character _expression
?proper(computer) = Computer
Replicate() : The function returns a character string resulting from repeating a character
expression to a specified number of times
? Replicate(Hello,3) HelloHelloHello

LEN() : The function returns the length of the character expression


?LEN(HELLO) 5

LOWER(): Returns specified expression in lower case letters


?LOWER(HELLO) hello

SUBSTRING(): The function returns specified number of characters from a given


expression
?SUBSTRING(graphics,1,5) graph
USER DEFINED FUNCTIONS

Apart from built in functions user can also define and write programs as functions to do a task
relevant to their programs

SYNTAX:

Function (function-name)
Commands
Return (expression)
End function

Example:

function star
str=space(20)
for a= 1 to 20
str=alltrim(str) + *
?str
Return str
endfunction

Creating Array Variables:

To create an array varaible, use DECLARE and DIMENSION statement.

The syntax for this is:

DECLARE array name [number of rows[,number of columns]]

Or

DIMENSION array name [number of rows[,number of columns]]

To declare one dimensional array containing 7 elements and named WEEK, as shown below:

DECLARE WEEK[7]

Or

DECLARE WEEK(7)

Or
DIMENSION WEEK[7]

Store 24 to Week(1)
It store 24 numeric value in the first element of the array week
To Display the output
DISPLAY MEMORY LIKE WEEK

Getting input from the user:

There are two commands namely ACCEPT and INPUT commands that allow you to get
data from the keyboard.

When you use either ACCEPT or INPUT commands, you enclose the prompt to be asked in
apostrophes() or double quotes().

You also need to provide a variable to store the answer to the question.

The INPUT command is very similar to the ACCEPT command.INPUT command is used to get
numeric values from the user .It shows a prompt for the user and then accepts number from the user
through the keyboard

Accept Enter your name: To Myname


Input Enter your Basic_Pay: To BP

INPUT Enter your salary to salary


?salary

For example:

Accept Enter Your Name: To name

After typing this you will get a prompt on the screen.

Visual Foxpro will leave the prompt on the screen until the user types the name.

Type any name and press Enter.

After you press enter, the command window appears because the program is over.

Type: ?name and then Enter.

The users name will be displayed on the screen.

The ACCEPT command is used to get values from the user through the keyboard
ACCEPT Enter your name to name
?name
@...SayGet command:

You can also use a combination of @, Say,Get and Read commands to prompt the user to
enter the values from the keyboard.

The @ command allows you to perform many things such as displaying information,
inputting data in the fields/variables, clearing selected screen and designing custom screens.

For example: To displayEnter your name in row 5 and column 10 type the following command:
NAME = SPACE(20)
Clear
@5,10 SAY Enter Your Name GET NAME
READ

Here NAME=SPACE(20) creates a variable called NAME that contains 20 blank spaces

Examples
Set printer on
? Enter name
??NAME
? Enter salary
??Salary
Set printer off

11.2.1 Variables
Variables: Variable is a memory location within the computer that is used to store data temporarily.

Variables play very important role in programming in:

1. Collecting and storing inputs

2. Preserving data from a table record

3. Storing the results of calculations for future use.


1. Storing individual items of information that must be globally available throughout an
application.

There are mainly four types of variables used in Visual FoxPro.

Character Variables: Character variables store strings of characters, which can be letters, numbers
of combination of both.

Numeric Variables: Numeric Variables are used to store numeric values such as whole or decimal
numbers.

Date Variables: Date Variables store date values written in MM/DD/YY format

Logical Variables: Logical Variables contain a logical value of True or False or Yes or No.

Variable can be created in two ways:

1) Using the STORE Command:

The format for STORE command is:

1)

STORE<expression> TO <variable name>

For example:

STORE 0 TO AMT
This assigns a numeric value o the variable AMT.

2)With the assignment (=) operator:

The format is:

variable=expression

For example:

AMT=0

This will assign a numeric value 0 to AMT.

11.2.2 Creating Array Variables


In addition to creating simple memory variables, Visual FoxPro lets to create a special type of
memory variable called an array. In an array, variables are arranged in a pattern of rows and
columns.

To create an array variable, use Declare or Dimension statement:

Syntax:

DECLARE array name [number of rows[, number of columns]]

Or

DIMENSION array name [number of rows [,number of columns]]

11.2.3 Simple Output Using ? Command

The ? displays the specific values that had been stored in the memory variable.

Syntax:

? MNAME, CHOICE, AMT


KEYWORDS USED IN PROGRAMMING

1.Set talk ON / OFF : set talk on/off determines whether or not FoxPro displays response to certain
commands on the screen or window

.2.Set Printer ON / OFF: Enables or Disables output to the printer.

3.WAIT () : Pauses the execution of the FoxPro command or program and display a message. FoxPro
resumes operation on pressing a key or clicking the mouse

1.PROMPT: Returns the prompt text of a pad chosen from a menu bar or an option chosen from a popup

11.2.5 @..SAY..GET Command


@, GET, SET commands are used to prompt the user to enter the values from the keyboard. The @
commands allow to perform many things such as displaying information, inputting data in the
fields/variables, clearing selected screen and designing custom screens.

11.3 Picture Clause


The picture clause restricts entry to specify characters and it validates but not values.
Symbol Meaning
A Accepts only alphabetic
characters
L Accepts only Y (yes) or N
(no)
N Accepts letters and digits
X Accepts any character
9 Accepts only digits or sign
# Accepts digits, banks and
sign
! Converts lowercase letters to
uppercase
$ Displays currency symbol
. Specifies decimal point
precision
, Left of the decimal
For example
User want to get emp_code must begins with an alphabet and has three digits that we can rite with
picture clause
A999
Control Flow:

Control Statements allow you to change the sequence of instructions for execution.

Control Statements:

1.Looping Statements

2.Selection Statements

Looping:

Repeating a step or a number of steps of a program for a specified number of times or until a
condition is met, is known as looping or iteration.

Iteration logic is used when one or more instructions may be executed several times depending on a
condition.

Visual FoxPro provides three loop commands.

There are:

a)DO WHILE..ENDDO
b)SCANENDSCAN
c)FORENDFOR

a)DO WHILE..ENDDO

SYNTAX:

DO WHILE <logical exp>


.
ENDDO

Each time the program reaches this DO WHILE command, it checks to confirm if the logical
expression evaluated is true.

If it does, the program executes the commands that follow.

When it gets to END DO, it loops-back.

Example
Use employee
Set talk off
Set printer on
Do while .NOT. EOF()
If basic>3000
?name,desig
?? Basic
Endif
Skip
Enddo
Set printer off
Set talk off

b) SCANENDSCAN

SCANENDSCAN is another very useful structure for programming in Visual Foxpro.

A SCAN loop acts like a DOWhile loop.

It reads a table file sequentially.

The syntax for command is:

SCAN [scope][FOR condition] [WHILE condition] [commands]

ENDSCAN

Example

Use student
Scan for stud_name= JOHN
?Name + stud_name
Endsacn

ForEnd For
ForEnd For executes a set of statements within a loop for a specified a number.

You can use a memory variable as a counter to determine how many times Visual Foxpro
executes the statement inside the loop.

The syntax of the command is:

FOR <memvar> = <expN1> TO <expN2> [STEP<expN3>]


Example

To display odd number series 1,3,5,7,9


For counter=1 to 10 step 2
?counter
Endfor

Or

For counter=1 to 10
?counter
Endfor

Endless Loops:
Improper loop logic is a very common error in Visual FoxPro programming.

For example, in the following program segment, the condition will never change.

Hence the following loop will execute indefinitely.

X=0
DO WHILE X=0
Statements
END DO

Selection:

Selection is used for making decisions. It is used for selecting the proper path out of the two or
more alternatives paths in the program logic.

1)IfElseEndif

The syntax for this selection statement is:

IF condition <list of commands>


Else<list of Commands>
EndIF

If..Else..End if evaluates a condition and executes the block statements immediately after IF and
before ELSE, if it is true.

Example

Clear
?
Accept Enter a number between 1 and 4 to n
If n=1
?you typed one
Else
If n=2
?you typed two
Else
If n=3
?you typed three
Else
?wrong selection :enetry not between 1 and 4
Endif
Endif
Endif
Wait

IIF():

IIF() is the functional form of an IFElse..Endif structure, which has three parameters.

The first defines the logical condition, the second is the expression returned if the conditions is
true, and the third is the one returned if it is false.

The syntax for this function is:

IIF(condition, expression1, expression2)

Example

? IIF(Result=p, pass, Fail)

Do CaseEnd Case:

The Do Case. .End Case constructs works similar to If/Else ladder.

The program looks through the Case statements to find if correct.

If it is correct, the program executes the code following the Case Statement and after it is done
with that block of code, goes on to the code following ENDCASE.

Syntax:

Do Case
Case condition1
<list of commands>
Case condition 2
<list of commands>
Case condition 3
<list of commands>
________________________
________________________
Otherwise
<list of commands>
End Case

Example

Clear
?
Accept enter number between 1 and 3 to n
?
Do case
Case n=1
?You typed one
Case n=2
?You typed two
Case n = 3
? You typed three

Otherwise
? Wrong number: enter between 1 and 3

Endcase
?
WAIT

You might also like