Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-02-09
4
Medium Priority
?
77 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

636 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