> try using: the value of field
> 
> instead of: the text of field
> 
> reason:
> the text of field is a string
> the value of field is the number
> 
> you want to add, so you need numbers

Close. I just got the scoop from Nuuj:

Lingo looks at the line of code, sees that it's a math operation and then decides what 
the resulting data type will be. If all arguments are integers then the result will be 
an integer, if not then the result will be a float. In the case cited, neither 
argument is an integer (they're both strings) and therefore the resulting data type is 
a float and so Director then tries to convert the type of each argument to a float 
(please see my PS about converting strings to floats), in doing so "27935" becomes 
27935.0 and "5500" becomes 5500.0, then the addition is performed add should return 
the correct result.

The above is true no matter what data type you pass into the equation:

x = FALSE + 1
-- first FALSE is converted to an integer
x = 0 + 1
-- both args are ints, no conversion needed so
put x
-- x = 2

y = TRUE + 5.0
-- first TRUE is converted to an integer
y = 1 + 5.0
-- both args are not integers, convert each to a float
y = 1.0 + 5.0
-- do the math now...
put y
-- 6.0000

z = "3" + "5"
-- neither are integers, convert them to floats
z = 3.0 + 5.0
-- do the math
put z
-- 8.0000

w = "3.0" * 14
-- both args are not integers, convert each to a float
w = 3.0 * 14.0
-- do the math
put w
-- 42.000

I figure that's enough to get the point across, if not then give a holler.

Cheers,
Tom

P.S. When type converting strings in this fashion be careful of things like this:

test = "1 + 4" * 3

This will *not* work as the string is parsed to see if it's a number, as soon as the 
space is found that fails. It would be more optimal to have Lingo _value_ the string 
found instead of parse it, but it doesn't, sorry.
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to