Functions ARGH! Help with this simple SUM script pls?
Posted: Sun Jul 27, 2008 4:36 pm
I am attempting a simple personal budget app that allows me to enter income in one list, and expenses in another. I want the totals to auto update as the fields are edited (ie no buttons required if possible).
I have put all the income amount fields into one group. I've done the same with all the expenses amount fields. I assumed this would make it easier to refer to in script?! Or is there an easier way to refer to a zillion fields at once to get their sum?!
I know I could just go and add up each field in one big long expression and get a result, but I'm on about day 4 of trying to wrap my brain around functions, and this project is supposed to be helping me learn. HA!
The income group is called "iList". Trying to display the total in field "iTotal" (will do the Expenses when got it working). I know the keyDown is probably NOT the correct message to use, and if not, what? Are there any field specific "field edit or change" messages available instead?
Anyway, no doubt I'm WAY off, but here goes (getting error of course):
By the way, this code is in the stack script because I wasn't sure about the best place yet? Is it okay in here? Sorry, still so much to learn... but really am enjoying the process!
Any help appreciated as usual.
I'm hoping I'm not TOO far off?
Gulp...
I have put all the income amount fields into one group. I've done the same with all the expenses amount fields. I assumed this would make it easier to refer to in script?! Or is there an easier way to refer to a zillion fields at once to get their sum?!
I know I could just go and add up each field in one big long expression and get a result, but I'm on about day 4 of trying to wrap my brain around functions, and this project is supposed to be helping me learn. HA!
The income group is called "iList". Trying to display the total in field "iTotal" (will do the Expenses when got it working). I know the keyDown is probably NOT the correct message to use, and if not, what? Are there any field specific "field edit or change" messages available instead?
Anyway, no doubt I'm WAY off, but here goes (getting error of course):
By the way, this code is in the stack script because I wasn't sure about the best place yet? Is it okay in here? Sorry, still so much to learn... but really am enjoying the process!
Code: Select all
function addList groupName
repeat with x = 1 to the number of items in groupList
add item x of groupList to sumValue
end repeat
return sumValue
end addList
on keyDown theKey
if theKey is a number then
put addList(iList) into field "iTotal"
end if
end keyDown

