Program
Program is the series of commands typed in a required sequence saved and stored in a program file.
What is FoxPro Program?
FoxPro program is an ordinary text file containing one or more FoxPro commands, each typed on a separate line. A file containing FoxPro commands is known as command file or a program. File Extension for FoxPro program is .prg.
FoxPro ignores blank lines in a program. So blank lines can be freely used to separate groups of commands that make up separate functional modules. When multiple files of command are used to perform various tasks, collection of files are referred to as an application.
Commands given at command window forms a part of FoxPro language. FoxPro language supports additional commands that are valid only when used within a program and they wont work in command window, they are program only commands. Syntax:
Modify Command <Program Name> OR
Modi Comm <Program Name>
Modi Comm Prg1
When used FoxPro assumes the file extension is .prg. A FoxPro programs can be executed by DO FILE NAME command. Syntax:
Do <File Name>
Do Prg1.
Memory Variables
Memory variables are temporary quantities that can be stored in the memory. They store values which can be later used in calculations or to store results of the calculations. E.g.
Store 15 to num1
Store 25 to num2
Store 0 to sum
Num1 =15
Num2=25
Sum=0
Comments
Comments are used to add explanatory text and serve as internal documentation. Comments are ignored in a program while compilation, so that disk space is not wasted and execution of program is not slowed.
FoxPro treats the line as a comment when program line begins with an (*) or with a keyword NOTE. Thus ( * ) character and keyword NOTE are used to add comment lines before actual FoxPro commands in a program. Comments can be added at the end of program line by introducing the comment with two ampersand (&&). Hence there are three ways of giving comments ( * ), NOTE and &&. For Example
* Program Name : F1.prg
NOTE This is the First Program
Use Flights && Opens the table.
Setting the Environment
Every FoxPro program includes all commands required to establish the working environment and restore it to its prior state before the program terminates execution. Which can be achieved by issuing some sort of set commands at the beginning of each program. For Example:
Set Notify ON/OFF
Enables the display of certain system messages.
Set Talk Window
Directs the display of system messages to an user defined window instead of system window.
Set Talk ON/OFF
Enables display of command results.
Screen Input/Output
@ say Command is used to place data at a particular screen location and to display data stored in fields or memory variables. This command displays output at a specified row and column position. For Example:
@ 2,10 say “Hello”.
@ get Command is used to retrieve data.
Options (Functions)
Including function clause affects the entire expression. For Example:
Mname = “eric”
@ 10,10 say Mname function “!”
Mno = 10
@ 10,10 say Mno function “B”
Mprice = 100
@ 10,10 say Mprice function “$”
Font
Font option can be used to apply fonts to the text. For Example:
@ 2,2 say “Hi There “ Font “courier”,16.
Style
Style clause is included to specify a font style for @---------Say output. For Example:
@ 2,2 say “Hi There “ Font “courier”,16 style “BI”
Other Styles are as follows:
B = Bold N = Normal S = Shadow
I = Italic O = Out Line - = Strikethrough.
Q = Opaque T = Transparent U = Underline.
Mcode = Space(5)
@ 12,10 say “Enter Code“ Get Mcode function “A”
Read
This allows to enter alphabets characters only.
Picture Clause
Mcode = Space(5)
@ 12,10 say “Enter Code“ Get Mcode picture “A9999”
Read
Above code forces to enter a character followed by 4 numeric to form the contents of variable Mcode.
Default
Default expression determines the type of memory variable created and its initial value.
For Example:
Mcode = Space(5)
@ 12,10 Get Mcode default “A100”
Read
Range
Range clause is included with the character, date and numeric data to specify a range of acceptable values.
Range is not checked if the enter key is pressed without changing the memory variable, array element or field. For Example:
Mfare = 0
@ 12,10 Get Mfare range 1,1000
Read
This code forces to enter numbers from to 1 to 1000 only.
Valid
Valid option is used to validate the input. For Example
Store 0 to Mfare
@ 12,10 Get Mfare style “BI” valid Mfare>0;
message “Enter a Non-Zero and Non-Negative Number”
Read.
Error
Error option lets to specify a custom error message. It displayed when a valid clause evaluates to false(.F.) For Example
Store 0 to Mfare
@ 12,10 Get Mfare style “BI” valid Mfare>0;
message “Enter a Non-Zero and Non-Negative Number”
error “Invalid Input”
Read.
When
When allows or prohibits access to a get editing region based on the value. If the value is true(.T.) get editing region can be accessed and it is false (.F.) the get editing region can not be accessed. For Example
Store 0 to Mfare
@ 12,10 Get Mfare style “BI” valid Mfare>0 when .F.
Read.
This code causes FoxPro to skip Mfare field and so not store anything to it.
Using Say and Get together
Single set of co-ordinates should be specified if both say and get clauses are to be included. For Example
Store 0 to Mfare
@ 12,10 Say “Enter the Flight Fare : “ Get Mfare;
Style “BI” valid Mfare>0
Read.
Example 1:- A program to accept two numbers and to display its sum, product, division subtraction and average
Set talk off
Set stat off
Clear
No1=0
No2=0
Sum = 0
Product = 0
Subtract = 0
Division = 0
Average = 0
@ 10,10 say “Enter no 1 “ get No1
@ 12,10 say “Enter no 2 “ get No2
read
Sum = No1+No2
Product = No1*No2
Subtract = No1-No2
Division = No1/No2
Average = No1+No2/2
@ 14,10 say “The Sum is “ +str(Sum)
@ 16,10 say “The Product is “ +str(Product)
@ 18,10 say “The Subtract is “ +str(Subtract)
@ 20,10 say “The Division is “ +str(Division)
@ 22,10 say “The Average is “ +str(Average)
Example 2:- Accept a number from the user and display its square and cube Numbers.
Set talk off
Set stat off
Clear
No =0
Square =0
Cube =0
@ 10,10 say “Enter no “ get No
read
Square = No * No
Cube = No*No*No
@ 14,10 say “The Square is “ +str(Square)
@ 16,10 say “The Cube is “ +str(Cube)
Example 3: -Accept name, RollNo, Mark1, Mark2, Mark3, Mark4, Mark5, Mark6, Total, Average and display name, Total and Average of the Student
Set talk off
Set stat off
Clear
Name=Space(10)
RollNo=0
Mark1=0
Mark2=0
Mark3=0
Mark4=0
Mark5=0
Mark6=0
Total=0
Average =0
@ 12,10 say “Enter Name :” Get Name
@ 13,10 say “Enter RollNo :” Get RollNo
@ 14,10 say “Enter Mark 1 :” Get Mark1
@ 15,10 say “Enter Mark 2 :” Get Mark2
@ 16,10 say “Enter Mark 3 :” Get Mark3
@ 17,10 say “Enter Mark 4 :” Get Mark4
@ 18,10 say “Enter Mark 5 :” Get Mark5
@ 19,10 say “Enter Mark 6 :” Get Mark6
Read
Total = Mark1+ Mark2+ Mark3+ Mark4+ Mark5+ Mark6
Average=Total/6
@ 22,10 say “The Student is “ +(Name)
@ 24,10 say “The Roll No is “ +str(RollNo)
@ 26,10 say “The Total is “ +str(Total)
@ 28,10 say “The Average is “ +str(Average)
Example 4 :- Accept empno, Name, Basic, Dept and calculate TA, DA, HRA, PF, ESIC, and NetSal.
SET TALK OFF
SET STAT OFF
CLEAR
EMP_NO=000
EMP_NAME=SPACE(25)
DEPT=SPACE(20)
SALARY=000000.00
ESIC=0
@ 12,5 SAY "EMPLOYEE NUMBER:" GET EMP_NO
@ 14,5 SAY "EMPLOYEE NAME:" GET EMP_NAME
@ 16,5 SAY "EMPLOYEE'S DEPT"GET DEPT
@ 18,5 SAY "SALARY:"GET SALARY
READ
TA=SALARY *.02
DA=SALARY *.03
HRA=SALARY *.04
PF=SALARY *.12
ESIC = SALARY *.01
ITAX = SALARY *.4
NETSAL = (SALARY + TA + DA + HRA) - (PF + ESIS + ITAX)
@ 22,5 SAY "EMPLOYEE NUMBER:" +str(EMP_NO)
@ 24,5 SAY "EMPLOYEE NAME:" +(EMP_NAME)
@ 26,5 SAY "EMPLOYEE'S DEPT" +(DEPT)
@ 28,5 SAY "SALARY:"+str(SALARY)
@ 30,5 SAY "Travelling Allowance"+str(TA)
@ 32,5 SAY "Dearance Allowance:"+str(DA)
@ 34,5 SAY "House Rent Allowance:"+str(HRA)
@ 36,5 SAY "Providend Fund:"+str(PF)
@ 38,5 SAY "ESIC:"+str(ESIC)
@ 40,5 SAY "Net Salary:"+str(NETSAL)
No comments:
Post a Comment