How to Preserve Index Expressions to Rebuild CDX and TagsLast reviewed: April 30, 1996Article ID: Q129331 |
The information in this article applies to:
SUMMARYOften, a utility menu is included in an application that enables the user to perform functions such as reindexing or backing up files. One very useful function to include on such a utility menu is a way to recreate the .CDX file with all of the tags rebuilt programatically. This keeps the .CDX file in optimum condition if done routinely. This article shows by example how to do this.
MORE INFORMATIONYou first need to store the tag names and index expressions in a utility table. Then you need some code to read the utility file that will use the values to reindex the table.
Sample CodeThe following sample code uses the tutorial table CUSTOMER.DBF to demonstrate how to create a utility file, read it, and use the values to reproduce the .CDX file. * Make the CDX Expression table. CREATE TABLE cdxexp ; (TAG C(10),expression C(254))* Insert three index expressions into the table. * Below is a simple index expression on one field. INSERT INTO cdxexp ; (TAG,expression) ; VALUES ; ("COMPANY","company")* Below is a concantenated index expression. INSERT INTO cdxexp ; (TAG,expression) ; VALUES ; ("STATE_CO","ALLTRIM(UPPER(state))+ALLTRIM(company)")* Below is a complex index expression that correctly orders a numeric * field concantenated with a character field. Indexing on the STR() of * a numeric alone will yield incorrect ordinal values of the numeric * field. This expression uses PADL and ALLTRIM with STR to put the * numeric characters into the correct location in the string. INSERT INTO cdxexp ; (TAG,expression) ; VALUES ; ("YTDP_ST","PADL(ALLTRIM(STR(ytdpurch,20,2)),20,'0') + ; ALLTRIM(UPPER(state))")* Use the library FoxTools for the MessageBox function. SET LIBRARY TO foxtools SET DEFAULT TO c:\fpw26a\tutorial * Delete the current CDX file in order to rewrite the header. IF USED('CUSTOMER') SELECT CUSTOMER USEENDIF DELETE TAG ALL * Open the table to reindex (CUSTOMER.DBF) in the second Workarea. SELECT B USE C:\FPW26A\TUTORIAL\CUSTOMER * Call the MsgBox function from FoxTools with "Yes/No" buttons, option 4. * The MsgBox function will need to be replaced with a GET object for * versions other than Windows. msg="Ready to rebuild the CDX file?" answer=MSGBOX(msg,"",4) * If the user clicks the Yes button, the return value will be 6. IF answer=6 SELECT A && index expression file called "cdxexp" GO TOP DO WHILE NOT EOF() && process the whole file mtag=cdxexp.tag && read the values from the record mexp=cdxexp.expression SELECT B INDEX ON &mexp TAG &mtag && index on the variable expressions SELECT A SKIP && go to the next record ENDDOENDIF * End of program.
|
Additional reference words: VFoxWin 3.00 FoxWin FoxDos FoxMac FoxUnix 2.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |