Convert boolean to a 1 or 0

  • Thread starter Thread starter Alex Stevens
  • Start date Start date
A

Alex Stevens

Hi All,

I want to cleanly convert a boolean value to a bit value (1 or 0) in vb.net.

I can:

Math.Abs(CInt(bolValue))

or:

cint(bolValue) * -1

However, I wondered if there was a built-in method.

Thanks

Alex
 
Alex Stevens said:
I want to cleanly convert a boolean value to a bit value (1 or 0) in
vb.net.

I can:

Math.Abs(CInt(bolValue))

or:

cint(bolValue) * -1

However, I wondered if there was a built-in method.

The cleanest method is to make a function that does it. It will make your
code more readable as well.

Or does VB still have the IIF function?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
* "Chad Z. Hower aka Kudzu said:
The cleanest method is to make a function that does it. It will make your
code more readable as well.

Or does VB still have the IIF function?

Yes, 'IIf' still exists.

OT: Nice X-Face.
 
Chad Z. Hower aka Kudzu said:
Use IIF then. :)

As an alternative (and in my mind a "cleaner" alternative) you may want to
consider defining a new datatype. A structure should be able to handle the
basic "Boolean" behavior and provide a "ToInteger" method as well.

Tom
 
Back
Top