none
converting to integers RRS feed

  • Question

  • I have the following expression:

    b(1717) = CInt(haveRecorder.Checked)

    where: b is a byte array, haveRecorder is a checkbox

    I thought it would take the booloean value of haveRecorder.Checked and convert it to an integer which can be stored in b(1717). If it wasn't checked then it would convert false to a 0 or if it was checked it would convert true to a 1.

    Instead it gives me an error about overflow. It says the number is either too large or too small for an integer. The value (I thought) could only be 0 (not checked) or 1 (checked).

    I have no idea what is wrong (other than the overflow). Enjoy!

    Friday, March 17, 2006 11:09 PM

Answers

  • CInt(true) = -1

    I would recommend using strict type checking (Option Strict On), which would have allowed the VB compiler to catch this error.

    For you case, consider using

        iif(haveRecorder.Checked, 1, 0)

    or (maybe even better) have an array of booleans instead of bytes...

    Best regards,
    Johan Stenberg

    Friday, March 17, 2006 11:43 PM
    Moderator