how to IF?!
-
There is no room for guessing in software development.
bool isBad = text1!="" && text2==""
[CORRECTION: TextBox.Text never is null, it is an empty or a non-empty string] :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
modified on Friday, April 9, 2010 6:17 PM
I prefer this for String type: bool isBad = ((String.IsNullOrEmpty(text1) == true) || (String.IsNullOrEmpty(text2))) My 2 cents
-
yes but this code will force the user to enter one of the textbox.. What if the user wants to leave the null?
-
yes but this code will force the user to enter one of the textbox.. What if the user wants to leave the null?
-
Ok it's quite late here and I'm tired so I could be wrong, but I'm fairly certain that if they are both null, that condition will evaluate to
true
it's ok.. rest now :) I will also sleep and come back later... it's 1:30am here in Bahrain.. Sweet Dreamz :)
-
I have two textbox BP_S and BP_D how can I make sure if one textbox is not null then the other should not be null as well... && and || won't worked I guess..
Wow, this is probably the first time I've seen a valid use for the EXCLUSIVE OR operator:
if (!(string.IsNullOrEmpty(textBox1.Text) ^ string.IsNullOrEmpty(textBox2.Text)))
{
MessageBox.Show("Valid");
}
else
{
MessageBox.Show("Invalid");
}You could also do that with && and ||, but this is probably the most succint technique.
-
Wow, this is probably the first time I've seen a valid use for the EXCLUSIVE OR operator:
if (!(string.IsNullOrEmpty(textBox1.Text) ^ string.IsNullOrEmpty(textBox2.Text)))
{
MessageBox.Show("Valid");
}
else
{
MessageBox.Show("Invalid");
}You could also do that with && and ||, but this is probably the most succint technique.
-
Wow, this is probably the first time I've seen a valid use for the EXCLUSIVE OR operator:
if (!(string.IsNullOrEmpty(textBox1.Text) ^ string.IsNullOrEmpty(textBox2.Text)))
{
MessageBox.Show("Valid");
}
else
{
MessageBox.Show("Invalid");
}You could also do that with && and ||, but this is probably the most succint technique.
most succinct? if exclusive OR is what the OP wants, then there is no need for XOR, OR, AND operators! Mind you, TextBox.Text never returns null.
MessageBox.Show((textBox1.Text.Length==0)==(textBox2.Text.Length==0)?"Valid":"Invalid");
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
-
I have two textbox BP_S and BP_D how can I make sure if one textbox is not null then the other should not be null as well... && and || won't worked I guess..
:doh:
if((!String.IsNullOrEmpty(BP_S.Text) && !String.IsNullOrEmpty(BP_D.Text)) || (String.IsNullOrEmpty(BP_S.Text) && String.IsNullOrEmpty(BP_D.Text)))
Mark as answer if its really satisfies ur query !!!! :)
modified on Saturday, April 10, 2010 8:52 AM
-
:doh:
if((!String.IsNullOrEmpty(BP_S.Text) && !String.IsNullOrEmpty(BP_D.Text)) || (String.IsNullOrEmpty(BP_S.Text) && String.IsNullOrEmpty(BP_D.Text)))
Mark as answer if its really satisfies ur query !!!! :)
modified on Saturday, April 10, 2010 8:52 AM
-
most succinct? if exclusive OR is what the OP wants, then there is no need for XOR, OR, AND operators! Mind you, TextBox.Text never returns null.
MessageBox.Show((textBox1.Text.Length==0)==(textBox2.Text.Length==0)?"Valid":"Invalid");
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
You fool! It can be MUCH more succint!
MessageBox.Show((textBox1.Text.Length>0)==(textBox2.Text.Length>0)?"Valid":"Invalid");
-
You fool! It can be MUCH more succint!
MessageBox.Show((textBox1.Text.Length>0)==(textBox2.Text.Length>0)?"Valid":"Invalid");
Do you mean
MessageBox.Show(((tb1.Text.Length>0)==(tb2.Text.Length>0)?"V":"Inv")+"alid");
? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
-
Do you mean
MessageBox.Show(((tb1.Text.Length>0)==(tb2.Text.Length>0)?"V":"Inv")+"alid");
? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Haha, I did exactly that, but then found it to take up more characters than the other method, to be less clear, and to potentially take up more processing time (the strig concatenation). If you make both words lowercase, you can get it down to exactly the same number of characters as the one I posted, but it still has the other issues. But nice try. ;)
-
Haha, I did exactly that, but then found it to take up more characters than the other method, to be less clear, and to potentially take up more processing time (the strig concatenation). If you make both words lowercase, you can get it down to exactly the same number of characters as the one I posted, but it still has the other issues. But nice try. ;)
correct.
MessageBox.Show((tb1.Text.Length>0)==(tb2.Text.Length>0)?"OK":"!OK");
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
-
correct.
MessageBox.Show((tb1.Text.Length>0)==(tb2.Text.Length>0)?"OK":"!OK");
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I had a nice long reply I was working on, but my Internet decided to go down just as I posted it. So, lucky for you, you get the short version instead:
((a.L>0)==(b.L>0)).S();
;P
-
Now that's interesting, because that wouldn't allow you to fill in the second textbox if you didn't fill in the first as well - and he never said anything about that. Basically it's the same as aspdotnetdev's, but in the least-succinct way.
harold aptroot wrote:
he never said anything about that
FYI, my impression is that the OP wants either both to be filled in or neither to be filled in. Filling in one without filling in the other is not allowed.
-
I had a nice long reply I was working on, but my Internet decided to go down just as I posted it. So, lucky for you, you get the short version instead:
((a.L>0)==(b.L>0)).S();
;P
why would you need a long reply to come up with a succinct code snippet? Anyway, with a real pre-processor, it is trivial:
T
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
-
harold aptroot wrote:
he never said anything about that
FYI, my impression is that the OP wants either both to be filled in or neither to be filled in. Filling in one without filling in the other is not allowed.
Ok, I think he just said that he wants a truth table like this:
D S result
0 0 1
0 1 1
1 0 0
1 1 1IOW "everything is OK except skipping the second textbox after filling in the first" The smallest formula for that truth table is, AFAIK, (¬D)v S (where v is OR) Or maybe I'm just taking his explanation too literally..
-
why would you need a long reply to come up with a succinct code snippet? Anyway, with a real pre-processor, it is trivial:
T
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
If my Internet didn't go down, you'd know. ;P Why use a letter with such a high ASCII value? This seems more optimal:
A
As a bonus, your left pinky is already on that letter. :rolleyes:
-
Ok, I think he just said that he wants a truth table like this:
D S result
0 0 1
0 1 1
1 0 0
1 1 1IOW "everything is OK except skipping the second textbox after filling in the first" The smallest formula for that truth table is, AFAIK, (¬D)v S (where v is OR) Or maybe I'm just taking his explanation too literally..
The OP said "one textbox is not null then the other should not be null as well". Order of the textboxes is never stated or implied. So "0 1" and "1 0" should have the same result ("0").
-
The OP said "one textbox is not null then the other should not be null as well". Order of the textboxes is never stated or implied. So "0 1" and "1 0" should have the same result ("0").