Microsoft KB Archive/113175

= How to print multiple columns in FoxPro for MS-DOS =

Article ID: 113175

Article Last Modified on 2/11/2005

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.6 for MS-DOS
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.6 Standard Edition
 * Microsoft FoxPro 2.5b for Macintosh

-



This article was previously published under Q113175





SUMMARY
A common request is to print multiple columns in FoxPro for MS-DOS. Currently this capability is not provided in the Report Writer. However, you can simulate this functionality by creating a cursor that creates the "columns," as described below.



MORE INFORMATION
NOTE: The following method, though designed specifically for FoxPro for MS-DOS, could also be used in FoxPro for Windows and FoxPro for Macintosh.

The following sample program creates an SQL cursor with the requested number of columns. You can call the program in the following manner:

USE

DO colmaker WITH 4 && where 4 is the number of columns desired

REPORT FORM  PREVIEW

The cursor can then be used to create a report. The columns will all be in one record, so the fields for the total number of columns desired will be placed on the same detail line. The program creates an extra field called TRACKER for every column. This field will not be displayed in the report. PROCEDURE colmaker PARAMETER colnum

* Initializes variables **********************  * Stores fields in database to an array 'repodbf' =AFIELDS(repodbf)

* Stores number of fields in database to a variable 'numfield' numfield = ALEN(repodbf,1)

* Stores database name to variable 'dbfname' dbfname = ALIAS

* Initializes procedure variables fldlist = "" whrclause = "" totcur = "" i = 0

* Calculates variables to deal with extra records extras = RECCOUNT % colnum IF extras <> 0 mtracker = CEILING(RECCOUNT/colnum) ENDIF

* Generates field list for SELECT statements FOR i = 1 to numfield fldlist = fldlist + dbfname+ "."+repodbf(i,1) + "," ENDFOR

* Adds a field to the resulting SELECT statements to organize * records fldlist = fldlist + "CEILING(recno/"+ALLTRIM(STR(colnum))+") ;     AS TRACKER"

* Deletes any residual temporary databases oldsaf = SET("SAFETY") SET SAFETY OFF FOR i = 1 to colnum fname = "temp"+ALLTRIM(STR(i)) + ".DBF" ERASE &fname ENDFOR

* Creates databases for columns FOR i = 1 to colnum curname = "temp" + ALLTRIM(STR(i)) x = IIF(i 0 FOR i = extras+1 to colnum fname = "TEMP" + ALLTRIM(STR(i)) SELECT &fname APPEND BLANK REPLACE tracker WITH mtracker ENDFOR ENDIF

* Builds join condition for resulting databases FOR i = 1 to colnum-1 whrclause = whrclause + "temp"+ALLTRIM(STR(i)) + ; ".tracker = temp" + ALLTRIM(STR(i+1)) + ; ".tracker AND " ENDFOR i     whrclause = whrclause + "temp1.tracker = temp" + ; ALLTRIM(STR(colnum)) + ".tracker"

* Combines resulting database into one final database SELECT * FROM &totcur INTO CURSOR final ; WHERE &whrclause

* Deletes residual databases FOR i = 1 to colnum fname = "temp"+ALLTRIM(STR(i)) SELECT &fname USE fname = fname + ".DBF" ERASE &fname ENDFOR

* Returns to resulting cursor SELECT final The "final" cursor will contain a copy of each field for the number of columns specified. For example, using the CUSTOMER database in the FoxPro TUTORIAL subdirectory, you could create a three-column report by placing the following expressions in the Detail band:   CNO_A        CNO_B       CNO_C COMPANY _A  COMPANY_B   COMPANY _C The records will appear in order across and down the page. For example:   RECORD 1    RECORD 2   RECORD 3 RECORD 4   RECORD 5   RECORD 6

Additional query words: VFoxWin FoxMac FoxDos FoxWin multi multiple multi- column multicolumn

Keywords: kbcode KB113175

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.