Reports can be run within a program with Report form command. It offers a number of flexible options. Reports can be created using following options:
Create Report <Report Name> or by Report Writer
? Command
? (Single Question Mark) Command used for displaying contents of variables. It is used to display information on the Screen or Printer.
? “Computer Fundamentals”
? “First Chapter”
Where Single Question mark (?) evaluates expression and displays the result on the next line.
At
AT clause specifies the column number where result is displayed. AT also allows to position the fields from a database file in the report.
? “Hello World !!” AT 30
The above command will display Hello World!! On the next line at column 30.
?? Command
?? Command (Double Question Mark) displays output on the current line, at the current cursor position.
? “Hello”
?? “Every One”
The Result of the above command is:
Hello Every One
System Memory Variable
All system memory variables are public by default. They can be declared as private within our programs. Each system memory variable is used for specific purpose. Some of these system variables are:
_Wrap = .T.
Wrap causes output of a ? and ?? commands to Word Wrap between Left and Right Margin.
_Alignment = “”
Alignment can be of three values they are:
Right, Left and Center
By default alignment is only Left justified.
_Wrap = .T.
_Alignment = “Center”
? “FoxPro is a Programming Language”
_Lmargin =<ExpN>
Left margin can be set as per user requirement. It determines the number of columns to be left blank printing the text.
_Lmargin = 4
_Rmargin<ExpN>
Determines number of columns to be left blank to right of the printer text.
_Wrap = .T.
_Lmargin = 4
_Rmargin = 78
_PageNo
Page no determines or sets the current page no on the output.
_PageNo =1
_PageLength
This can be specified to determine the length of the page. An integer value from 1 to 32767 can be assigned to Plength.
_PageLength = 500
_PLength = 500
Control Break
In a Report it is necessary to group information based in some common criteria.
On Key Command
On Key Command can be used to trap specified key.
On Key label F1 Do Cancel
Syntax for Report is
Report
[Form <File> |?]
[Environment]
[<scope>]
[For <Expl 1>]
[While <Expl 2>]
[Heading <Expl C>]
[NoEject]
[Plain]
[Preview]
[To Printer [Prompt] | To File <File>]
[Summary]
Where
For clause is used to specify condition that must be met for records included in the report.
While condition should used along with an index to specify records to be included in the report while specified condition is true.
Environment option enables FoxPro to use same Environmental Settings that were in effect when report was saved.
Scope is optional (All, Next X, Or Rest) can be used.
Plain option drops system clock data and page numbers.
Heading option followed by a character expression, causes heading to appear at top of each page.
NoEject option cancels form feed that normally occurs when the To Print option is used.
To File option can be used to store output to a text file.
Summary option cancels normal display or printing of detail lines within a report.
Set Filter
Set filter command can be used to provide users with choices of conditions that apply to data printed with a report. Syntax:
Set Filter to [Condition]
Set Filter to Source = “Bombay”
Line and Column Numbers
_PlineNo determines current line number. It takes value from 0 through _Plength -1. Value stored in _PlineNo can not be exceed the value in _Plength.
_PlineNo
Is automatically set to 0 when command Eject Page is used.
_PcolNo
Determines current column number. Its value automatically incremented by FoxPro as it moves to next column. Column number can also be set by assigning a value to PColNo. It can take values from 0 to 255.
Directing Output to Printer
Output of ? and ?? commands are by default sent to Screen. To direct output to printer the command SET PRINTER ON is used. It directs all output not formatted by @ -- say to the printer.
SET PRINTER OFF Command directs output back to screen. If printer is not connected to your system, output can be redirected to file.
SET PRINTER OFF Command directs output back to screen. If printer is not connected to your system, output can be redirected to file.
Set printer to <File>
Before a report program starts printing the report, it should determine if printer is connected or not and if it is connected, whether it is on-line or not.
PrintStatus( )
This function is used to verify whether printer is connected or not, or whether it is online or offline. This function returns the logical True if printer is ready to accept output, otherwise it returns logical False value. So before directing the output to printer it is necessary to check whether printer is ready to accept output. Output could be redirected to a file after checking for printer status using the PrintStatus() function
If printstatus()
Set print on
Else
Set printer to out.txt à Output to a file
Set printer on à Output to a Printer
Endif
Reports (Example 1)
Set talk off
Set stat off
Set escape off
Set printer to out.txt
Set printer on
Use FL_Infor Order FL_Code
_Wrap =.T.
_Alignment = “Center”
_Lmargin = 4
_Rmargin=76
_PageNo=1
_Plength=66
? “Flight Details”
_Alignment = “Left”
? “Page No”
?? Ltrim (Str(_PageNo))
_Alignment = “Right”
??”Date :” +DtoC(Date())
_Alignment = “Left”
?Replicate (“-“,85)
***************Column Headings***************
? ”Flight Code” At 5
?? ”Flight Date” At 20
?? “Eco Seats” At 40
?? “ Exe. Seats” At 65
?Replicate (“-“,85)
Scan
? Flight_Code At 5
?? Flight_Date At 20
?? Eco_Seats At 40
?? Exe_Seats At 65
EndScan
?Replicate (“-“,85)
Wait Window
Clear
Use
Set print off
Set printer to
Set escape on
Return
Page Breaks
In multi page reports, column headings may need to be displayed on every page. After printing one page the printer must be advanced to next page. The PAGE HANDLER command specifies the command to be executed when a particular line number is reached. Usually procedure is executed when a particular line is reached. This procedure is used to advance the printer to the next page and print the column headings on the new page.
ON PAGE [at Line <ExpN> Command>]
FoxPro executes the specified command when value in _PLineNo is greater than the number specified in he At Line Clause while executing ? and ?? commands.
Disabling Page Handler
On page command disables page handler, so it must be specified while resetting the environment at the end of the programs. Example:
à On Page At Line 60 do NewPage
Procedure NewPage will be executed if the value in _PlineNo is greater than 60. Procedure NewPage will be used to advance the printer to a new page (Eject Page)and print the page number and column headings.
Example 2
Set talk off
Set stat off
Set escape off
Set printer to out.txt
Set printer on
Use Flights
On Page AT Line 60 do NewPage
_Wrap =.T.
_Alignment = “Center”
_Lmargin = 4
_Rmargin=76
_PageNo=1
_Plength=66
? “Flight Details”
_Alignment = “Left”
? “Page No”
?? Ltrim (Str(_PageNo))
_Alignment = “Right”
??”Date :” +DtoC(Date())
_Alignment = “Left”
?Replicate (“-“,85)
***************Column Headings***************
? ”Flight Code” At 5
?? ”Flight Date” At 20
?? “Eco Seats” At 40
?? “ Exe. Seats” At 65
?Replicate (“-“,85)
Scan
? Flight_Code At 5
?? Flight_Date At 20
?? Eco_Seats At 40
?? Exe_Seats At 65
EndScan
?Replicate (“-“,85)
Wait Window
Clear
Use
On Page
Set print off
Set printer to
Set escape on
Return
Procedure NewPage
_Alignment = “Center:
? “Flight Report “
Eject Page
? ”Flight Code” At 5
?? ”Flight Date” At 20
?? “Eco Seats” At 40
?? “ Exe. Seats” At 65
?Replicate (“-“,85)
On Page command is used to handle page breaks.
Duplicate Copies
Printing can be repeated to print more copies of the same Reports. The following commands are used to establish these commands.
PrintJob ----EndPrint Job
All commands used for printing must be enclosed within printjob and endprintjob. All system variables can be defined before the printjob.
Printjob--- Endprintjob is an iteration construct, loops as many times as the value in a system memory variable _PCopies. _PCopies contains the number of copies between the range of 1-----32767. Syntax:
* Define after System Memory Variables.
_PCopies = 5
PrintJob
* Commands to Print Entire Report
EndPrintJob
Thus there are Five copies of the report with the _PCopies =5)
Control Break Programs
The Control breaks can be of two types Single Level Control break and Double Level Control Break.
Single Level Control Break
In a report it may sometimes be necessary to group information based on some common criterion. The grouping on a single field is called as single level control break where only one field is the controlling field. Syntax:
Use Flights
Scan
If not Control Break
Print Record
Add 1 to total Bookings, Final Total
Else
Print Total
Initialize Total Bookings to 0
Print Record
Endif
Endscan
Print Total Bookings, Final Total
Double Level Control Break
When a report is grouped on a more than one field it is called as double level control break.
Syntax:
Use Flights
Scan
If not Major Break
Print Record
Add up number of Bookings
Else
Print Total Bookings
Add Total Bookings Total to Final Total
Initialize Bookings Total to 0
Print Record
Add 1 to Bookings Total
Add Bookings Total to Final Total
Initialize Bookings Total to 0
Print Bookings Total
Initialize Bookings Total to 0
Print Record
Add 1 to Bookings Total
Endif
Endscan
Print All Totals
Print Final Total
Example(Single Level Control Break)
Set talk off
Set stat off
Clear
Use Salary
Index on dept tag dept1
Gtot =0
Mdept =space(15)
Subtot =0
Mdept=dept
Do while not EOF()
? “Name of Employee” At 5
?? “ Salary Drawn “ At 20
Do while Mdept = dept
? Name At 20
?? Basic At 40
Subtot= Subtot +Basic
Skip
Enddo
? “Total of Dept “ + Mdept + str (Subtot)
Mdept =Dept
Gtot =Gtot +Subtot
Subtot =0
Enddo
? “Grand Total “ +str(Gtot)
Example(Single Level Control Break)
Set talk off
Set stat off
Set safe off
Clear
Use Salesman
Index on Region tag Region1
Index on Name tag Name1
Mctr=0
Tctr=0
R =4
MRegion =space(25)
MName=space(25)
Do while not EOF()
? “Ponds India Ltd” At 30
? “ Region Wise Report of the Sales Man “ AT 25
MRegion=Region
Do while MRegion =Region
? “Region “At 5
?? “Name” At 15
?? “Sales Man “ At 35
? Replicate( “_”, 85 )At 4
MName=Name
Do while MName=Name
? Region At 5
?? Name At 15
?? SalesMan At 35
Mctr= Mctr+Salesamt
Skip
Enddo
?Replicate(“-“, 85) At 5
? “Total Sales Conducted in one Region “ +str(Mctr)
Tctr = Tctr+Mctr
Mctr=0
Enddo
? “Total Sales Amount in Region “ +str(Tctr)
?Replicate(“-“, 65) At 10
Wait
Gctr=Gctr+Tctr
Tctr=0
Enddo
?Replicate(“-“, 85) At 5
? “Grand Total Of Sales Amount in Region “ +str(Gctr)
1) Multiples of 50
Set talk off
Set stat off
Clear
P=0
Ctr=1
Do while Ctr<=500
P = Ctr*50
@2,10 say “Multiples of 50 “
?? P
Ctr = Ctr+1
Enddo
2) Multiples of 4
Set talk off
Set stat off
Clear
No=1
P=1
Ctr=1
R=4
Do while Ctr<=100
P=No*4
Ctr =Ctr+1
No = No+1
@ 2,10 say “Product is “ +str(P)
@ r,10 say “Multiples of 4 is “
r=r+1
if r>=30
r=4
clear
endif
enddo
3) Print a Reverse No
Set talk off
Set stat off
Clear
Dime A[10]
No=0
i=1
Do while i< =10
A[i]=0
@ 5,7 say “Enter No “ get A[i]
Read
i = i+1
enddo
i=10
do while i>=1
@ 9,7 say “Reverse of the Number is” get A[i]
wait
i = i-1
enddo
4) Program to Print
*
* *
* * *
* * * *
* * * * *
Set talk off
Set stat off
Clear
No=1
No1=1
R=4
C=60
Do while No<=5
No1=1
Do while No1<=No
@ R,C say “*” Pict “!”
C=C-5
No1= No1+1
Enddo
R=R+1
No=No+1
C=60
Enddo
Assignments
· Accept height and base of a Triangle and print its Area.
· Accept height, base of Radius and print Area of a Circle.
· Accept a year from the user and print whether it is a Leap Year or not by using Mod(Year/4=0) function.
· Accept two numbers and accept an Operators like /, +, -, * and print appropriate messages and answers.
· Accept length, breadth or the rectangle and print its area.
· Accept two numbers and accept an Operators like /, +, -, * and print appropriate messages and answers.
· Accept length, breadth or the rectangle and print its area.
No comments:
Post a Comment