>this code under it works, is there another way to rewrite it...
>[SNIP]For starters, never use an area by number. Your program should not care where the files are open. Do a SELECT 0 if you need to get the next available area, then chose the file by alias, not area number.
You can replace the whole DO WHILE with SCAN..ENDSCAN and the whole assignment with SCATTER MEMVAR (or SCATTER MEMEVAR NAME if you prefer an object).
create table newcurbilldata (....)
select 0
use curbilldata
scan
scatter memvar
inset into newcurbilldata from memvar
endscan
Also, never use single letter variables from "a" to "j" plus "m" as they are reserved words:
m.d=Sec2Str(tot_m)
This is not safe. Just change the variable names.
There could be other, more optimized ways, but this one is the first that jumpos out.