Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: true & -1

  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question true & -1

    Code:
    WScript.Echo(true)        -> -1
    
                (false)       ->  0
    
                (true == -1)  ->  0
    
                (false == 0)  -> -1
    
                (true == 1)   -> -1
    Why does it not return [true] and [false]?

    Why does true become [-1]?

    Maybe I used to know, but can't remember...
    *this message will self destruct in n-seconds*

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And the answer is: just because...

    boolean [WMI]
    BOOL vs. VARIANT_BOOL vs. BOOLEAN vs. bool
    *this message will self destruct in n-seconds*

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, the reason is that you have two different systems: COM, and JScript. The argument you are sending to WScript.Echo is a JScript native, while the value echoed is COM native. The Windows Scripting Host provides the layer in between.

    Now, the true COM native is a VB boolean, which means it's actual value is -1. The JScript native is the true value of JScript Boolean type. Thus, the echoed value for a JScript boolean is converted to a COM boolean, with a value of either 0 for fale or -1 for true. Still, the argument sent is native to JScript, not COM. In JScript, a cast of the true boolean to a number gives a value of 1, not -1 as in VB. This is the reason why the three JScript comparisons give the COM echoes they do.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, this reminds me of a horror movie where somone gazes into a mirror and their reflection takes on a life of its own!
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

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