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 2

SitesMasstec

Programmer
Sep 26, 2010
519
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.
 
Hello dear colleagues!

I am "fighting" to put into use the above advices from Ein, Chris, Tamar and Mike.

As an example, I have never seen in a many VFP books I have, the name of a file inside parenthesis, like USE (ARQUIVO55). Of course, it is a surprise to me.

I will let you know as I finish applying these valuable advices.
 
May you dear colleagues check if I have learnt correctly? Well, this is just the first basic step which I think I have understand.

Code:
SELECT 0
USE CLIENTES ALIAS CLIENTES      && Original table with data (clients from a firm)


ARQUIVO55=SYS(2015)              && Random name for a temporary file
COPY STRUCTURE TO (ARQUIVO55)    && Copy CLIENTES.DBF structure to the temporary file
USE                              && Close CLIENTES.DBF


SELECT 0
USE (ARQUIVO55) ALIAS ARQUIVO55  && Just to name the Alias name
USE


SELECT CLIENTES
GOTO TOP

DO WHILE NOT EOF()

   IF YCNOME<>XQualNome    && YCNOME stores CNOME value from table CLIENTES.DBF
      SKIP
      LOOP
   ENDIF

   IF YCCIDA<>XQualCidade  && YCCIDA stores CCIDA value from table CLIENTES.DBF
      SKIP
      LOOP
   ENDIF

   SELECT ARQUIVO55
   APPEND BLANK            && To populate the temporary file with selected data
   REPLACE CNOME WITH YCNOME   
   REPLACE CCIDA WITH YCCIDA

   SELECT CLIENTES
   SKIP
ENDDO

Well, I got an error when running...:(

ErroTreinoBasico1.JPG
 
Last edited:
first line you open the table "clients". 2nd line you just create the new table, but within the line below the "COPY..." you're closing your "clients"-table with the single "USE"-command.
Frm_414.jpg
I have a method within my object to use a table for different usage like here
Code:
LPARAMETERS Tc_Alias as String, Tc_Rw as variant
** .SrvFile is a member in this object
DO CASE
CASE EMPTY(Tc_Rw)            && open readonly
    USE (.SrvFile) ALIAS (Tc_Alias) IN SELECT(Tc_Alias) SHARED NOUPDATE AGAIN
CASE VARTYPE(Tc_Rw) == "L"    && open readwrite
    USE (.SrvFile) ALIAS (Tc_Alias) IN SELECT(Tc_Alias) SHARED AGAIN
CASE VARTYPE(Tc_Rw) == "C"    && open exclusive (i.e. "X")
    USE (.SrvFile) ALIAS (Tc_Alias) IN SELECT(Tc_Alias) EXCLUSIVE
ENDCASE
RETURN USED(Tc_Alias)

to close a specific workarea
Code:
SELECT (aliasname)
USE
** or better, not to change the active workarea just...
USE IN SELEC(aliasname)
 
Oh, yes! The command SELECT (alias name) would not select any table if I had closed the table before!

Now the program is working fine.

Well, now I will put these learnings into practice in the real program.

Tamar had advised not to use macro in USE (as USE &ARQUIVO55). Instead I should use:
Code:
USE (ARQUIVO55) ALIAS ARQUIVO55

I am trying to understand why the use of parentheses in the above code, instead of macro substitution. I was more confusing when I found this example in Kilofox (macro in USE (&lcFile) :
Code:
*** Open the files to compare and get their structures into the cursor
FOR lnCnt = 1 TO 2
lcFile = ("tcFile" + PADL(lnCnt,1))
USE (&lcFile) AGAIN IN 0 SHARED ALIAS TestFile
AFIELDS( laFields, 'TestFile' )
APPEND FROM ARRAY laFields
USE IN TestFile
 
Oh, I finally come to terms with "name expression" to use instead of macro substitution, to refer to table names.

It was strange to me the use of (ARQUIVO55). Now it is not anymore. I feel clearly that name expression in VFP is somehow like (10+5) in Math, after reading Tamar's article that she advised me.

I have it printed for a more confortable reading.
 

Part and Inventory Search

Sponsor

Back
Top