Solved

The && logical operator is not working or is it me?

Posted on 2015-02-09
4
60 Views
Last Modified: 2015-02-09
Hi, I'm using vs2012
Please see attached code.

This value,  gridEditUser.Enabled.Value, is false.  I double check it in the debug mode.  The rest of the || condition would evaluate to be true.  Problem that is blows my mind that it apparently evaluate to be true and went on to process the rest of the code.
And-Operator.txt
0
Comment
Question by:lapucca
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40599231
I am looking at it closely. But AND in English writing translates to OR in programming.

It is like executing items to by per this select statement:

Select Fruit From Produce
Where Fruit = 'Apple' OR  Fruit = 'Orange'

This person was told Apple and Orange. So he will have Apple and Orange in the list.

The following will have nothing to return:

Select Fruit From Produce
Where Fruit = 'Apple' AND  Fruit = 'Orange'
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 40599241
try this:

           
     if( gridEditUser.Enabled.Value && ( (String.IsNullOrEmpty(gridEditUser.Surname)) || (String.IsNullOrEmpty(gridEditUser.GivenName))  || (String.IsNullOrEmpty(gridEditUser.MiddleName)) || (String.IsNullOrEmpty(gridEditUser.VoiceTelephoneNumber)) ) )
                {
                    e.Cancel = true;
                    lblError.Visible = true;
                    lblError.Text = "First Name, Last Name, Middle Name and Cell Phone fields are all reqired.";
                    return;
                }

Open in new window

0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40599261
Maybe that holds in SQL only, your testing will determine if it is the same in procedural programming.

Typos fixed...

It is like executing items to buy per the list produced by the select statement below:

Select Fruit From Produce
Where Fruit = 'Apple' OR  Fruit = 'Orange'

This person was told to buy Apple AND Orange. So he will have Apple and Orange in the above list to buy

But, the following will have nothing to return, so he will not buy Apple or Orange.

Select Fruit From Produce
Where Fruit = 'Apple' AND  Fruit = 'Orange
0
 

Author Closing Comment

by:lapucca
ID: 40599280
Thank you.  I thought I was losing my mind.  I was just missing the parenthesis.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question