Article ID: 129331
Article Last Modified on 12/3/2003
* 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
USE
ENDIF
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
ENDDO
ENDIF
* End of program.
Additional query words: VFoxWin FoxWin FoxDos FoxMac FoxUnix
Keywords: kbcode KB129331