Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've written a Sudoku code and just tried to check if columns were corect. I will be controlling rows and squares later. Although it seems right to me. It doesn't work. the simulator freezes. Here is the code:

TextBox[,] dene = new TextBox[9,9];
Random b = new Random();
int kontrol = 0;
int m=0;

for (int i = 0; i < 9; i++)
{
    for (int j = 0; j < 9; j++)
    {
        dene[i, j] = new TextBox();
        dene[i, j].Text = "0" ;
    }
}


for (int i = 0; i < 9; i++)
{
    for (int j=0;j<9;j++)
    {
        while (m == 0)
        {
            int inta = b.Next(1, 10);
            for (int k = 0; k < 9; k++)
            {
                int c = Convert.ToInt32(dene[i, k].Text);
                if (inta == c)
                {
                    kontrol++;
                }
            }
            if (kontrol == 9)
            {
                dene[i, j].Text = inta.ToString();
                kontrol = 0;
                m = 1;
            }
            else
            {
                kontrol = 0;
            }
        }
        m = 0;
    }
}
Posted

All your textboxes are initialised with '0'. inta is always greater than 0. Never will kontrol++ happen, kontrol always stays 0, and m also. while(m==0) stays true eternally.
 
Share this answer
 
Thanks to your explanation i've found the solutoin with
if (inta != c)
          {
              kontrol++;
          }


Ty very much
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-May-13 10:47am    
Not an answer, should be removed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900