Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default True Or False, no matter what... it still displays the false statement

True Or False, no matter what... it still displays the false statement

If X = Y then
msgbox("They are equal")
else
msgbox("They are not equal")
end if

Ok, both X and Y are set to 3. But, the message box "They are no
equal" is still shown.

I know that both X and Y is set to 3 because when the macro is runnin
I but my curser over the variable and it tells me it is equal to 3

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default True Or False, no matter what... it still displays the false statement

This works for me:

''''''''''''''''''''''''
Dim X As Double, Y As Double
X = 3
Y = 3

If X = Y Then
MsgBox ("They are equal")
Else
MsgBox ("They are not equal")
End If
''''''''''''''''''''''''''''''''''''''

--
steveb
(Remove 'NOSPAM' from email address if replying direct)


"rocky640 " wrote in message
...
True Or False, no matter what... it still displays the false statement

If X = Y then
msgbox("They are equal")
else
msgbox("They are not equal")
end if

Ok, both X and Y are set to 3. But, the message box "They are not
equal" is still shown.

I know that both X and Y is set to 3 because when the macro is running
I but my curser over the variable and it tells me it is equal to 3.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default True Or False, no matter what... it still displays the false statement

Rocky,

How are the variables X and Y declared, and are their values
computed? It might be the case that the inherent rounding issues
with Double or Single variables causes their values to be
unequal. For example, X might be 3.00000000000001 and Y might be
3.000000000002.

What happens if you write your code like

If Abs(X-Y) < 0.0001 Then

You might want to post the code that assigns the values to X and
Y.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com






"rocky640 " wrote in
message ...
True Or False, no matter what... it still displays the false

statement

If X = Y then
msgbox("They are equal")
else
msgbox("They are not equal")
end if

Ok, both X and Y are set to 3. But, the message box "They are

not
equal" is still shown.

I know that both X and Y is set to 3 because when the macro is

running
I but my curser over the variable and it tells me it is equal

to 3.


---
Message posted from http://www.ExcelForum.com/



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
TRUE/FALSE STATEMENT Dave Excel Discussion (Misc queries) 4 September 1st 09 11:55 AM
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
TRUE/FALSE function in IF statement Caelan Aegana Excel Worksheet Functions 2 July 21st 08 11:45 PM
Two TRUE to one FALSE statement bluebird Excel Worksheet Functions 4 January 11th 07 05:07 PM
If Statement returns true when false? Eric Excel Discussion (Misc queries) 3 September 11th 06 01:58 PM


All times are GMT +1. The time now is 03:11 PM.

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

About Us

"It's about Microsoft Excel"