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

Set a TAG for a field programmaticaly

SitesMasstec

Programmer
Sep 26, 2010
512
Brasil
Hello colleagues!

I have a free table named ETIQUETA.DBF:

CriarTAG.jpg

Now I want to create a TAG (ascending) for the field CCIDA, but programmaticaly.

I tried many commands like
Code:
ALTER TABLE ETIQUETA ... TAG CCIDA
, but I failed.

Is it possible?

In fact, I want this for another table, derived from another table. The above table is just to simplify the problem.
 
Look at the INDEX command, for example:

Code:
INDEX ON CCIDA TAG CCIDA

The default order is ASCENDING so you don't need to specify that but as the help says:

By default, Visual FoxPro displays and accesses records in ascending order. However, you can include ASCENDING as a reminder of how records are displayed.
 
If you use this index temporary for a view and/or printing issue, you also can use the SQL SELECT.
Code:
SELECT * from "ETIQUETA" ;
  INTO CURSOR CursorName ;
  [WHERE any filters ;] && optional
  ORDER BY CCIDA

As your picture schown is the table readonly, then you can't any index-tags
 
Hi,

Tag is not part of table structure in VFP, you need to use INDEX ON Command for any Tag you want to create. So, for your example above, once you open the table (exclusive) you need to add following command:

Code:
INDEX ON CCIDA TAG CCIDA

(as Paul has already mentioned)

This will create you index and going forward you can use it with your table as

Code:
USE ETIQUETA ORDER CCIDA

Thanks,
PREMAL
 
You mentioned that this is a free table. Although you can use ALTER TABLE to create an index and assign it a tag, you can only do that if the table is part of a database.

From the VFP Help:

ALTER TABLE - SQL Command
You can use ALTER TABLE to modify the structure of a table that has not been added to a database. However, Visual FoxPro generates an error if you include the DEFAULT, FOREIGN KEY, PRIMARY KEY, REFERENCES, or SET clauses when modifying a free table.

For free tables, you would do this:

Code:
INDEX ON  <some expression> TAG <tag name>

Mike
 
Do you know how you can revisit your old questions? In the top right you see your name. there's a dropdown when you click on that, and there you find "Your content", which is all your posts.
You have been told how to create indexes programmatically in previous threads:
 
Premal & Mike:

ETIQUETA.DBF is a free table (I have not used VFP Database in this life, yet :censored:)

In a some parts of the program I have:

Code:
INDEX ON NOVOCNOME TAG NOVOCNOME
...
IF XQualOrdem="A"
     Ordem="NOVOCNOME"
ENDIF
...
USE ETIQUETA ORDER &Ordem

Chris: Yes, in the first post you mentioned ("Create a table with Tag indexes") Steve Yu had answered:

Code:
index on LOCALIZA + str(codagente,6) tag anytagname

I will pay more attention next time. Thanks.
 
One further point ...

You say you have the INDEX IN ... in "some parts of the program". Do you know that you only need to create a given index tag once (for a given table). Once it has been created, it stays in existence until explicitly deleted, even after you close the table or terminate the program.

Mike
 
Oh, yes Mike, I know.

I let you dear colleagues misunderstood me. I would mean:

In one part of the program I have the command:
Code:
INDEX ON NOVOCNOME TAG NOVOCNOME

In another part of the program I have the command:
Code:
IF XQualOrdem="A"
     Ordem="NOVOCNOME"
ENDIF

And in another part I have:
Code:
USE ETIQUETA ORDER &Ordem

Just once each command.

Sorry.
 
Your question was how to create an index tag programmatically, that's done with the INDEX command. Even if you didn't revisit your old threads that should be clear by now, but your listing of the three program code lines almost shouts out you have the code but don't kno what lines does what.

The importance of what Mike Lewis points out is that by redoing INDEX ON you're wasting time, energy, effort, patience of users. Once an index is created it's created and grows and shrinks with the data. The only reason Mike points that out is that legacy index types in IDX files don't have that behavior, but it's still in legacy developers habits to repeteadly do INDEX data, though that's just a waste of time once it's done in the major CDX file of a table.

It's also no virtue to only have one place in all your code to USE a table ordered by a tag nor to only have one place in code that decides which order tag to use. Regarding that, you could even spare to first set a variable but use the table ordered by the tag you know you want to use or SET ORDER to it.

It's not even a virtue to only have one line of INDEX ON... in your code, because that doesn't tell anything about how many times it's executed. You usually generate tables at design time, during development and include them in a setup that just puts them on the end users computer, there's not even the necessity to have any INDEX ON line of code, therefore. There are good reasons to programmatically create new tables including their indexes and not only use table files you generate during development, but the number of search results will never tell you anyhthing about the quality of code regarding that.

Besides, most of all these things have been told to you in the threads I quoted. It's watering down a knowledge base if you add the same answers to the same questions into a forum.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top