Results 1 to 5 of 5

Thread: [RESOLVED] Return values from boolean

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Resolved [RESOLVED] Return values from boolean

    Hi,

    Is there any builtin function which will give value 1 for True and value 0 to false. I have following function:
    VB Code:
    1. Private Function BoolToVal(ByVal blnTemp As Boolean) As Integer
    2. 'This function will return 1 if the value is true else will return 0
    3.     If blnTemp = True Then
    4.         BoolToVal = 1
    5.     Else
    6.         BoolToVal = 0
    7.     End If
    8. End Function
    CS

  2. #2
    Addicted Member sigid's Avatar
    Join Date
    May 2006
    Location
    Massachusetts, USA
    Posts
    182

    Re: Return values from boolean

    ...how about "val = ABS(blnVal)"? Any TRUE boolean in VB is = -1, so just remove the sign...

  3. #3

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Return values from boolean

    Found a solution myself. Abs(Int(true)) will return 1 and Abs(Int(false)) will return 0

    Anyway,

    Thanks.
    CS

  4. #4

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Return values from boolean

    Quote Originally Posted by sigid
    ...how about "val = ABS(blnVal)"? Any TRUE boolean in VB is = -1, so just remove the sign...
    Thanks, I already found the solution.
    CS

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: [RESOLVED] Return values from boolean

    Cint(True) returns negative one cause all the bits are set to 1 including the highest bit (which determines +/-).

    So use...

    Debug.Print (CInt(yourbool) AND 1)

Posting Permissions

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



Click Here to Expand Forum to Full Width