subtract function

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

subtract function

Post by gepponline » Tue Mar 10, 2015 12:14 pm

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:

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: subtract function

Post by Dixie » Tue Mar 10, 2015 12:46 pm

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...:-)

gepponline
Posts: 91
Joined: Tue Sep 03, 2013 1:53 pm

Re: subtract function

Post by gepponline » Tue Mar 10, 2015 12:48 pm

D'oh.... I've copied and pasted from add function and I did not care about syntax... :cry:
Thank you!

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: subtract function

Post by Klaus » Tue Mar 10, 2015 12:59 pm

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

Post Reply