Text representations of Booleans

  • Thread starter Thread starter John Dann
  • Start date Start date
J

John Dann

This question is just for my education as there are some simple and
obvious workarounds, but...

I have an array of Booleans that I need to export to a text file.
Currently the Boolean values are appearing in the text file as the
text strings True/False, but I need them as the integers 1 and 0 (for
input to another program that only recognises Booleans in integer
form). Have I overlooked a suitable Boolean method (eg if there were a
Boolean.ToInteger) that can do this at one stroke?

Thanks
JGD
 
John said:
I have an array of Booleans that I need to export to a text file.
Currently the Boolean values are appearing in the text file as the
text strings True/False, but I need them as the integers 1 and 0

Here are two suggestions.

You can use CInt() to convert the boolean to a number -- but it will use -1
and 0 for True and False. You can make this into 1 and 0 by using the Abs()
function:

MsgBox(Math.Abs(CInt(yourbool))

Alternatively you could use IIf to do anything you want:

MsgBox(CStr(IIf(yourbool, "1", "0")))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top