Professional Documents
Culture Documents
Chaniyara
Basic commands
Creating a Program
Input and Output Statements in Foxpro
Control Structures in Foxpro
Creating menu in Foxpro for DOS
Simple Journal Entry program
Simple Ledger creation & Posting Program
Trial Balance Program
Balance Sheet Program
Page 1 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
COMMANDS IN FOXPRO
Syn:
use <dbname>
Ex:
use book
Use
Close all
Syn:
crea <dbname>
create <dbname>
Ex:
crea book
Modify Structure:
Page 2 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Modify structure
(Or)
Modi stru
APPEND
Syn:
append
[Blank]
[From <dbname>]
Ex
Append
Append Blank
- To add blank records.
Append from first.dbf
- To add the records from FIRST.DBF to SECOND.DBF
- Same Structure is required for these databases
DISPLAY
Syn:
Display
[All]
[Structure]
[Status]
[Memory]
Ex:
Display
Display All
Display All Records in page wise.
Page 3 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Display Structure
Display Memory
Set stat on
Edit
GO TOP
GO BOTTOM:
Go
To go to a particular record
Syn:- GO <recordno>
Eg:- GO 8
Go to record 8
List
Syn:
list
Page 4 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Creating a Program
PROGRAM
A Program is a set of instructions used to achieve the desired output.
Writing Programs
* FoxPro has powerful built-in editor for writing and editing.
* It can be invoked from the command window by using the MODIFY COMMAND.
Syntax:
MODIFY COMMAND <prenames>
Example:
Modify Command journal
(This program will automatically save with the extension .PRG)
Press CTRL + W - To save and close the program window
Executing Program
Programs can be executed by DO command.
Syntax:
DO <prgname>
Example:
Do journal
When compile the executed file the FoxPro creates an object code program with .FXP
extension. If there are any errors, creates a file an .ERR extension.
INPUT command
Page 5 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
It is used to accept Numeric input from the user and store it into a memory variable.
Syntax:
INPUT [<char exp>] TO <memvar>
Example:
Store 0 to eno
INPUT "Enter your Enrollment No : " TO eno
? Eno
ACCEPT command
It is used to accept character input from the user and store it into a memory variable.
Syntax:
ACCEPT [<char exp>] TO <memvar>
Example:
Store space (15) to NAM
ACCEPT "Enter the Name: " to NAM
? "Entered name: NAM
Example 2
clear
SET TALK OFF
Accept "Enter your nane :" to nam
Input "enter your Age : " to age
Accept " enter your city :" to cit
Accept "Enter your Mail id : " to mail
? "******************************************"
? "NAME :: " ,nam
? "AGE :: " ,age
? "CITY :: " ,cit
? "MAIL ID:: " ,mail
? "******************************************"
Page 6 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Syntax:
Input
@row,column | say <char_exp> get <mem_var>
Output
@row ,column | say <char_exp> get <mem_var>
Clear
@row, column to row, column clear
Clear all
Ex
@5, 5 clear to 20, 20
Box Command
@row1, column1 to row2, column 2
Picture clause
PICTURE clause is used to control of display or the information to be accepted.
@..SAY...GETS PICTURE CODES:
A - Allows only alphabets
9 - Allows only digits, signs for numeric data
N - Allows Letters and Digits
# - Allows Only Digits, Blanks and Signs
X - Allows any Character
L - Allows any Logical Data T, t, F, f, Y, y, N, n
Y - Allows Only Y, y, N, n
! - Converts letters into uppercase.
* - Displays asterisk in place of leading zeros.
, - Display the comma
Page 7 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 8 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
^ Displays numeric data using scientific notation. Used with numeric data only.
Example:-
Clear
Store 75815 to amt
@6,20 say amt function ^
$
Displays data in currently format. the currency symbol appears before or after the field value
depending on the current setting of set currency. used with numeric data only.
Example:-
Clear
Store 75815 to amt
@6,20 say amt function $
Picture expression can include the following characters:-
Page 9 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
If.else.endif:-
The commands between if..end if will be executed only if condition is satisfied, otherwise
the next statement is executed. For every if there must be an end if. Every is matched with the
nearest unmatched if.
Syntax:-
If<condition>
<Command sequence-1>
Else
<Command sequence-2>
End if
Example 2
clear
Store 0 to x,y
@5, 5 say " Enter the First value: " get x
@7,5 say " Enter the Second value: " get y
Read
IF x > y Then
@10, 10 say str(x) + is Greater than + ltrim (str(y))
Else
@10, 10 say str(x) + " is lesser than " + ltrim (str(y))
Endif
Example 3
clear
Store space(1) to x,ch
@5, 5 say " Enter any Alphabet: " get x
Read
Page 10 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 11 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
case day = 4
@10,10 say "WEDNESDAY"
case day = 5
@10,10 say "THURSDAY"
case day = 6
@10,10 say "FRIDAY"
case day = 7
@10,10 say "SATURDAY"
OTHERWISE
@10,10 SAy "Invalid Input"
EndCase
FOR LOOP
Syntax
FOR <memvar> = <initial value> TO <final value> STEP <no>
................
................
ENDFOR
Example: 1
CLEAR
FOR I = 1 TO 10
?I
EndFor
Example: 2
To print the EVEN nos from 2 to 50
CLEAR
FOR I = 2 TO 50 STEP 2
?I
EndFor
Page 12 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 13 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 14 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 15 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
ROW = 6
DO WHILE .NOT. EOF()
@ROW,6 SAY DATE
@ROW,19 SAY PART1 +[ DR]
@ROW+1,19 SAY [TO ]+PART2
@ROW+2,19 SAY [ (BEING ] +NAR+ [)]
Page 16 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 17 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
if p>r
br = p
else
br = r
endif
Page 18 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
if cs > ds
bl = cs - ds
mamt = cs
@r+1,11 say "To bal b/d"
@r+1,26 say bl
@br+5,50 say "By Bal c/d"
@br+5,65 say bl
else
bl = ds - cs
mamt = ds
@p+1, 50 say "By bal c/d"
@p+1, 66 say bl
@br+5,11 say "To Bal b/d"
@br+5,26 say bl
endif
Page 19 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 20 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
l=l+1
endif
cs = cs + credit
ds = ds + debit
skip
enddo
if cs > ds
sus = cs - ds
@l,7 say "Suspense A/c"
@l,22 say sus
else
if ds > cs
sus = ds - cs
cs = ds
@l,7 say "Suspense A/c"
@l,35 say sus
endif
endif
Page 21 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
Page 22 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
grloss = abs(grpro)
grpro = 0
@11,40 say "By Gross Loss:"
@11,68 say grloss
gramt = tdeb
else
@11,2 say "To Gross Profit:"
@11,30 say grpro
gramt = tcr
endif
@12,2 say repl("-",75)
@13,30 say gramt
@13,68 say gramt
@14,2 say repl("-",75)
wait""
clear
Page 23 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
**Balance Sheet**
store 0 to ass, land, cashb, cashh, rsrv, cap, aint
@2,25 say "Balance sheet for the year Ended"
@3,2 say repl("-",75)
@4,3 say "Liablities Amount"
@4,48 say "Assets Amount"
@5,2 say repl("-",75)
@6,2 say "Capital"
@6,20 get cap
@7,2 say "Add. Int"
@7,20 get aint
read
if netpro > 0
@8,2 say "(+)Net pro"
@8,20 say netpro
cap = cap + aint + netpro
else
@8,2 say "(-)Net Loss:"
@8,20 say netloss
cap = cap + aint - netloss
endif
@8,30 say cap
Page 24 of 25
Foxpro 2.6 Samples Mayurkumar M. Chaniyara
read
liab = rsrv + cap
@6,48 say "Cash in Hand:"
@6,68 get cashh
@7,48 say "Cash at Bank:"
@7,68 get cashb
@8,48 say "Land:"
@8,68 get land
ass = land + cashb + cashh
@10,2 say repl("-",75)
@11,30 say liab
@11,68 say ass
@12,2 say repl("-",75)
wait window
return
Page 25 of 25