How to Make GENXTAB.PRG Work with Any Table/.DBF

Last reviewed: April 30, 1996
Article ID: Q113525
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, and 2.6
  • Microsoft FoxPro for MS-DOS, versions 2.5, 2.5a, 2.5b, and 2.6

SUMMARY

Currently, you can only use GENXTAB.PRG with the first three fields of a database even though the comments in GENXTAB.PRG say otherwise. The comments read as follows:

    Calling example:
    DO genxtab WITH 'XTAB.DBF',.T.,.T.,.T.,1,2,5,.T.

    This command causes GENXTAB to write the output database to
    'XTAB.DBF'. However, XTAB.DBF will be deleted and the output
    stored to a cursor called XTAB. The input database will be closed
    at the conclusion of the program. The rows in XTAB.DBF will
    contain the unique values of field 1 in the database that is
    selected when GENXTAB is called, the columns will contain
    unique values of field 2 in the input database, and the
    cell values will come from field 5 in the input database.
    The thermometer will be shown. A total field will be created.

All the parameters work correctly except the row, column, and cell parameters. GENXTAB.PRG always uses the first field as the row, the second field as the column, and the third field as the cell.

To correct this problem, modify GENXTAB.PRG using the code below and save it as GENXTABX.PRG.

For more information about the meaning of the parameters, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q113971
   TITLE     : How to Call GENXTAB.PRG

MORE INFORMATION

To make the modifications, choose Go To from the Edit menu, and then change the lines below.

WARNING: All of the following modifications must be made at the same time in order to maintain the functionality of GENXTABX.PRG.

   Line 238
   ORIGINAL CODE:
      IF inpfields[1,2] $ 'MGP'
   CHANGE TO:
      IF inpfields[m.rowfld,2] $ 'MGP'

   Line 242
   ORIGINAL CODE:
      IF inpfields[2,2] $ 'MGP'
   CHANGE TO:
      IF inpfields[m.colfld,2] $ 'MGP'

   Line 246
   ORIGINAL CODE:
      IF inpfields[3,2] $ 'MGP'
   CHANGE TO:
      IF inpfields[m.cellfld,2] $ 'MGP'

   Line 310
   ORIGINAL CODE:
      outarray[1,1] = mapname(inpfields[1,1])
   CHANGE TO:
      outarray[1,1] = mapname(inpfields[m.rowfld,1])

   Line 311
   ORIGINAL CODE:
      outarray[1,2] = inpfields[1,2]
   CHANGE TO:
      outarray[1,2] = inpfields[m.rowfld,2]

   Line 312
   ORIGINAL CODE:
      outarray[1,3] = inpfields[1,3]
   CHANGE TO:
      outarray[1,3] = inpfields[m.rowfld,3]

   Line 313
   ORIGINAL CODE:
      outarray[1,4] = inpfields[1,4]
   CHANGE TO:
      outarray[1,4] = inpfields[m.rowfld,4]

   Line 317
   ORIGINAL CODE:
      outarray[i,2] = inpfields[3,2]                   && field type
   CHANGE TO:
      outarray[i,2] = inpfields[m.cellfld,2]           && field type

   Line 318
   ORIGINAL CODE:
      outarray[i,3] = inpfields[3,3]                   && field length
   CHANGE TO:
      outarray[i,3] = inpfields[m.cellfld,3]           && field length

   Line 319
   ORIGINAL CODE:
      outarray[i,4] = inpfields[3,4]                   && decimals
   CHANGE TO:
      outarray[i,4] = inpfields[m.cellfld,4]           && decimals

   Line 325
   ORIGINAL CODE:
      outarray[ALEN(coluniq)+2,2] = inpfields[3,2]
   CHANGE TO:
      outarray[ALEN(coluniq)+2,2] = inpfields[m.cellfld,2]

   Line 326
   ORIGINAL CODE:
      outarray[ALEN(coluniq)+2,3] = inpfields[3,3]
   CHANGE TO:
      outarray[ALEN(coluniq)+2,3] = inpfields[m.cellfld,2]

   Line 327
   ORIGINAL CODE:
      outarray[ALEN(coluniq)+2,4] = inpfields[3,4]
   CHANGE TO:
      outarray[ALEN(coluniq)+2,4] = inpfields[m.cellfld,4]

Save the file as GENXTABX.PRG so that the original GENXTAB can be used. This completes the changes necessary to make GENXTABX.PRG work with any database and any character or numeric fields you choose. To test the changes, use the following example, which uses the SALESMAN.DBF file in the TUTORIAL subdirectory off the main FoxPro directory.

Example

   *** CODE BEGINS HERE ***
   CLOSE DATA
   newgxtx=GETFILE('PRG',"Select GENXTABX.PRG","Select")
   oldgxt=_genxtab
   _genxtab=newgxtx
   SELECT 0
   gxtname=GETFILE('DBF',"Chose SALESMAN.DBF","USE")
   USE (gxtname) EXCLUSIVE
   SET SAFETY OFF
   INDEX ON name+state TAG combo
   SET SAFETY ON
   DO (_GENXTAB) WITH 'TEST_GXT',.T.,.T.,.T.,4,9,5,.T.
   BROWSE
   CLOSE DATA
   _genxtab=oldgxt
   *** CODE ENDS HERE ***

To make GENXTABX your default _genxtab, add the following line to your CONFIG.FP or CONFIG.FPW file:

   _GENXTAB=<path to FoxPro directory>\GENXTABX.PRG


Additional reference words: FoxDos FoxWin 2.50 2.50a 2.50b 2.60 crosstab
KBCategory: kbprg kbcode
KBSubcategory: FxenvConfigfp


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.