Hi,
I'm experimenting with using a tile based system for a game, the colour of the tiles are based off the int which is found when converting a char array storing the integer found in a text file. 0 is a black tile, 1 is a green tile and 2 is a new line.

This is the code which places the tiles:
Code:
   public void createMap() {

            for (int y = 0; y <= 5; y++ )
            {

                for (int x = 0; int.Parse(readMapArray[tileIndex].ToString()) < 2; x++ )
                {
                    tileIndex++;
                    createTile(int.Parse(readMapArray[tileIndex].ToString()));
                    tilePoint = new Point(tilePoint.X + 32, tilePoint.Y);
                }
                tileIndex++;
                tilePoint = new Point(0, tilePoint.Y + 32);
            }

        }
I get a "Format exception was unhandelled" error on the line when the second for loop initialises.
I only get the error when i include the second incrementation of tileIndex. however, if i take this out, it only creates the first line of tiles (because it doesn't increment the next index past the value of 2).

This is my code to change the colour of the tile (the createTile):

Code:
 public void createTile(int tileType) {
            PictureBox tile = new PictureBox();
            tile.Location = tilePoint;
            tile.Height = 32;
            tile.Width = 32;
            tile.Visible = true;
            if (tileType == 0)
            {
                tile.BackColor = Color.Black;
            }
            if (tileType == 1) {
                tile.BackColor = Color.GreenYellow;
            }
            this.Controls.Add(tile);
            
        }
This problem actually kept me awake for hours last night just thinking about it.
Why is this error happening and what can I do to solve it?

Thanks in advance

Arrokai