Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Handling Tables
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00868831
Message ID:
00869451
Views:
16
Hi Barne,

You understand VFP help literally. The Name expression can only be used in places where name is expected and has to replace whole name not part of it. The macro substitution on other hand can be used almost anywhere. IOW, you cannot always replace macro substitution with Name exprerssion one to one but it may be possible by changing code little bit. For Example,
m.var1 = mytable.&FieldName
* Direct conversation to Name expresion wouldn't work 
m.var1 = mytable.(FieldName)
* But this will
m.var1 = ("mytable." + m.FieldName)
I would suggest that you change your code as shown below. There's no reasonto use macro substitution in this case.
replace &lcfldnm1 with .t.
*   -->
replace (lcfldnm1) with .t.
...
    replace &lcfldnm2 WITH a.&lcfldnm1  && accepted
*   -->
    replace (lcfldnm2) WITH EVALUATE("a." + lcfldnm1)
See the reasons for errors below each line
    replace (lcfldnm2) WITH a.(lcfldnm1) &&syntax error
*   Name expression has to replace whole name

    replace b.lcfldnm2 WITH a.lcfldnm1  &&accepted,when executed can't find lcfldnm1&2
    * The command references fields with names 'b.lcfldnm2' and 'a.lcfldnm1'
    *  which don't exist

    replace (b.lcfldnm2) WITH (a.lcfldnm1)  &&accepted,when executed can't find lcfldnm1&2
    * The command references fields which names aro stored in the 
    *  fields 'b.lcfldnm2' and 'a.lcfldnm1' and they don't exist
There're also cases when macro substitution is only way to achive something. For example, building dynamic SQL command. In other cases performance may be better with macro substitution. For example, SCAN command with dynamic FOR clause.

Take a look at some interesting discussion here on UT Macro Substitution - Epilogue Thread #736706, Re: Macro substitution Thread #735756 and some topics on FoxWiki http://fox.wikis.com/wc.dll?Wiki~TheLimitsofMacros~VFP, http://fox.wikis.com/wc.dll?Wiki~MacroSubstitution~VFP, http://fox.wikis.com/wc.dll?Wiki~MacroReplacement~VFP


>Thanks so much for your help. I thought I’d impose again to state the “crux” of my problem.
>I do modeling, which involves selecting fields from a number of tables and combining them in a master table. As a result, I need a way to “indirectly” refer to these fields so they can be found and then put in the master table. The old DOS, Clipper program I am now using does this easily with “macro” substitution and the table direction symbol “->”.
>
>The below problem, involves “inverting” the values in one table to another, e.g., making the 1st record in one table the last in another and so on.
>
>The bold text below is what happens when I used each of the replace commands in the code.
>The VFP reference says to avoid the use of the “&” and use a () in its place, yet attempts to do that produce errors; and, use of the “&” seems to produce the most concise and cleanest code. What am I doing wrong?
>PARAMETERS m.lcdir, m.lcfil
>MESSAGEBOX("in yahinv")
>CD (lcdir)
>SET MULTILOCKS ON
>m.liwkarea1=1
>m.liwkarea2=2
>SELECT 1  &&wk area a
>USE (lcfil)
>COPY STRUCTURE EXTENDED TO hdr
>SELECT 2
>USE hdr
>GO 2
>m.lcfldnm1=FIELD(5)
>replace &lcfldnm1 with .t.
>CREATE temp from hdr
>ERASE hdr.dbf
>SELECT 2
>USE temp
>SELECT a
>m.lircdcnt=RECCOUNT(1)
>SELECT b
>FOR m.icnt = 1 TO m.lircdcnt
>  APPEND BLANK
>ENDFOR
>GO top
>CURSORSETPROP("Buffering",5)
>SELECT a
>FOR m.lifldcnt = 1 TO FCOUNT()
>  GO bottom
>  DO WHILE m.lircdcnt => 1
>    m.lcfldnm1=FIELD(m.lifldcnt)
>    SELECT b
>    m.lcfldnm2=FIELD(m.lifldcnt)
>    replace &lcfldnm2 WITH a.&lcfldnm1  && accepted
>    replace (lcfldnm2) WITH EVALUATE("a."+lcfldnm1)  &&accepted
>    REPLACE (lcfldnm2) WITH (lcfldnm1) IN m.liwkarea1  &&accepted
>    replace (lcfldnm2) WITH a.(lcfldnm1) &&syntax error
>    replace b.lcfldnm2 WITH a.lcfldnm1  &&accepted,when executed can't find lcfldnm1&2
>    replace (b.lcfldnm2) WITH (a.lcfldnm1)  &&accepted,when executed can't find lcfldnm1&2
>    WAIT "stop"
>    SKIP 1
>    SELECT a
>    m.lircdcnt = m.lircdcnt - 1
>    ?m.lircdcnt
>    SKIP -1
>  ENDDO
>  m.lircdcnt=RECCOUNT(1)
>  SELECT b
>  GO top
>  SELECT a
>  WAIT "ready for next for loop"
>ENDFOR
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform