Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default boolean to integer

Can I convert a boolean expression e.g. (m=2), into a 1 or
0 during a VBA calculation without resorting to if
statements or the like?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default boolean to integer

You can multiply the boolean expression with 1
(m=2)*1

Frank

sphenisc wrote:
Can I convert a boolean expression e.g. (m=2), into a 1 or
0 during a VBA calculation without resorting to if
statements or the like?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default boolean to integer

Dim Expression As Boolean

Expression=(m=2)


If m=2 (2=2)
Expression will be true, which is -1 (negative one) in VBA
(In Excel, True is 1), so Expression= -1

If m<2, then Expression is false, so Expression= 0

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"sphenisc" skrev i en meddelelse
...
Can I convert a boolean expression e.g. (m=2), into a 1 or
0 during a VBA calculation without resorting to if
statements or the like?

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default boolean to integer

A boolean expression used in a math expression returns -1
for true, 0 for false. This is actually very convenient:
just precede it with a - (negative sign) and it will
return 1 for true, 0 for false!

HTH,
Nikos
-----Original Message-----
Can I convert a boolean expression e.g. (m=2), into a 1

or
0 during a VBA calculation without resorting to if
statements or the like?

Thanks
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default boolean to integer

On Tue, 13 Jan 2004 03:49:24 -0800, "sphenisc"
wrote:

Can I convert a boolean expression e.g. (m=2), into a 1 or
0 during a VBA calculation without resorting to if
statements or the like?

Thanks


You can just use it in a mathematical expression and it will convert
automagically.

However, you must be aware that in VBA, FALSE = 0 and TRUE = -1.

So you may want to use a Unary or an ABS function.


--ron
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
How do I add an integer to an existing integer? Aaron Excel Worksheet Functions 3 December 17th 09 09:46 PM
IF vs Boolean Brad Excel Discussion (Misc queries) 3 September 4th 09 01:58 AM
boolean question Lisa Excel Worksheet Functions 1 September 5th 08 12:53 PM
More on Boolean Epinn New Users to Excel 7 November 28th 06 09:29 AM
VBA Boolean Jeff Excel Discussion (Misc queries) 1 February 2nd 06 10:01 PM


All times are GMT +1. The time now is 06:49 AM.

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"