Page 1 of 1
Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 2:15 pm
by cmhjon
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

Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 2:22 pm
by dunbarx
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
Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 2:31 pm
by dunbarx
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
Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 2:41 pm
by cmhjon
Hi Craig,
Nice! And super easy!
Thank you so much,
Jon

Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 3:02 pm
by bogs
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.
Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 3:23 pm
by Klaus
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!

Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 6:58 pm
by dunbarx
Monsieur Klaus
Pourquoi, mon petite chouchou?
Craig
Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 7:03 pm
by dunbarx
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
Re: Auto Calculate Text Fields?
Posted: Thu Sep 06, 2018 11:20 pm
by Klaus
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
Re: Auto Calculate Text Fields?
Posted: Fri Sep 07, 2018 3:56 pm
by dunbarx
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

Re: Auto Calculate Text Fields?
Posted: Fri Sep 07, 2018 4:04 pm
by Klaus
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
Re: Auto Calculate Text Fields?
Posted: Sat Sep 08, 2018 6:21 pm
by jacque
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.