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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to alter Indexes expression using code

Status
Not open for further replies.

i12hvfun

Programmer
Jul 26, 2002
20
SG
Hi All,
how can I alter the CDX indexes Expression after indexing?
example

use dbf
index on field1 tag tag1

I want to change the field1 to field2 still keeping the tag intact.

Thanks
 
Remove the tag and recreate it using the new field:
Code:
INDEX ON field1 TAG tag1
DELETE TAG tag1
INDEX ON field2 TAG tag1
 
Thanks Eric,
I bet my question sounds silly.
The thing is, I do not want to re-generate the index again. I just need to run index with field1 once but change it to field2 without indexing again.
I am not sure whether by deleting tag and perform index on field2 will run index again.
 
i12hvfun

If your table had 2 indexes to start with, you could switch between them without having to re-index the table.

use myTable
index on field1 tag tag1
index on field2 tag tag2

set order to tag tag1
set order to tag tag2




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi

INDEX ON field1 TAG field1
INDEX ON field2 TAG field2

OR

INDEX ON field1+field2 TAG tag1
INDEX ON field2+field1 TAG tag2

And when you want to use it
SET ORDER TO 1 or 2 or TAG1 or TAG2
OR

SEEK eExpression TAG TagName
or
SEEK(eExpression,cTagName)

:)




ramani :)
(Subramanian.G)
 
Accept my apologises if I have confuse all of you.

Let me explain what I am trying to do.

I am using a index progress bar function

use myTable
index on progressbar(field1) tag tag1


function progressbar
lparameters cField1
wait window at 10,10 'indexing '+transform(recno())+' of '++transform(reccount())
return cField1
endfunc

The problem is, the return value is not field1. So, the index expression after indexing is 'index on progressbar(field1) tag tag1' instead of field1. So, I need to code to alter the expression to field1.

Many thanks.
 
Using such index expressions will slow down your app and your table and index access/updates dramatically. I'd never use it. It does not make an app better.
 
Hi
Try this

use myTable
sTemp=progressbar(field1)
index on &sTemp tag tag1


function progressbar
lparameters cField1
wait window at 10,10 'indexing '+transform(recno())+' of '++transform(reccount())
return cField1
endfunc
 
thanks 738262. It didn't help as the function does not run in index on statement.

 
Can I have one question that is related to this thread?

In my application I have database. After some time I need to add one more index to table. Because there are more then one PC that use this application so I wont to do it in function that will be run on application startup.

But when I do this:
open database db
use table1
index on filed10 tag tag10
index on filed11 tag tag11
close tables
close database

But after I modify table in database builder so there isnt the new indexes that I tried to create. Where is the problem? Sometimes I get error hat database isn't validate.
Than I have to repair it in VFP designer.

Pleas help.
Thanks
 
i12hvfun,
I agree with Eric, that it would likely take a great deal of extra time to create this index. Have you considered just turning the TALK setting on and an having an appropriate ODOMETER value? This will show that the reindexing is going on, without slowing things down quite so much.

On the other hand to "answer" your original question, you'll need to close the table (and the index), and use the low-level IO routines (FOPEN, FSEEK, FWRITE, FCLOSE) to alter the index expression value in the .CDX header. It's clearly defined in the VFP documentation, but I hesitate to give you the exact code, because I consider it a potentially bad kludge.

Rick
 
Rick,
I guess have to compromise on the interface.
Thanks All!

Bon011
maybe you should consider opening a new thread. The response might be better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top