Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Problem: True vs. False

Hi,

I am using excel and VB to do my work and when some wrong result is
returned in excel, I debug my code to find where it is wrong. When I
evaluated a particular statement: -

'Checks if the edges and sensor center point are close to the line B
ElseIf (Abs((Abs((mB * SensorX) - SensorY + cB) / (Sqr((mB ^ 2) + 1)))
- SensorRadius) <= 0.03) Or
((Abs((mB * SensorX) - SensorY + cB) / (Sqr((mB ^ 2) + 1))) <= 0.03)
And
((SensorY ((mC * SensorX) + cC))
And
(SensorY < ((mA * SensorX) + cA)))
Then
InRange = "X"

I found out that 1st, 2nd and 4th statments gave me True whereas the
third statment gave me a False. Now the entire result must be a False.
(True or True And False And True) = False. But instead I get True.
What is wrong???? I have assigned my brackets correctly and I cant see
why this problem is caused? Can anyone please help? Thanks

Swamy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Problem: True vs. False

Swamy,

Perhaps you need to group the 1st and 2nd conditions together..i.e.,

True or True And False And True = True

but,

(True or True) And False And True = False


--
Hope that helps.

Vergel Adriano


"Mahadevan Swamy" wrote:

Hi,

I am using excel and VB to do my work and when some wrong result is
returned in excel, I debug my code to find where it is wrong. When I
evaluated a particular statement: -

'Checks if the edges and sensor center point are close to the line B
ElseIf (Abs((Abs((mB * SensorX) - SensorY + cB) / (Sqr((mB ^ 2) + 1)))
- SensorRadius) <= 0.03) Or
((Abs((mB * SensorX) - SensorY + cB) / (Sqr((mB ^ 2) + 1))) <= 0.03)
And
((SensorY ((mC * SensorX) + cC))
And
(SensorY < ((mA * SensorX) + cA)))
Then
InRange = "X"

I found out that 1st, 2nd and 4th statments gave me True whereas the
third statment gave me a False. Now the entire result must be a False.
(True or True And False And True) = False. But instead I get True.
What is wrong???? I have assigned my brackets correctly and I cant see
why this problem is caused? Can anyone please help? Thanks

Swamy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Problem: True vs. False

I found out that 1st, 2nd and 4th statments gave me True whereas the
third statment gave me a False. Now the entire result must be a False.
(True or True And False And True) = False. But instead I get True.
What is wrong???? I have assigned my brackets correctly and I cant see
why this problem is caused? Can anyone please help? Thanks


AND has a higher operator precedence than OR, so

True Or True And False And True

evaluates the ANDs first, before the OR... this means the intermediate
result, after the ANDs are handled, is this...

True Or False

which evaluates to True. You can use parentheses to force the order of
precedence handling. If that first term is supposed to be "grouped" with the
second term, just enclose them both in parentheses. Using your True, False
example (instead of repeating the actual logical expressions), this is what
you need...

(True Or True) And False And False

which will equate to False.

Rick

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Problem: True vs. False

Thanks for your help. It finally worked :).

Swamy


On Jun 8, 1:32 pm, "Rick Rothstein \(MVP - VB\)"
wrote:
I found out that 1st, 2nd and 4th statments gave me True whereas the
third statment gave me a False. Now the entire result must be a False.
(True or True And False And True) = False. But instead I get True.
What is wrong???? I have assigned my brackets correctly and I cant see
why this problem is caused? Can anyone please help? Thanks


AND has a higher operator precedence than OR, so

True Or True And False And True

evaluates the ANDs first, before the OR... this means the intermediate
result, after the ANDs are handled, is this...

True Or False

which evaluates to True. You can use parentheses to force the order of
precedence handling. If that first term is supposed to be "grouped" with the
second term, just enclose them both in parentheses. Using your True, False
example (instead of repeating the actual logical expressions), this is what
you need...

(True Or True) And False And False

which will equate to False.

Rick



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the best way to toggle between true and false in Excel? Hiall, My excel work involves a lot of toggling between true and false (booleantypes) ... and it's very repetitive... Is there a way to select a bunch ofcells, and press a key short-cu LunaMoon Excel Discussion (Misc queries) 9 July 29th 08 12:28 AM
Search for 2 true arguments and return true or false David Excel Discussion (Misc queries) 3 July 15th 06 10:18 AM
Function to return True/False if all are validated as True by ISNU Tetsuya Oguma Excel Worksheet Functions 2 March 15th 06 10:28 AM
True / false output problem paul thomas Excel Programming 3 June 9th 04 06:46 PM
True Or False, no matter what... it still displays the false statement rocky640[_2_] Excel Programming 2 May 13th 04 04:57 PM


All times are GMT +1. The time now is 12:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"