Page 1 of 1

subtract function

Posted: Tue Mar 10, 2015 12:14 pm
by gepponline
Hi!
I'm trying to make a simple subtract operation on a text field but i get an "cant' find object" error and i can't understand why...

Here is my code:

Code: Select all

on mouseUp
   put the text of field "numero" into tNumero
   if tNumero > 0 then
    subtract 1 to tNumero
   else
      put 0 into tNumero    
   end if
put tNumero into field "numero"
end mouseUp
No problem if the number is less or equal to 0. Instead if the number is positive i get the error. What's wrong with my code?
If i use thee same code but with the ADD function instead of subtract, all work good.
:roll:

Re: subtract function

Posted: Tue Mar 10, 2015 12:46 pm
by Dixie
Hi...

You have

Code: Select all

subtract 1 to tNumero
use

Code: Select all

subtract 1 from tNumero
I just tested using this..

Code: Select all

on mouseUp
   put fld 1 into temp
   subtract 1 from temp
   put temp into fld 1
end mouseUp
Works...:-)

Re: subtract function

Posted: Tue Mar 10, 2015 12:48 pm
by gepponline
D'oh.... I've copied and pasted from add function and I did not care about syntax... :cry:
Thank you!

Re: subtract function

Posted: Tue Mar 10, 2015 12:59 pm
by Klaus
Hi Geppo,
gepponline wrote:D'oh.... I've copied and pasted from add function and I did not care about syntax...
but you should! :D

If in doubt, always consult the dictionary first!


Best

Klaus