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

Macro substitution

Status
Not open for further replies.

diarmaid

Programmer
Jun 27, 2003
34
IE
Can anyone say if the following REPLACE statement is valid?

FOR lnCycle = 1 TO gnTotalPeriods
lcField = ReportData.Period_"+PADL(ALLTRIM(STR(lnCycle)),2,"0")
lcGetBudgField = "nbudg.nb_cbp"+PADL(ALLTRIM(STR(lnCycle)),2,"0")
* REPLACE (lcField) WITH (&lcBudgField) && Error "Missing operand"
* REPLACE (lcField) WITH (lcBudgField) && Error "data type mismatch"
REPLACE (lcField) WITH lcBudgField && Error "data type mismatch"

ENDFOR

The left side, lcField works, problem is to the right of the "WITH".
 
Hi Diarmaid,

None of those options look right to me.

Personally, my first choice would be to try:

REPLACE (lcField) WITH EVALUALTE(lcBudgField)

By the way, are you sure that lcBudgField actually exists? You third line is setting lcGetBudgField. Is that a mistake?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
First you some errors here. Maybe they are just typos, but who knows.
1. You didn't have opened quote in lcField"
lcField = ?????ReportData.Period_"

2. You replace with lcBudgField but you store the value to lcGetBudgField.

As I said they maybe just a typos. I prefer:
Code:
FOR lnCycle = 1 TO gnTotalPeriods
    lcPadded    = PADL(ALLTRIM(STR(lnCycle)),2,"0")
    lcField     = "Period_"      + lcPadded
    lcBudgField = "nbudg.nb_cbp" + lcPadded
    REPLACE (lcField) WITH;
            EVALUATE(lcBudgField) IN ReportData
ENDFOR

BTW If you use VFP9 that is enough:
Code:
lcPadded    = PADL(lnCycle,2,"0")



Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
 
SOLVED! Thanks, I wasn't aware of the EVALUATE() function, that works perfectly and means I can drop a long CASE statement I was using to provide for all possibilities.

Not needing the ALLT(STR()) with PADL() is also a new one for me ... isn't it great to learn things!

I did make some errors when copying the code into the posting, sorry about that.
 

BTW If you use VFP9...

Borislav, PADL()/PADR()/PAD() work that way since at least VFP6. Not really sure about previous versions.
 
I'm pretty sure the PADx() functions have done type conversions and trimming since they came into the language.

Tamar
 

Tamar, now that you mentioned it, I checked the paper copy of FoxPro 2.0 documentation I have around. It already has PADx() function (I think now it's been always there, from the start), and it does mention that the expression can be character, numeric, or date types.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top