Solved

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

Posted on 2015-02-09
4
56 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 33

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 69

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 33

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now