Well consider what we already know:
  • 0 is false
  • Non-zero is true
  • 0 = "0" so "0" should be false
  • 0 = "foo" so "foo" should be false

So, how come the $c and $f tests are true when $c="0" and $f="foo" if we are converting to boolean?

The answer is that we are not converting to boolean. We are checking the truth of the data, which is not necessarily the same thing as the truth of the boolean value of the data.

The most common time this catches people out is when checking boolean / numeric flags in INI files using ReadProfileString() or values in the registry using ReadValue(). Both these functions return STRING data regardless of how the value is encoded, so "0" and "1" are both true which is probably not what is expected.

This means that code like the following will not work as expected if the BootPending flag is 0:
 Code:
If ReadValue("HKLM\SomePath","BootPending")
   "Cannot install, there is a restart pending"+@CRLF
EndIf


Instead, you must cast the datum to a type that will work:
 Code:
If CInt(ReadValue("HKLM\SomePath","BootPending"))
   "Cannot install, there is a restart pending"+@CRLF
EndIf