Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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