[Message Deleted]
-
:confused: execute your code in your mind assuming the textbox holds "abc", for two iterations, and you will know. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Why not use the built in methods?
if (e.KeyChar == 13)
{
if (Test1.Text.IndexOfAny(new char[]{'@', '.', ',', '!'}) < 0)
{
MessageBox.Show("The name can' t hold '.', '!', '[]'", "Info", 0, MessageBoxIcon.Error);
return;
}
if (Text1.Text != "")
{
ListBox1.Items.Add(Text1.Text);
}
Text1.Text = "";
}No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
:confused: execute your code in your mind assuming the textbox holds "abc", for two iterations, and you will know. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
Or - and this is just a suggestion, so I'll whisper - use the debugger You might find it helps...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Or - and this is just a suggestion, so I'll whisper - use the debugger You might find it helps...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
I'll pretend I didn't hear that. IMO debuggers are fine for solving hard problems, just looking at the code and executing it mentally is what always has to come first. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
why test after the unwanted characters have been added to the text? why not check them on entry, i.e. use the KeyDown event and refuse the characters. Or even override the IsInputChar() method. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
I'll pretend I didn't hear that. IMO debuggers are fine for solving hard problems, just looking at the code and executing it mentally is what always has to come first. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
I know what you mean, but sometimes I can stare at code and only see what I meant to write!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
why test after the unwanted characters have been added to the text? why not check them on entry, i.e. use the KeyDown event and refuse the characters. Or even override the IsInputChar() method. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
Complicated - what happens if the user pastes it in?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Complicated - what happens if the user pastes it in?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
Correct, one actually needs both kinds of validation to get immediate feedback. IMO issuing a bad character message at the end of a line isn't part of a good UI. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Correct, one actually needs both kinds of validation to get immediate feedback. IMO issuing a bad character message at the end of a line isn't part of a good UI. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
Luc Pattyn wrote:
issuing a bad character message at the end of a line isn't part of a good UI.
That throws most of t'interweb in the bin, then...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Why not use the built in methods?
if (e.KeyChar == 13)
{
if (Test1.Text.IndexOfAny(new char[]{'@', '.', ',', '!'}) < 0)
{
MessageBox.Show("The name can' t hold '.', '!', '[]'", "Info", 0, MessageBoxIcon.Error);
return;
}
if (Text1.Text != "")
{
ListBox1.Items.Add(Text1.Text);
}
Text1.Text = "";
}No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Yep. Now, I could say I left that as an exercise for the reader? Or just admit it: I made a mistake - sorry! Also, to work with your original code it needs to be:
if (e.KeyChar == 13)
{
if (Test1.Text.IndexOfAny(new char[]{'.', '!', '[', ']'}) >= 0)
{
MessageBox.Show("The name can't hold '.', '!', '[]'", "Info", 0, MessageBoxIcon.Error);
return;
}
if (Text1.Text != "")
{
ListBox1.Items.Add(Text1.Text);
}
Text1.Text = "";
}because I added comma and atsign, and forgot your square brackets as well. :-O
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones