1
I’m developing software in c# to count the number of electronic anklets that go inside a box. This box has room to store 40 anklets. In the case of Software I put 40 txtbox where each one represents the serial number of each anklet. As it happens the operator sometimes repeat the same anklet in different txtbox, with the help of a known I developed this method below which indicates if there are repeated values within these txtbox that in the case were placed in an Array[39]. So far so good, what happens is that not always the 40 txtbox are filled because sometimes the boxes are incomplete, the problem is that the method indicates duplicity error because as there are fields that are empty, maybe it understands as if they were repeating values. I wonder if, have how I disable the textbox that are not filled. This condition of the code below was put in btsalvarfile. I put the code where I capture the textbox information in the Array and it does a check.
Code:
private void BtnSair_Click(object sender, EventArgs e)
{
System.Windows.Forms.Application.Exit();
}
//Evento onde é feita a verificação de duplicidade da etiqueta.
private void BtnAdicionar_Click(object sender, EventArgs e)
{
Int64[] valores = new Int64[40];
//RATE 01-10
valores[0] = Convert.ToInt64(textBox1.Text);
valores[1] = Convert.ToInt64(textBox3.Text);
valores[2] = Convert.ToInt64(textBox4.Text);
valores[3] = Convert.ToInt64(textBox5.Text);
valores[4] = Convert.ToInt64(textBox6.Text);
valores[5] = Convert.ToInt64(textBox7.Text);
valores[6] = Convert.ToInt64(textBox8.Text);
valores[7] = Convert.ToInt64(textBox9.Text);
valores[8] = Convert.ToInt64(textBox10.Text);
valores[9] = Convert.ToInt64(textBox11.Text);
//RATE 11-20
valores[10] = Convert.ToInt64(textBox12.Text);
valores[11] = Convert.ToInt64(textBox13.Text);
valores[12] = Convert.ToInt64(textBox14.Text);
valores[13] = Convert.ToInt64(textBox15.Text);
valores[14] = Convert.ToInt64(textBox16.Text);
valores[15] = Convert.ToInt64(textBox17.Text);
valores[16] = Convert.ToInt64(textBox18.Text);
valores[17] = Convert.ToInt64(textBox19.Text);
valores[18] = Convert.ToInt64(textBox20.Text);
valores[19] = Convert.ToInt64(textBox21.Text);
//RATE 21-30
valores[20] = Convert.ToInt64(textBox22.Text);
valores[21] = Convert.ToInt64(textBox23.Text);
valores[22] = Convert.ToInt64(textBox24.Text);
valores[23] = Convert.ToInt64(textBox25.Text);
valores[24] = Convert.ToInt64(textBox26.Text);
valores[25] = Convert.ToInt64(textBox27.Text);
valores[26] = Convert.ToInt64(textBox28.Text);
valores[27] = Convert.ToInt64(textBox29.Text);
valores[28] = Convert.ToInt64(textBox30.Text);
valores[29] = Convert.ToInt64(textBox31.Text);
//RATE 31-40
valores[30] = Convert.ToInt64(textBox32.Text);
valores[31] = Convert.ToInt64(textBox33.Text);
valores[32] = Convert.ToInt64(textBox34.Text);
valores[33] = Convert.ToInt64(textBox35.Text);
valores[34] = Convert.ToInt64(textBox36.Text);
valores[35] = Convert.ToInt64(textBox37.Text);
valores[36] = Convert.ToInt64(textBox38.Text);
valores[37] = Convert.ToInt64(textBox39.Text);
valores[38] = Convert.ToInt64(textBox40.Text);
valores[39] = Convert.ToInt64(textBox41.Text);
//Verificando a Duplicidade
int quant_campos = valores.Length;
var groups = valores.Distinct().ToList();
if (quant_campos > groups.Count)
{
MessageBox.Show("EXISTEM VALORES DUPLICADOS", "ATENÇÃO!!!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
return;
Luiz, your question is not clear enough that you can understand and write an answer, please edit it in a way that is better understood. For examples how are you doing to read the txtbox ? and how are they loaded? where the error is occurring ?
– Marco Souza
int quant_groups = values. Where(item => item != null). length; or var quant_groups = values.Where(item => !string.Isnullorempty(item)). length length;
– Marco Souza
It is difficult to give an answer without knowing what you are manipulating, I believe that your verification can be simpler than this trying to do.
– Marco Souza
I put more code information, please make sure it’s clearer where I’m going.
– Luiz Felipe