Thanks:  0
Likes:  0
Dislikes:  0

# Thread: True / False as a number

1. ## True / False as a number

Pass is 0
Fail is a non zero number such as -13412

What are true and false equivalent to as numbers?

How can I prove this to myself?

Thanks,

Kevin

2. Play around with this Kevin:

If 1 Then
Print "True"
End If
If Not 0 Then
Print "False"
End If

Mark Smith.

3. If you really want some frustration, take a look at this:
Code:
```' Browser("Google").Page("Google").WebEdit("q") is the google home page search box... add it to your repository
msgbox "It exists"
Else
msgbox "It does not exist."
End If```
You might think the result would be "It exists" when you're on the google home page... but you'd be wrong. VBscript treats any number other than 0 as true in a boolean comparison. However, if you convert True to an integer, it's -1. The Exist function returns 1 if the object you're looking for actually exists. So if you do the comparison above, it'll always fail because the function returns 1 and vbscript converts the True to -1.
1 <> -1

4. Which is why you really shouldn't think of true/false as a number, but if anything a range of numbers.

5. Think of Pass/Fail as a process level item. Any process, like a .bat file or a .exe will return an error code when it exits to the system. In this case, Pass is 0, meaning error code 0, as no errors. Otherwise it's any number, meaning an error code was returned.

For true/false in programming, you're looking at bits. 0 in this case is False, meaning 0 bits are turned on. Other wise any number is true, meaning there is a True bit somewhere in the bit string. To conceptualize the one above in this model, think of pass being 0, as being a "False" for "Was there an error?"

6. Mark, Dennis, NoUse4aName,David,
Wow. Confusing!

7. 0 is false.
-1 or some other number (other than 0) is true.

May I understand it as this for QTP UFT VBscript?

8. Kevin,
A simple VBScript test to prove that 0 is equivalent to a False, and any other number is equivalent to True:

For i = -5 to 5 Step 1
msgbox i & " is " & cbool(i), vbOKOnly, "True/False Test"
Next

You don't need QTP or UFT to run this since it's just VBScript. You can use wscript or in windows to run it from a .vbs file.

9. Alex,
I tried the code and understand it.
I will think of it as 0 is there are no light bulbs turned on. Anyother number sets a switch to turn a bulb on someplace.
Also cbool is something I have not needed in the past.
I learned GW BASIC 30 years back. It still trips me up at times.
Thanks,
Kevin

#### 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 Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.