+ Reply to Thread
Results 1 to 5 of 5

When does TRUE evaluate to minus 1?

  1. #1
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315

    When does TRUE evaluate to minus 1?

    I want to exploit the fact TRUE equtes to -1 but cannot get my head around the conditions surrounding this. I have experimented in code with MsgBox (5=(50/10)) , or some such direct equality , but each time simply get the result TRUE.

    How can I wrest minus 1 from a TRUE boolean relationship?

  2. #2
    Registered User
    Join Date
    07-25-2005
    Posts
    62
    Convert the bool to and integer

    CInt(True) = -1

    CInt(5=5) = -1

    CInt(5=4) = 0

  3. #3
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Thanks Tommy. Exactly what I am lookoing for.

  4. #4
    Tom Ogilvy
    Guest

    Re: When does TRUE evaluate to minus 1?

    msgbox "the column is " & _
    Left(ActiveCell.Address(0,0), 2 + (ActiveCell.column < 27))

    would be an example of exploiting True is equivalent to -1

    --
    Regards,
    Tom Ogilvy

    "davidm" <[email protected]> wrote in
    message news:[email protected]...
    >
    > I want to exploit the fact TRUE equtes to -1 but cannot get my head
    > around the conditions surrounding this. I have experimented in code
    > with MsgBox (5=(50/10)) , or some such direct equality , but each time
    > simply get the result TRUE.
    >
    > How can I wrest *minus 1* from a TRUE boolean relationship?
    >
    >
    > --
    > davidm
    > ------------------------------------------------------------------------
    > davidm's Profile:

    http://www.excelforum.com/member.php...o&userid=20645
    > View this thread: http://www.excelforum.com/showthread...hreadid=390606
    >




  5. #5
    Chip Pearson
    Guest

    Re: When does TRUE evaluate to minus 1?

    You can either use CInt to convert it to an integer, or do some
    arithmetic with it. E.g.

    Dim Res As Integer
    Res = CInt(5 = (50 / 10))
    Debug.Print Res
    ' or
    Res = (5 = (50 / 10)) + 0
    Debug.Print Res


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com




    "davidm" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > I want to exploit the fact TRUE equtes to -1 but cannot get my
    > head
    > around the conditions surrounding this. I have experimented in
    > code
    > with MsgBox (5=(50/10)) , or some such direct equality , but
    > each time
    > simply get the result TRUE.
    >
    > How can I wrest *minus 1* from a TRUE boolean relationship?
    >
    >
    > --
    > davidm
    > ------------------------------------------------------------------------
    > davidm's Profile:
    > http://www.excelforum.com/member.php...o&userid=20645
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=390606
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1