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 biv343 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 3

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
549
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.
 
That's a good example how the advice given in books can be good advice given at the time it was printed but be outdated.
Let me point out a service you might not know, Hentzenwerke publishes Updates/FAQ/Errata for their books.
For Kilofox that's at https://www.hentzenwerke.com/catalog/kilofoxfaq.htm

And Kilofox (aka 1001 Things You Wanted to Know About Visual FoxPro) is from the year 2000. In 2000 VFP7 was the current version. You can't expect anything relevant for VFP 8 or 9 from that book, for example. And if you have a revision of the book that's even that old, that it doesn't use name expressions - as Tamar says in VFP5 - then that's even worse.

I'm not saying all in all VFP 8 and 9 have changed that much that this book has become useless, but the books "What's New in 8" and "What's New in 9" are good companion books to keep up to date with "How to FoxPro", if we call it that way. And even the 2000 revision of Kilofox could be more helpful than the revision you have.

You can't expect to become a better programmer from owning books, not even from reading them. If you don't practice and program regularly and the error "Alias XYZ is not found" does not tell you that you closed a workarea you thought is open - which is a prerequisite of using SELECT (not SQL-SELECT) and you need a heads up to realize that - then all the books you have seem to have been very fruitless especially if it's even a comment of your own code that the USE closes CLIENTES.

SELECT also is not a command that you only use once when Christmas and Easter occur at the same day of an eclipse, but every single day of programming with VFP. You make the impression you start learning Foxpro at day 1, while your account here at Tek-Tips is 15 years old and I'm sure you didn't created that account in your first day of FoxPro programming. At that year, 2010, VFP9 already was the latest VFP version, but you're more of a legacy FoxPro developer, so you must have started in the 80ies, perhaps. What you do mainly must be something else, I can't understand why you lack so much of FoxPro knowlegde after being here for 15 years.
 
Last edited:
Chris: Yes, I have been using FoxPro since 1993 (FoxPro 2.0 for DOS). I only began using VFP (part of Visual Studio 6) in 2001.

But in that period, till 2011 I was employed in a firm using large and complex program developed since 1990 in Quick Basic. So I had little time to dedicate do VFP.

Since 2012 I have been learning VFP (programming mode) and only in 2018 I started using OOP in VFP. It was a drastic change for me to absorb all (it seems infinite) possibilities of VFP9.

I appreciate your comments.
 
When you step in any course (college or to learn a foreign language) there are steps fo follow. To go into step 2 you have to pass step 1, to go into step 3 you have to pass step 2, and so on.

This is not true for learning a programming language: each new version lets some former codes obsolete. You have to had practice in all versions, since de beginning.

As Chris said in above post, there are "What's New in 8", "What's New in 9", but these books are for people with good understanding of old versions of VFP. Of course, they are good companion, but they are more useful as earlier a programmer started using FP/VFP.

I have not found a book about VFP9 for "new users", people who have not been using VFP exclusively during all their professional work. If someone has any advice about where to find such a book, please inform here.

I am very grateful for the advices you dear colleagues have given me in all these years.

Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top