Microsoft KB Archive/172853: Difference between revisions
m (Text replacement - "[[../foxpro/q" to "[[../") |
m (Text replacement - "&" to "&") |
||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
{| | {| | ||
|width="100%"| | |width="100%"| | ||
= HOWTO: Create an ASCII Text Output File with Headers & | = HOWTO: Create an ASCII Text Output File with Headers & Footers = | ||
'''ID: Q172853''' | '''ID: Q172853''' | ||
Line 23: | Line 23: | ||
== SUMMARY == | == SUMMARY == | ||
Attempting to route a report to an ASCII text file from FoxPro 2.x for MS- DOS using the command REPORT FORM | Attempting to route a report to an ASCII text file from FoxPro 2.x for MS- DOS using the command REPORT FORM <report name> TO FILE <file name>, creates an ASCII text file without printer control codes. However, attempting to route a report to an ASCII text file from FoxPro for Macintosh using the command REPORT FORM <report name> TO FILE <file name>, creates an ASCII text file with embedded printer control codes.<br /> | ||
<br /> | <br /> | ||
In FoxPro 2.x for Windows, the simplest way to create an ASCII text file from a report is to use the Generic/Text only printer driver within Windows. However, if for some reason you cannot install this printer driver, you can use the following sample code as a workaround. The sample code below creates a report programmatically and sends it to an ASCII text file. | In FoxPro 2.x for Windows, the simplest way to create an ASCII text file from a report is to use the Generic/Text only printer driver within Windows. However, if for some reason you cannot install this printer driver, you can use the following sample code as a workaround. The sample code below creates a report programmatically and sends it to an ASCII text file. | ||
Line 36: | Line 36: | ||
<pre class="CODESAMP"> *begin program | <pre class="CODESAMP"> *begin program | ||
m.usefile=sys(2004) & | m.usefile=sys(2004) && get the start up directory | ||
* add a path to the clients file | * add a path to the clients file | ||
m.usefile=m.usefile+ | m.usefile=m.usefile+"sample\organize\dbfs\clients.dbf" | ||
USE (m.usefile) & | USE (m.usefile) && use the clients table | ||
gnhandle=FCREATE('output.txt',0) & | gnhandle=FCREATE('output.txt',0) && create an output file | ||
* set up some variables to track pagination | * set up some variables to track pagination | ||
gnpage=1 & | gnpage=1 && page count variable | ||
gnlines=0 & | gnlines=0 && line count variable | ||
GO TOP & | GO TOP && go to the first record | ||
* Now loop through the table | * Now loop through the table | ||
DO WHILE !EOF() | DO WHILE !EOF() | ||
* If the number of lines is 0, put in a page header | * If the number of lines is 0, put in a page header | ||
IF gnlines | IF gnlines>=65 | ||
gnlines=0 & | gnlines=0 && reset the line count to 0 | ||
gnpage=gnpage+1 & | gnpage=gnpage+1 && increment the page count | ||
ENDIF | ENDIF | ||
DO CASE | DO CASE | ||
CASE gnlines=0 | CASE gnlines=0 | ||
=pagehead() & | =pagehead() && procedure to write page header | ||
LOOP | LOOP | ||
CASE gnlines=56 | CASE gnlines=56 | ||
=pagefoot() & | =pagefoot() && procedure to write page footer | ||
LOOP | LOOP | ||
OTHERWISE | OTHERWISE | ||
gnlines=gnlines+1 & | gnlines=gnlines+1 && increment the line count | ||
* concatenate four character fields | * concatenate four character fields | ||
out_line=client_id+SPACE(3)+company+SPACE(3)+city+SPACE(3)+state | out_line=client_id+SPACE(3)+company+SPACE(3)+city+SPACE(3)+state | ||
=FPUTS(gnhandle,out_line) & | =FPUTS(gnhandle,out_line) && output the string to the ASCII file | ||
* FPUTS() automatically adds a carriage return & | * FPUTS() automatically adds a carriage return & line feed | ||
* change fputs to fwrite if you want to control insertion of | * change fputs to fwrite if you want to control insertion of | ||
* the carriage return & | * the carriage return & line feed characters | ||
SKIP & | SKIP && skip to the next record | ||
ENDCASE | ENDCASE | ||
ENDDO | ENDDO | ||
* If not at the end of the page, pad blank lines | * If not at the end of the page, pad blank lines | ||
IF gnlines | IF gnlines<56 | ||
out_line= | out_line="" | ||
FOR i=gnlines TO 56 | FOR i=gnlines TO 56 | ||
=FPUTS(gnhandle,out_line) | =FPUTS(gnhandle,out_line) | ||
gnlines=gnlines+1 | gnlines=gnlines+1 | ||
NEXT | NEXT | ||
=pagefoot() & | =pagefoot() && write the page footer | ||
ENDIF | ENDIF | ||
=FCLOSE(gnhandle) & | =FCLOSE(gnhandle) && close the open output file | ||
RETURN | RETURN | ||
PROCEDURE pagehead | PROCEDURE pagehead | ||
=spacer() & | =spacer() && insert blank lines | ||
* Place the title into the file | * Place the title into the file | ||
out_line= | out_line="This is Sample ASCII Text Output" | ||
gnlines=gnlines+1 & | gnlines=gnlines+1 && increment the line count | ||
=FPUTS(gnhandle,out_line) & | =FPUTS(gnhandle,out_line) && write the page header | ||
=spacer() & | =spacer() && insert blank lines | ||
RETURN | RETURN | ||
PROCEDURE pagefoot | PROCEDURE pagefoot | ||
=spacer() & | =spacer() && insert blank lines | ||
* Place the date and page number in the footer of the file | * Place the date and page number in the footer of the file | ||
out_line=DTOC(DATE())+SPACE(50)+ | out_line=DTOC(DATE())+SPACE(50)+"Page "+LTRIM(STR(gnpage)) | ||
=FPUTS(gnhandle,out_line) & | =FPUTS(gnhandle,out_line) && write the page footer | ||
=spacer() & | =spacer() && insert blank lines | ||
gnlines=0 & | gnlines=0 && reset the line count to 0 | ||
gnpage=gnpage+1 & | gnpage=gnpage+1 && increment the page count | ||
RETURN | RETURN | ||
PROCEDURE spacer | PROCEDURE spacer | ||
* Padding four lines in this loop | * Padding four lines in this loop | ||
out_line= | out_line="" | ||
FOR i=1 TO 4 | FOR i=1 TO 4 | ||
gnlines=gnlines+1 | gnlines=gnlines+1 |
Latest revision as of 12:29, 21 July 2020
The information in this article applies to:
SUMMARYAttempting to route a report to an ASCII text file from FoxPro 2.x for MS- DOS using the command REPORT FORM <report name> TO FILE <file name>, creates an ASCII text file without printer control codes. However, attempting to route a report to an ASCII text file from FoxPro for Macintosh using the command REPORT FORM <report name> TO FILE <file name>, creates an ASCII text file with embedded printer control codes.
MORE INFORMATIONIf printer control codes are present in an ASCII text file, they can cause significant difficulties when you try to share the file with another application or user. The sample code below illustrates hot to use low-level file input and output (I/O) functions to create an ASCII text output file with headers and footers. Sample Code*begin program m.usefile=sys(2004) && get the start up directory * add a path to the clients file m.usefile=m.usefile+"sample\organize\dbfs\clients.dbf" USE (m.usefile) && use the clients table gnhandle=FCREATE('output.txt',0) && create an output file * set up some variables to track pagination gnpage=1 && page count variable gnlines=0 && line count variable GO TOP && go to the first record * Now loop through the table DO WHILE !EOF() * If the number of lines is 0, put in a page header IF gnlines>=65 gnlines=0 && reset the line count to 0 gnpage=gnpage+1 && increment the page count ENDIF DO CASE CASE gnlines=0 =pagehead() && procedure to write page header LOOP CASE gnlines=56 =pagefoot() && procedure to write page footer LOOP OTHERWISE gnlines=gnlines+1 && increment the line count * concatenate four character fields out_line=client_id+SPACE(3)+company+SPACE(3)+city+SPACE(3)+state =FPUTS(gnhandle,out_line) && output the string to the ASCII file * FPUTS() automatically adds a carriage return & line feed * change fputs to fwrite if you want to control insertion of * the carriage return & line feed characters SKIP && skip to the next record ENDCASE ENDDO * If not at the end of the page, pad blank lines IF gnlines<56 out_line="" FOR i=gnlines TO 56 =FPUTS(gnhandle,out_line) gnlines=gnlines+1 NEXT =pagefoot() && write the page footer ENDIF =FCLOSE(gnhandle) && close the open output file RETURN PROCEDURE pagehead =spacer() && insert blank lines * Place the title into the file out_line="This is Sample ASCII Text Output" gnlines=gnlines+1 && increment the line count =FPUTS(gnhandle,out_line) && write the page header =spacer() && insert blank lines RETURN PROCEDURE pagefoot =spacer() && insert blank lines * Place the date and page number in the footer of the file out_line=DTOC(DATE())+SPACE(50)+"Page "+LTRIM(STR(gnpage)) =FPUTS(gnhandle,out_line) && write the page footer =spacer() && insert blank lines gnlines=0 && reset the line count to 0 gnpage=gnpage+1 && increment the page count RETURN PROCEDURE spacer * Padding four lines in this loop out_line="" FOR i=1 TO 4 gnlines=gnlines+1 =FPUTS(gnhandle,out_line) NEXT RETURN *end of program file
REFERENCESFor additional information on creating ASCII output files, please see the following articles in the Microsoft Knowledge Base:
Additional query words: Keywords : kbcode kbVFp FoxWin FxprgGeneral FxprintGeneral Version : MACINTOSH:2.5b,2.5c,2.6a; WINDOWS:2.5,2.5a,2.5b,2.6,2.6a Platform : MACINTOSH WINDOWS Issue type : kbhowto |
Last Reviewed: August 12, 1999 |