



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























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
Creating a database There are two ways to create a database in FoxPro:
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
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
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
@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