Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I add an integer to an existing integer? | Excel Worksheet Functions | |||
IF vs Boolean | Excel Discussion (Misc queries) | |||
boolean question | Excel Worksheet Functions | |||
More on Boolean | New Users to Excel | |||
VBA Boolean | Excel Discussion (Misc queries) |