Docsity

Foxpro programming summary notes, Study notes of System Programming

Toggle sidebar
bg1
Introduction to Visual FoxPro
Database
This is a collection of electronic and organized information.
Database is organized into rows and columns, the rows in a database are
called records and columns are called fields (fieldnames).
Database models
A database model allows the user to arrange information in a database. They
show how data is arranged in a database.
Types of database models
1. Relational database model
Information is arranged in rows and columns. This information is drawn
from different tables linked by a common field.
2. File management system
This is a traditional method of storing information in a database where
data is arranged sequentially.
3. Hierarchical database model
This is a model where information stored in a database has a parent
child relationship. A pointer (key) is used to access information from a
database.
4. Network database model
Records and links represent data. It allows modeling of many to many
relationships.
Designing a database
Terms used in FoxPro
1. Data
This is the information that goes into a database for processing.
2. Fields
These are attributes or categories of information to be displayed in a
table.
FOXPRO TUTORIAL
BY: KABA N. DANIEL
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

Partial preview of the text

Download Foxpro programming summary notes and more Study notes System Programming in PDF only on Docsity!

Introduction to Visual FoxPro

Database This is a collection of electronic and organized information. Database is organized into rows and columns, the rows in a database are called records and columns are called fields (fieldnames). Database models A database model allows the user to arrange information in a database. They show how data is arranged in a database. Types of database models

  1. Relational database model Information is arranged in rows and columns. This information is drawn from different tables linked by a common field.
  2. File management system This is a traditional method of storing information in a database where data is arranged sequentially.
  3. Hierarchical database model This is a model where information stored in a database has a parent child relationship. A pointer (key) is used to access information from a database.
  4. Network database model Records and links represent data. It allows modeling of many to many relationships. Designing a database Terms used in FoxPro
  5. Data This is the information that goes into a database for processing.
  6. Fields These are attributes or categories of information to be displayed in a table. FOXPRO TUTORIAL 1
  1. Reports This is a summary of information.
  2. Field type (data type) Shows the type of information to be stored in a particular field.
  3. Width (Field size) This is the number of characters to be entered in a certain field. Phases of database design
  4. Data definition Determines what important fields to be included in your database. Determines the exact fields that will be stored in a database. E.g Housing company database * Customer Name * Gender * Age * Room Number etc.
  5. Data refinement Review the list of fields on your initial list so that the fields can form an accurate description of the types of data that will be in the database. e.g. * Member Last Name * Member Middle Name * Member First Name * Gender * Room Number * Town Code FOXPRO TUTORIAL 2

Creating a database There are two ways to create a database in FoxPro:

  1. Using command window by entering Create Filename
  2. Using File Menu The command window The command window is used to allow users create database objects and display information they want from the database. Example 1 Creating Housing Company database Items table
    • Stock No
    • Description
    • Cost Orders table
  • CustNo
  • stockNo
  • Quantity
  • Date Customers table
  • LastName
  • MiddleName
  • FirstName
  • Gender
  • Address
  • City
  • Citycode
  • CustNo FOXPRO TUTORIAL 4

Code Create items Create orders Create customers Alternatively, you can create tables in the Command window or a program file using standard SQL commands like: CREATE TABLE Customers; (CustomerID I, ; Customer C(20), ; Address C(20)) CREATE TABLE Materials; (MaterialID I, ; MaterialName C(20), ; SaleUnit C(10), ; UnitPrice Y) CREATE TABLE Orders ; (OrderID I, ; CustomerID I, ; OrderDate D, ; PayDate D) CREATE TABLE OrderDetails ; (OrderID I, ; OrderDetailID I, ; MaterialID I, ; nitsSold N(10, 2) Adding records to a table (file) This is done using either file menu or command window. Using the command first activate the database by typing USE “ “ command and then type APPEND command. e.g. Use items Append FOXPRO TUTORIAL 5

E.g. Freeze fields Deleting records Use DELETE and PACK commands to prepare records for deletion at a later time. These commands allow the user to mark records for later removal from database. Also uses LOCATE command to find desired records and then use DELETE command to mark records for deletion. E.g. Locate for LastName=” “ Delete Or Delete record 4 To reverse the process use RECALL command. E.g. Recall record 4 or Recall all Deleting files This is removal of files (database) from memory. Use DELETE command to remove databases from the computer memory. Delete items.dbf Replacing records We use CHANGE command to change or replace records. E.g. Replace all city with”Nairobi” for city=”Kampala” Or Change LastName to “Kennedy” for LastName=”Kenny” FOXPRO TUTORIAL 7

Sorting records This is the process of arranging records in a predetermined sequence.ie ascending or descending order. We use SORT command to sort records in a database. e.g. Use customers Sort on LastName to customers Use customers List LastName You can also specify the type of sort wanted i.e. Ascending or descending order. e.g. Sort on LastName /D to customers Use customers List LastName Sorting multiple fields Use customers Sort on lastname, middlename, firstname to customers Use customers List LastName, middle name, first name Indexing records Index contains information about the address of individual records in database. FOXPRO TUTORIAL 8

This is a link between one or more tables in a database. There are three major types of relationships

  1. One to one relationship
  2. One to many relationships
  3. Many to many relationships Be4 setting relation is created, set index in the fields. Relating two or more tables A. Items table StockNo Description Cost 2001 Leather handbag 1000 2002 Casing 3000 2003 Mirror 4000 2004 Shoes 6000 2005 Books 3500 2006 Soap 1500 B.Orders table CustNo StockNo Quantity Date 9001 2001 10 03/05/ FOXPRO TUTORIAL 10

C. Customers Table

LastName MiddleName FirstName Gender Address City Citycode CustNo Kaba Omar Daniel Male P.o.Box 3 Kampala 40100 9001 Zablon Kerubo Mary Female P.o.Box 6 Nairobi 40200 9002 Nyakundi Edward Kenny Male P.o.Box 8 Harare 40300 9003 Onkundi Pamela Barare Female P.o.Box 9 Abuja 40400 9004 Jennifer Moraa Bonda Female P.o.Box 1 Kola 40500 9005 Mary Dennis Mogere Female P.o.Box 7 Lusaka 40600 9006 Kebati Kefah Dancan Male P.o.Box 4 Kigali 40700 9007 Code Close databases Select 1 Use items Index on StockNo to bystock Select 2 Use orders Index on CustNo to Bycust Select 3 FOXPRO TUTORIAL 11

Close the command file and open command window and type DO command followed by the name of the command file then press enter key. e.g. DO Test Compiling FoxPro programs FoxPro programs runs on compiled basis rather than on interpreted basis. Interpreters convert line by line in a program into machine code. The compilers translate the entire program into object code once. Constants This is an item which does not change during execution, fixed data items in FoxPro. Variables These memory locations in a computer that store data awaiting execution. They are referred to using their names. Rules for creating variables

  1. Should be ten or fewer characters
  2. Must consist of only letters, numbers and underscores.
  3. Variables names cannot be commands or function names we use STORE command to assign data types to a variable. Syntax Store expression to variable name Example 1 Store 200 to salary Or Salary = 200 Expression FOXPRO TUTORIAL 13

A combination of one or more fields, functions, operators, variables and constants to perform an operation. Sum =a + b Net Pay = Gross pay – Deductions Operators These are symbols that are used to work on related values to produce a single value. Types of operators

  1. Arithmetic operators Used to mathematically produce numeric results. * Addition (+) * Subtraction (-) * Multiplication (*) * Division (/) * Exponentiation (^) * Modulus (Mod)
  2. Relational operators Used to compare and relate character strings. * And * Not * Or * Between
  3. Logical operators
    • Less than (<)
    • Greater than (>)
    • Less than or equal to (<=)
    • Greater than or equal to (>=) FOXPRO TUTORIAL 14

@6,15 say "product of two numbers" @8,10 to 15,50 double @10,14 say "Enter num1" get a @12,14 say "Enter num2" get b Read d=ab @14,14 say "product is is" +str(d,4,0) Area of a circle store 0 to a,d @5,10 to 7,50 double @6,15 say "Area Calculation for Circle" @8,10 to 15,50 double @10,14 say "Enter Radious of Circle" get a read d=22/7aa @12,14 say padr("Area of Circle",15) +str (d,6,2) Area Calculation for Triangle store 0 to a,b,d set clock to 4, @5,10 to 7,50 double @6,15 say "Area Calculation for Triangle" @8,10 to 15,50 double @10,14 say "Enter Base of Triangle " get a @12,14 say "Enter Height of Triangle" get b read d=1/2a*b @14,14 say "Area of Triangle" +str(d,6,2) Interest Calculation FOXPRO TUTORIAL 16

set clock to 1, store 0 to rate,ammount,time,interest,total @2,8 to 4,60 double @3,25 say "Interest Calculation" @5,8 to 20,60 double @7,10 say "Enter Principal Ammount" get ammount @9,10 say "Enter Time " get time @11,10 say"Enter Rate of Interest " get rate read interest=ammounttimerate/ @13,10 say "Simple Interest: " +(str(interest,10,2))+" Kshs." total=ammount+interest @15,10 say "Total Ammount with Interest: "+(str(total,10,2)) +" Kshs." Find Sum/Count of Even/Odd numbers from the 10 numbers entered clear i= sumeven= sumodd= te= to= do while i<= input "enter a number :" to n rem= n % 2 if rem= ?"Even" te=te+ sumeven=sumeven + n else ?"Odd" to=to+ sumodd=sumodd + n endif i=i+ enddo FOXPRO TUTORIAL 17

Example 1 store 0 to age set clock to 4, @5,10 to 7,50 double @6,15 say "getting age of a student" @8,10 to 15,50 double @10,14 say "Enter your age" get age read if age >=60 then @14,14 say "You are old retire" else @14,14 say "you are young work hard" endif

2. DO CASE… CASE… ENDCASE STATEMENT This is a selection control structure that tests a condition and evaluates to return a true or false value. It is used when you have different levels of logical order to evaluate. Example store 0 to score @5,10 to 7,50 double @6,15 say "GRADE CALCULATION" @8,10 to 15,50 double @10,14 say "ENTER YOUR SCORE" get score read Do case FOXPRO TUTORIAL 19

case score >= 80 @ 14,28 say "A" case score >= 70 @14,28 say "B" case score >= 60 @14,28 say "C" case score >= 50 @ 14,28 say "D" case score <= @14,28 say "E" endcase Repeat statements

3. Do While…………Enddo This is repetition control structure that is used to keep something going on until the statement is true Example Position = 10 Number = 0 Do While Number <= 10 @ Position, 5 say Number Number = Number + 1 Position = Position + 1 Enddo FOXPRO TUTORIAL 20