> SELECT newinit
> LOCATE FOR alltrim(acode) = myscanvalue
> DO WHILE !FOUND( )
You've already got the solution for this, but a general remar would be that Found() is not reset until the next Locate, Continue or Seek.
> x='00'+alltrim(str(val(x)+1))
Another one here: you're adding numbers that look like 001, 002, 003, ... 008, 009, 0010 - but then when you Go Bott it will find 009 as the last one (because they will align as 001, 0010, 002, 003, 004, ... 008, 009), and you'll get 0010 for all after 009. You'd better set
x=tran(val(x)+1, "@L 999999") - i.e. fixed number of digits with leading zeros. They'll line up fine then.