I recommend you to replace line 9-11 with the follows. I=INDEX MOD 50 Y=INDEX DIV 50