>>>The problem would be if REPLACE changes the fields in the current index. It may change position of the current record in the index so the next record would be not the one before REPLACE. It doesn't have anything to do with SCAN/ENDSCAN though and would have the same effect in DO WHILE or any other loop.
>>
>>I know that this may cause problems, but I remember this happening to me without changing the indexed fields. I attributed it to Rushmore Optimization.
>>
>>IIRC, it was years ago, in FoxPro 2.x.
>
>I belive that you're mistaken. I never encounter anything even close in Fox 2.6 or later.
Trying to reproduce the behaviour, I came up with the following test file. It seems to confirm my claims. Any comments? I tested it in VFP 6 and VFP 8.
On the other hand, replacing the REPLACE ALL with a SCAN / REPLACE / ENDSCAN produces the results in the expected order, invalidating my original claim.
create cursor TestFile (KeyField I, FieldToReplace I)
index on KeyField tag KeyField
set order to "KeyField"
insert into TestFile (KeyField) values (1)
insert into TestFile (KeyField) values (3)
insert into TestFile (KeyField) values (5)
insert into TestFile (KeyField) values (4)
insert into TestFile (KeyField) values (2)
Sequence = 0
replace all FieldToReplace with MySequence()
browse normal
function MySequence
Sequence = Sequence + 1
return Sequence
endfunc
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)