I guess that CX is bigger than or equal to LEN(N$) when the error occurs. Could you try to replace as follows? [line 61] Replace CX=CX+1 with CX=CX+(CX<(LEN(N$)-1)) [line 65] Replace CX=CX-1 with CX=CX-(CX>0)