Really?
Code:
i=0
scan
i=i+1
replace something with i
endscan
Merely on the subject of understanding and implementing instructions, you fail to do the simplest things. If you can't follow a recipe how do think you cope in inventing recipes?
Doing it step by step in slow motion:
1. To populate the field with consecutive numbers, write a loop;
Code:
[highlight #FCE94F]scan
endscan[/highlight]
2. each time round the loop, replace the field with an integer;
Code:
scan
[highlight #FCE94F]replace thefield with aninteger[/highlight]
endscan
3. start the integer at zero, ...
Code:
[highlight #FCE94F]aninteger=0[/highlight]
scan
replace thefield with aninteger
endscan
4. ...and increment it by one each time round the loop.
Code:
aninteger=0
scan
[highlight #FCE94F]aninteger=aninteger+1[/highlight]
replace thefield with aninteger
endscan
5. Do that immediately after setting the index
Code:
[highlight #FCE94F]set order to index[/highlight]
aninteger=0
scan
aninteger=aninteger+1
replace thefield with aninteger
endscan
If you can't even do that, you disqualify to get to your goals. And don't expect now that this code runs as is, it has some prerequisites for working, mainly a table with a field named "thefield" capable to store an integer value.
Since Mike recommends thefield to be part of the table, you have a problem if two users watch the data in different order and each overwrites the others order. That problem can be solved by having thefield in a separate local table or cursor, but I won't go into the details.
What's so bad about this is that the SET ORDER TO really happens immediately, but the scan loop will take its time. If you have a few records, this will still be fine and seemingly fast. But if you have a complex filter condition, probably even not optimizable, then this will slow things down. When you SET FILTER TO, you don't do a query and VFP does not check all rows and marks them inside or outside of the filter condition, that condition is set means it will be checked every time you skip a row, every time you go forward or change current record in any way on that single record you are now at. And alone that aspect also means, if a row is edited in a way not matching the filter anymore, the row will disappear and so you will have a row number gap.
If you take this forward it means at least every time you leave a record you need to check, whether your numbering still is valid, not just at SET ORDER and SET FILTER changes. It doesn't work out, because your main task and the main thing users will need to wait for is for your loop to have renumbered the rows.
Bye, Olaf.