If nRet = TRUE doesn't work in nRet is bigger then 1?

forum.gupta.bugreport (2005-2010)
luca.pivato
United States of America
Posts: 611
Joined: 10 May 2017, 23:43
Location: USA

If nRet = TRUE doesn't work in nRet is bigger then 1?

Post by luca.pivato » 21 Apr 2005, 17:17

 Posted by:  Gianluca Pivato 

Apparently numbers are automatically casted to a boolean if they are part of
a logical expression, unless they are compared to a boolean, in which case
the boolean is converted to a number. Is this a bug?

Set nRet = 8

If nRet
.... <--- this is executed

If nRet And TRUE
.... <--- this is executed

If nRet = TRUE
.... <--- this is NOT executed

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2385
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: If nRet = TRUE doesn't work in nRet is bigger then 1?

Post by Jeff Luther » 21 Apr 2005, 17:29

 Posted by:  Jeff Luther 

IMHO it is not a bug. 'TRUE' is a constant = 1 in TD (as FALSE = 0), so
if nRet = 1
will not evaluate 'true' (ie, positively), since nRet = 8 in your example.

If nRet >= TRUE
presumably would evaluate 'true.'

IMHO #2: if nRet is a 'number'--as inferred by the 'n' in your var.
name--then it seems a bit loose of the TD compiler to even allow an
expression like If nRet = TRUE. (The secret as to why it does allow this
is that all booleans and handles are also numbers 'under the covers' in TD).
Thus, it's at least misleading to code "If nRet = TRUE".

Best Regards,
Jeff Luther/PC Design
www.pulpcards.com/gupta/

luca.pivato
United States of America
Posts: 611
Joined: 10 May 2017, 23:43
Location: USA

Re: If nRet = TRUE doesn't work in nRet is bigger then 1?

Post by luca.pivato » 21 Apr 2005, 20:35

 Posted by:  Gianluca Pivato 

I know the reason why it doesn't work. But in SAL all basic types are
automatically casted to bool:

If sString
If nNumber
If dtDate

Are all automatically casted to bool by the interpreter. However in this
case: If nRet = TRUE is the boolean TRUE that is casted to a number (1)
instead of nRet casted to a boolean (as it would happen in If nRet And
TRUE). That's why I think that it migh be a bug or maybe an unpredicted
feature.

/Gianluca

Jarmo Muukka

Re: If nRet = TRUE doesn't work in nRet is bigger then 1?

Post by Jarmo Muukka » 22 Apr 2005, 13:18

 Posted by:  Jarmo Muukka 

To me SQLWindows has never had a real Boolean datatype. It allows you to set
bSuccess = anyNumber. If you compare boolean to TRUE or FALSE, it just
compares number to 1 or to 0.

Set bSuccess = 2
If bSuccess = TRUE
! never executed, because 2 != 1

If Boolean would be true Boolean, then boolean variable would be TRUE when
non-zero number is assigned to it. But it's not. ;-(

To me numbers are not casted to boolean. Boolean is just a another word for
Number. Nothing else. If numbers are used in logical expressions like in
your examples, they are just checked are they non-zero.

Set nRet = 8
If nRet ! succeeds because 8 is non-zero
If nRet And TRUE ! succeeds because 8 and 1 are both non-zero
If nRet = TRUE ! does not succeed because 8 is not 1

Which one of these is a bug? In SQLWindows: none, unfortunately.

If this would be C# code then all three would cause compilation error.

JMu

Return to “gupta.bugreport”

Who is online

Users browsing this forum: [Ccbot] and 0 guests