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

VFP 6 string substitution 1

Status
Not open for further replies.

wetton

Technical User
Jun 26, 2006
42
0
0
AU
I want to contruct a loop to process ten fields


for a 1 to 10

SELECT temp2

IF !empty(temp2.addr_1)
SELECT TEMP_1
REPLACE TEMP_1.Place1 with temp2.addr_1
ENDIF

endfor

I want the addr_n and Placen to be substituted instead of using 10 statements as at present.

Many thanks

PW
 
I cannot remember if you have it in VFP 6, but take a look at FIELD() in help. It returns the name of a field 1, field 2, etc. You could use this to create a REPLACE statement that you could run using macro substitution.

For example,

FOR i = 1 TO FCOUNT([MyTable])
IF NOT EMPTY(FIELD(i,[MyTable]))
lcReplaceCmd = [REPLACE ]+FIELD(i,[MyTable])+;
[WITH ]+FIELD(i,[MySecondTable])+;
[IN 'MyTable']
&lcReplaceCmd
ENDIF
ENDFOR

Untested and off-the-cuff, but it should get you started.
Ken
 
PW try this:


local lcPlace
local lcAddr
local a

for a 1 to 10

lcPlace = "Place" + transform(a)
lcAddr = "Addr" + transform(a)

if not empty(Temp2.&lcAddr)
replace &lcPlace with Temp2.&lcAddr in Temp1
endif

endfor


Goodluck,
Shardlow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top