473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

AND statement

Expand|Select|Wrap|Line Numbers
  1. public void FormEvents_Loading(object sender, LoadingEventArgs e)
  2.         {
  3.             XPathNavigator root = MainDataSource.CreateNavigator(); 
  4.  
  5.             XPathNavigator C1 = this.CreateNavigator();
  6.             string txtC1 = C1.SelectSingleNode("/my:myFields/my:field76",     this.NamespaceManager).Value;
  7.  
  8. XPathNavigator C2 = this.CreateNavigator();
  9.              string txtC2 = C2.SelectSingleNode("/my:myFields/my:field79", this.NamespaceManager).Value;
  10.  
  11.              XPathNavigator C3 = this.CreateNavigator();
  12.             string txtC3 = C3.SelectSingleNode("/my:myFields/my:field83", this.NamespaceManager).Value;
  13.  
  14.             if (!this.New)
  15.            if (txtC1 == "false" && txtC2 == "false" && txtC3 == "false")
  16.              {
  17.                 e.CancelableArgs.Cancel = true;
  18.                 e.CancelableArgs.Message = "You don't have permission to open the form";
  19.                 return;
  20.               }
  21.         }
Even if txtC1, txtC2 & txtC3 values equals false, form opens up. If I just use one condition like: if(txtC1 == "false", code does work (form will not open)

Looks like AND operator is not working? as each individual check works.
May 21 '09 #1
5 1502
tlhintoq
3,525 Expert 2GB
It really helps if you describe your need/goal and the problem someplace in your post. Yeah, we can infer your intent here but its not to not make the people who are going to help you have to struggle just to figure out the question.

Line 14 does nothing
You have not enclosed the block following that "if" condition with braces, so there is no block to execute if this.New is not true

Remember that comparrisons to strings are case sensitive.
You really want to check in a manner that bypasses that.
if (txtC1.ToLower() == "false" && txtC2.ToLower() == "false"

Put a breakpoint on line 15. When code stops there hover your mouse over the 3 values or look in the watch window to see what the actual values are of txtC1,2,3. I'll bet you find they are not "false". All it would take is an extra space for example and they would not == "false". A more forgiving check might be
if (txtC1.ToLower().Contains("false") && txtC1.ToLower().Contains("false")
May 21 '09 #2
Sorry for not mentioning what i am looking to achieve.

Goal: If the form is Not new AND txtC1 AND txtC2 AND txtC3 == "false", dont open the form.

I put a line break on line 15 and looks like all values are "false".

As menetioned in original post, if I try

txtC1 == "false" or txtC2 == "false" or txtC3 == "false" individually, I get the desired result (form doesn't open)

thanks
May 21 '09 #3
tlhintoq
3,525 Expert 2GB
I guess I"m a little confused as to what conditions you could create where you would being opening a form what wasn't "new". I'm not really sure what you mean by new? Are you trying to create a form that can only open one instance?

If so I'm not so sure I would try to put that code in the form. You have to create the second instance in order to have a .Loading() which is where you check exists. That means you allocate time, memory, resources, objects to the creation of a second instance whether you intend to use it or not. Why create all that just to delete it again? If your CALLING code checks to see if it already exists it can keep a second instance from every being created.

Had you considered only creating one instance of the form then using the ".Show()" and ".Hide()" methods? Thus it always exists, it just may not be visible.

As menetioned in original post, if I try

txtC1 == "false" or txtC2 == "false" or txtC3 == "false" individually, I get the desired result (form doesn't open)
Right, because at least one really is equal to "false" EXACTLY. You said that if you only checked txtC1 that it worked fine. This would indicate that txtC2 or txtC3 is not really an EXACT match for "false".

Another way to diagnose it might be to output those three variables to the console just before you check them.

Or nest your 'if' statements so you can better find the mismatach

Expand|Select|Wrap|Line Numbers
  1. if (txtC1.Text.ToLower().Contains("false"))
  2. {
  3.    console.Writeline("1 matched");
  4.    if (txtC2.Text.ToLower().Contains("false"))
  5.    {
  6.       console.Writeline("2 matched");
  7.          if (txtC3.Text.ToLower().Contains("false))
  8.          {
  9.             //  This can only be reached if all three match
  10.          }
  11.       }
  12.    }
  13. }
May 21 '09 #4
No, If I check ANY of the three (txtC1, txtC2, txtC3) alone, it works ...meaning they all equates to "false"

if(txtC1 =="false") .... this statement works

if(txtC2== "false)".....this statement works

if(txtC3 == "false") .... this statement also works.


Problem is when I try to AND them, then it doesnt work.
(if txtC1 == "false" && txtC2 =="false" && txtC3 == "false")
May 21 '09 #5
tlhintoq
3,525 Expert 2GB
@andyoye
Expand|Select|Wrap|Line Numbers
  1.             string txtC1 = C1.SelectSingleNode("/my:myFields/my:field76",     this.NamespaceManager).Value;
These values are only being set one time, at creation.
Perhaps they should become properties so they get updated every time you check them. Sometimes thing don't happen as fast or exactly in the sequence we think they do. They may not equal "false" when created, but do equal "false" millisenconds later at the time you check them, because their values have finally returned.

Expand|Select|Wrap|Line Numbers
  1. string txtC1
  2. {
  3. get
  4. {
  5. return  C1.SelectSingleNode("/my:myFields/my:field76",   this.NamespaceManager).Value;
  6. }
  7. }
  8.  
May 22 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.