cherokee
23rd May 2008, 16:22
Hello everyone,

Is there any behavior difference on these two statements?

Function abc()
{

long count
….
if count > 0 then
or
if count then

}

I believe that a long if it is greater than 0 will consider as true for a boolean comparison, isn't it?

Thanks in advance,

mark_h
23rd May 2008, 16:42
Yes - I believe that is what the support center told me. In baan it must be 0 to be false and anything else is true. I am not 100% sure of that, but I think they told me that back 3 to 4 years ago.

cherokee
23rd May 2008, 16:50
I have used it that way always... but I got a complain from a user on a customized session and by checking the script, it is the only thing that I could think of that could make it fail.

I'll stick to the believe of 0 false, greater than 0 true.

Thanks again.

mark_h
23rd May 2008, 17:33
This might not be related, but with doubles I had that if statement work in test, but not in production. Actually I was debugging someone elses program. We have seen this several times with various little things - nothing serious, but just enough to make us wonder about backend issues. Those type things us developers do not really see.

NPRao
23rd May 2008, 20:13
I believe that a long if it is greater than 0 will consider as true for a boolean comparison, isn't it?
No. The boolean comparison considers if its 0 or not.
Here is a sample code:

long count

count = 1
if count then
message("True")
else
message("False")
endif
count = 0
if count then
message("True")
else
message("False")
endif
count = -1
if count then
message("True")
else
message("False")
endif

In LN there is a new datatype for boolean. The online help on the forum does not have the boolean listed.

Data types
There are six types of variables: long, double, boolean, string, table, and domain variables.

Long variables can contain any whole number from -2147483648 to 2147483647. For numbers beyond this range, use double variables instead. Physically, four bytes are reserved for each long variable.
Double variables are used for any number containing a decimal point, with a maximum of 15 significant digits (8 bytes).
Boolean variables can have two values: true or false.
A string variable contains a string constant. The maximum length of a string is 1024 characters.
A table variable is used for database tables in your program. The table must be defined in the data dictionary.
A domain variable is a variable of a certain type that is defined in the data dictionary. Each of the following types are possible: long, byte, integer, date, enumerate, set, float, double, string, text. Each domain defined in the data dictionary can be used in a declaration of your program. See also Domains.

To avoid potential issues it is always good to be explicit, when you are using a long variable for boolean behavior and avoid "if count then" statements.

mark_h
26th May 2008, 02:03
NPR - is that a feature of LN? A couple of service packs back, the support center told me (and I think this is what they said) in baan 4 a boolean is false it will always be 0. Then everything else is true.

I agree with your last statement to clear confusion.