Solved

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

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 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