some Quotes (translated) from Cetin about using macros,
* first rules in macros "use if necessary "
* general pference is usage name expressions
* & is working 99% but loosing speed and causing errors such as "unrecognized command"
* basically macros executings any strings like you written your hand
let us showing some examples
lcFields = "company, contact, cust_id"
lcTable = "customer "
lcColumn = "country"
lcValue = "USA"
* some picked values from users
lcSelect = "select "+m.lcFields + from " + ;
m.lcTable + " where " + m.lcColumn + "[" + m.lcValue + "]"
&lcSelect
results is like below
Visual Fox Pro
select company, contact, cust_id from customer where country = [USA]
at this point some sections needs macro but some of sections need 'name expression' instead of fixed and macro
first prefence for name expression : fileName, windowName, tableName, aliasName .. using between brackets ()
Visual Fox Pro
lcAlias = "customer"
select lcAlias && search for alias named lcAlias
select &lcAlias && mean : select customer - dont use!
select (lcAlias) && lcAlias is a name expression and written like select customer - use it !
let us examine below codes
Visual Fox Pro
lcFields = "company, contact, cust_id"
lcTable = "customer "
lcColumn = "country"
lcValue = "USA"
* some picked values from users
select &lcFields from (m.lcTable) where evaluate(m.lcColumn) = m.lcValue
we can also use like below
Visual Fox Pro
select &lcFields from (m.lcTable) where &lcColumn = m.lcValue
step by step examination
lcFields: a column list . we can not use instead of 'name expression' or evaluate() . macro necassary
lcTable: table/cursor/alias name. each one specially for name expression
lcColumn: a column name , at the first look it seems we need 'name expression' but here we need column value not column name
if we cant use Name expression there is evaluate and macro alternatives so at the first sample we used evaluate() then macro.
another bad sample
Visual Fox Pro
lcFileName = getfile("TXT")
copy file &lcFileName to yeni.txt
above codes may be tested 100 times w/o error but customer can call you tomorrow ! why ?
may be you selected a file from folders which containing w/o space like "c:\temp\file.txt" but customer may be be selected like "c:\Program files\my file.txt"
result is like below
Visual Fox Pro
copy file c:\Program files\my file.txt to new.txt
error ! just we need name expression
Visual Fox Pro
lcFileName = getfile("TXT")
copy file (m.lcFileName) to new.txt