Auto Calculate Text Fields?

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
cmhjon
Posts: 175
Joined: Tue Aug 04, 2015 11:55 am

Auto Calculate Text Fields?

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
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Auto Calculate Text Fields?

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
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Auto Calculate Text Fields?

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: 175
Joined: Tue Aug 04, 2015 11:55 am

Re: Auto Calculate Text Fields?

Post by cmhjon » Thu Sep 06, 2018 2:41 pm

Hi Craig,

Nice! And super easy!

Thank you so much,
Jon :)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Auto Calculate Text Fields?

Post by bogs » Thu Sep 06, 2018 3:02 pm

I really like that second one Craig :D

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.
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Auto Calculate Text Fields?

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! :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Auto Calculate Text Fields?

Post by dunbarx » Thu Sep 06, 2018 6:58 pm

Monsieur Klaus

Pourquoi, mon petite chouchou?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Auto Calculate Text Fields?

Post by dunbarx » Thu Sep 06, 2018 7:03 pm

Bogs wrote:

Code: Select all

 a number or if it was empty t
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: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Auto Calculate Text Fields?

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é! :oops:

I was not aware of the fine difference between "the target" and "target"!
Merci, mon chèr, I learned something new today! :D


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Auto Calculate Text Fields?

Post by dunbarx » Fri Sep 07, 2018 3:56 pm

Klaus.

You, know, I thought that was it. 8)

After all these years, you did not know about "target"? It goes back to HC v.1. :shock:

It really is a useful gadget. How did you live without it? :wink:

Craig :D

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Auto Calculate Text Fields?

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. :shock:
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? :wink:
Very fine, to be honest! :-D


Best

Klaus

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Auto Calculate Text Fields?

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”