Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index details

Status
Not open for further replies.

GoodOldRob

Programmer
Sep 10, 2003
8
0
0
GB
Is there a simple way with foxpro 2.5(dos) to extract programmatically the index key details from a .cdx file, so that i can build an INDEX ON command at runtime.

I have done some thing similar on the table field details using AFIELDS()
 
You can use the TAG() and KEY() functions.
Here's a little routine I use. Call it by issuing a command like this:

USE MyTable EXCLUSIVE
nResult = ReindexEx("MyTable")

Code:
*.....
FUNCTION ReindexEx 
PARAMETERS cFileName

?'Reindexing ' + cFilename + '...*'

STORE 1 TO nWhichTag
DO WHILE !EMPTY(TAG(nWhichTag))
   DIMENSION aTags[nWhichTag, 2]
   aTags[nWhichTag, 1] = Key(nWhichTag)
   aTags[nWhichTag, 2] = Tag(nWhichTag)
   nWhichTag = nWhichTag + 1
ENDDO

DELETE TAG ALL 

FOR nIndex = 1 TO nWhichTag - 1
   ??'*'
   INDEX ON &aTags[nIndex, 1] TAG &aTags[nIndex, 2] 
NEXT

You can modify this routine to save off the keys to a table, delete the index and scan through the table recreating them on the fly if you feel more secure doing it that way rather than just deleting the tags with DELETE TAG ALL.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Sorry, I forgot to add the SET PROCEDURE TO MyProc in the beginning:

SET PROCEDURE TO MyProc
USE MyTable EXCLUSIVE
nResult = ReindexEx("MyTable")
.
.
.

*..... MyProc.PRG ....
FUNCTION ReindexEx
.
.
.

-Dave S.-
[cheers]
Even more Fox stuff at:
 
What about the DESCENDING part of the INDEX ON command , i have found the descending() command in fox2.6 but cannot find anything like it in fox2.5
 
I haven't been able to find anything either.
I think MS figured you would just create the index then set the order to either ascending or descending as needed.
An option (a pain but it should work) may be to list the structure to a text file, import the text file to a table, parse the tags and keys while looking for the word 'descending', and recreate them that way.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Rob,
Descending(), Unique() ansd Tagcount() were introduced in 2.6 (as well as For() which duplicates sys(2021)).
Here's a routine I wrote in VFP 8.0, that I modified to work (as best as it can) in 2.5.
Code:
* ListCDXInfo.prg
PARAMETERS p_cTable
USE (p_cTable) NOUPDATE

FOR ii= 1 TO 255 && 2.6 TAGCOUNT()
   IF Empty(TAG(ii))
      Exit && ?LOOP
   ENDIF
   ? TAG(ii)
   ?? ";"
   ?? KEY(ii) && or sys(14, ii)
   ?? ";"
   ?? sys(2021, ii) && or FOR(ii)
   ?? ";"
   ** VFP ?? PRIMARY(ii)
   **?? ";"
   ** VFP ?? CANDIDATE(ii)
   **?? ";"
   ** 2.6 ?? UNIQUE(ii)
   **?? ";"
   ** 2.6 ?? DESCENDING(ii)
   **?? ";"
ENDFOR &&* ii= 1 TO TAGCOUNT()
lcCode = ""
FOR ii= 1 TO 255 &&TAGCOUNT()
   IF Empty(TAG(ii))
      EXIT && ? LOOP
   ENDIF
   lcCode = lcCode + "INDEX ON "+KEY(ii)+" TAG "+TAG(ii)
   IF !EMPTY(sys(2021, ii)) && or FOR(ii))
      lcCode = lcCode + " FOR "+ sys(2021, ii) && or FOR(ii)
   ENDIF
   **IF DESCENDING(ii)
      **lcCode = lcCode + " DESCENDING"
   **ENDIF
   lcCode = lcCode + chr(13) + CHR(10)
ENDFOR &&* ii= 1 TO TAGCOUNT()
_cliptext = lcCode
wait window _cliptext nowait
USE
* EOP: ListCDXInfo.prg
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top