The answer is to use INT()  (Peter Horsbøll Møller, Spencer Simpson, Lars Nielsen thank you).

 

It is strange because the user’s guide specifies that the argument should be a numeric _expression_ and that threw me off because if one multiplies two logical variables it fails, requiring numeric values (but these can be contained in variables). Nice to get the explanation that logical variables are treated as “special” numeric ones (a one byte numeric with values 0 or 1). That applies to some contexts, for ex. in functions like Maximum(), Cos(), Log() but it fails in “arithmetic” operations (I guess because the variable types are checked before the operation is carried out and that nobody allowed for the logical type to be treated numerically)

 

It is one more example of the “niceties” MapBasic contains that can documented only by experience.

 

Jacques Paris

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jacques Paris
Sent: 1 mai 2006
15:04
To: MapInfo-L@lists.directionsmag.com
Subject: [MI-L] logical to numeric

 

I have not seen much written on the subject but I was faced with it: how to use logical variables in operations without using if statements.

 

I was not able to pinpoint such a function and may be I am on an entirely wrong track but to solve my “problem” I have devised a possible conversion and I would like to know if it is acceptable or how could it be improved. Here it is, with its justification

 

num_logic = ASC(STR$(logic))\73    

STR$() will return F or T, their ascii codes (ASC) are 70 and 84. The integer division by any value from 71 to 83 will return 0 or 1.

 

This conversion to numeric finds its place in conditional operations (ex. inclusion in a summation when a condition must be respected sum(numeric(i)*num_logic(i)) ) or condition summaries (ex1: how many true conditions apply to the case sum(num_logic(i)) – ex2. if one condition is false all is false num_logic(1)*num_logic(2)*…

 

I would appreciate any comment on that issue and proposed solution. TIA

 

Jacques Paris

_______________________________________________
MapInfo-L mailing list
MapInfo-L@lists.directionsmag.com
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to