lundi 13 juillet 2020

cicle if-do while not working, but seems perfect

im doing a "winners table", from a excel page, this cicle is to find the winner:

            if (G1 != "0")
            {
                do
                {
                    D1 = dgv1.Rows[con].Cells[0].FormattedValue.ToString();
                    D2 = dgv1.Rows[con].Cells[1].FormattedValue.ToString();
                    D3 = dgv1.Rows[con].Cells[2].FormattedValue.ToString();
                    D4 = dgv1.Rows[con].Cells[3].FormattedValue.ToString();

                    if (D1 == G1)
                    {
                        TablaGanadores.Rows.Add(D1.ToString(), D2.ToString(), D3.ToString(), D4.ToString());
                        break;

                    }
                    else
                    {
                        con++;
                    }


                }
                while (con < 999);
            }

There are a Textbox where you put the winner number, it's default valor is "0", that's why if G1 (the number in Textbox) is not 0, it will continue doing the cicle "Do-While", there i put in D1,D2,D3,D4 the data from 1 row in excel page (they work alone outside the cicle), then the cicle, if D1 (where is the number to compare) is the same as the winner number in the Textbox, it will create a new row in my table "TablaGanadores", with D1,D2,D3,D4 (it works outside of cicle), then, it breaks the cicle, else, just add 1 to my counter, to check the next row in my excel file, and there are 999 rows

But it just don't work, and im in my limit day to give my program, and this is the last thing in it, my head will explode, i don't find the error

Aucun commentaire:

Enregistrer un commentaire