>Ctr$= FORMAT(ctr$,"###########")
That won't work correctly if the digit after the space is a 0 (and there's nothing in the OP to suggest that it might not be).
Mind you, reviewing the original code suggests the whole problem can be avoided by using one of two different conversion techniques:
Change [tt]ctr$ = STR$(ctr[/tt]) to [tt]ctr$ = CStr$(ctr)[/tt]
or delete [tt]ctr$ = STR$(ctr)[/tt] and change [tt]a$ = a$ + "000" + ctr$[/tt] to [tt]a$ = a$ + "000" + ctr[/tt] (or, perhaps better, [tt]a$ = a$ & "000" & ctr[/tt])