0
I have a part of my program that I do several checks when the button is clicked and one of these checks is: it picks the value inserted in textboxRankTecnica
and has to buy with the array ranksAceitaveis
. If he enters a value that is not in ranksAceitaveis
, he has to display the MessageBox
. If it is the same, it continues with the code, but the big problem is that even typing an acceptable value, it launches the textbox
. Codes I’ve tried (none of them did what they wanted, because even typing a correct value, it returns the message):
string[] ranksAceitaveis = new string[] { "E", "E+", "D", "D+", "C", "C+", "B", "B+", "A", "A+", "S", "S+", "S++" };
else if (textBoxRankTecnica.Text.Length > 0)
{
for (int i = 0; i <= (ranksAceitaveis.Length - 1); i++)
{
if (!textBoxRankTecnica.Text.Contains(ranksAceitaveis[i]))
{
passouCriacao = false;
MessageBox.Show("O Rank digitado é inválido [...]".", "Rank inválido", MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
}
}
}
/*outro codigo:*/ string[] ranksAceitaveis = new string[] { "E", "E+", "D", "D+", "C", "C+" , "B", "B+", "A", "A+", "S", "S+", "S++"};
else if (textBoxRankTecnica.Text != ranksAceitaveis.ToString().ToLowerInvariant())
{
passouCriacao = false;
MessageBox.Show("O Rank inserido é inválido, digite um [...]".", "Rank inválido", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/*outro codigo:*/ else if (textBoxRankTecnica.Text != "E".ToLowerInvariant() || textBoxRankTecnica.Text != "E+".ToLowerInvariant()) //E o resto das verificações
/*outro codigo:*/ else if (textBoxRankTecnica.Text.Length > 0)
{
for (int i = 0; i <= (ranksAceitaveis.Length - 1); i++)
{
if (textBoxRankTecnica.Text != ranksAceitaveis[i].ToString().ToLowerInvariant())
{
passouCriacao = false;
MessageBox.Show("Text [...]".", "Rank inválido", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
Is this what you want? https://dotnetfiddle.net/5sJWKh
– Maniero
Nor was it for my case. Even if I enter a correct value (the ones in the variable "ranksAceitaveis") it continues with the same error. It’s boring this, huh e.e.g. I don’t know why any of these codes have worked so far . But still, thanks for trying to help.
– Wevelly Felipe
Probably because you don’t know how to get what you want. Your question only has a few codes played, it is difficult to help so you need to define what should happen clearly before anything else. What’s more, based on the codes you posted that were written almost randomly, something tells me it didn’t work for you because it modified something it shouldn’t. The problem is just not well explained. This posted did not have the slightest chance of working because they do not make sense. If you don’t understand what you’re doing you won’t be able to program anything.
– Maniero
"Codes played" I believe the way I wrote generated it. They are not codes played, they are attempts. /another code/ means it’s another try, note the question that has "codes I’ve tried". The intention was to divide each attempt into a separate block, I couldn’t, so I did it by comment. Maybe I already have an idea of what might be going on and I’ll try to solve it.
– Wevelly Felipe
I took your idea as a basis and adapted it to my needs and it worked. Thank you!
– Wevelly Felipe
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero