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
-
cmhjon
- Posts: 191
- Joined: Tue Aug 04, 2015 11:55 am
Post
by cmhjon » Thu Sep 06, 2018 2:15 pm
Hi all,
Suppose I have 3 text fields. I put a number into fields 1 and 2. Without clicking anything, the sum of fields 1 and 2 automatically appear in field 3.
How does one achieve this?
Thanks,
Jon

-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10323
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Sep 06, 2018 2:22 pm
Such a fun thing.
In the card script:
Code: Select all
on textChanged
put fld 1 + fld 2 into fld 3
end textChanged
Craig newman
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10323
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Sep 06, 2018 2:31 pm
Hi again.
Know that you can insert stuff like:
Code: Select all
if the short name of the target is in variableContainingTheCorrectFieldNames and\
target is a number then...
So that only the two fields of interest with valid text place their sums into that third field. That sort of thing, so that it actually works.
Craig
-
cmhjon
- Posts: 191
- Joined: Tue Aug 04, 2015 11:55 am
Post
by cmhjon » Thu Sep 06, 2018 2:41 pm
Hi Craig,
Nice! And super easy!
Thank you so much,
Jon

-
bogs
- Posts: 5480
- Joined: Sat Feb 25, 2017 10:45 pm
Post
by bogs » Thu Sep 06, 2018 3:02 pm
I really like that second one Craig
I didn't see anyone checking if the field had a number or if it was empty though, and although you can add, subtract, and multiply with it, you really shouldn't ever divide by 0 if you can avoid it.
-
Klaus
- Posts: 14198
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Sep 06, 2018 3:23 pm
if the short name of the target is in variableContainingTheCorrectFieldNames and target is a number then...
...and target is a number...?
Jamais, mes amis, jamais!

-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10323
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Sep 06, 2018 6:58 pm
Monsieur Klaus
Pourquoi, mon petite chouchou?
Craig
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10323
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Sep 06, 2018 7:03 pm
Bogs wrote:
Good point. Shows how important testing is. (Pseudo)
Code: Select all
if the short name of the target is in varEtc... and\
(target is a number or target = "") then
Craig
-
Klaus
- Posts: 14198
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Sep 06, 2018 11:20 pm
dunbarx wrote: ↑Thu Sep 06, 2018 6:58 pm
Monsieur Klaus
Pourquoi, mon petite chouchou?
Craig
Oh, mon dieux, c'est ma faute, très désolé!
I was not aware of the fine difference between "the target" and "target"!
Merci, mon chèr, I learned something new today!
Best
Klaus
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10323
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri Sep 07, 2018 3:56 pm
Klaus.
You, know, I thought that was it.
After all these years, you did not know about "target"? It goes back to HC v.1.
It really is a useful gadget. How did you live without it?
Craig

-
Klaus
- Posts: 14198
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Sep 07, 2018 4:04 pm
Hi Craig,
dunbarx wrote: ↑Fri Sep 07, 2018 3:56 pm
After all these years, you did not know about "target"? It goes back to HC v.1.
I was not "X-Talk ready" when I received my first Mac LC with HC pre-installed in 1993, so I did not really understand HC or dived deeper into it.
dunbarx wrote: ↑Fri Sep 07, 2018 3:56 pm
It really is a useful gadget. How did you live without it?
Very fine, to be honest!
Best
Klaus
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sat Sep 08, 2018 6:21 pm
This brings up my pet peeve about the omission of "the" before property names. It can bite you if you aren't familiar with the entire dictionary.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com