Hey, I was wondering if you are able to add numbers in seperate text fields and then be displayed in another text field?
Sort of like a table set up? And how would I go about doing this?
Thanks
Adding numbers in text fields
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Adding numbers in text fields
This is pretty easy.
Given you have 3 fields named: numberOne, numberTwo and theResult and maybe a button to calculate the result (you could also use field messages. The button is just for the example)
In the button:
It is a bit more wordy then necessary. I just wrote "the text of" to show you what actually happens. If you want it automagically when the user changes the data, look at the keyDown message and the closeField and exitField messages in the dictionary, or ask for more examples please.
All the best,
Malte
Given you have 3 fields named: numberOne, numberTwo and theResult and maybe a button to calculate the result (you could also use field messages. The button is just for the example)
In the button:
Code: Select all
on mouseUp
if the text of fld "numberOne" is a number and the text of fld "numberTwo" is a number then
put fld "numberOne" + fld "numberTwo" into fld "theResult"
else
put "Incorrect data into fld "theResult"
end if
end mouseUp
All the best,
Malte
Re: Adding numbers in text fields
Thanks that helps heaps, but what if i wanted to continue to add to the total number,
say using 8 text fields to create the total?
say using 8 text fields to create the total?
Re: Adding numbers in text fields
In that case find clever names for your fields e.g.
field1
field2
...
field8
and repeat is your friend (no error checking here, you need to add it)
snippet:
Cheers,
Malte
field1
field2
...
field8
and repeat is your friend (no error checking here, you need to add it)
snippet:
Code: Select all
local theResult
repeat with i=1 to 8
add field ("field"&i) to theResult
end repeat
answer theResult
Malte