I started playing with a test stack, and in the meantime you have already got some answers, but I typed a reply anyway, so I'll paste it below, as there may be some other areas you want to examine (eg closeField)
Hi heatherbee
(so far as I know) keyDown or rawKeydown may or may not be the appropriate messages to check in your situation. The field change message that is sent when a user exits focus on a field is "exitField" if the contents have not been changed, or "closeField" if the contents have been edited or updated. It seems that you probably want the updating of the field to trigger the totalling, so I'd imagine that to be more appropriate to handling the "closeField" message on each field in the group, but keyDown may work in your situation. You will likely need to pass the keyDown message in your handler if you find that it's right for you.
To catch the message on the card, putting the handler in the stack or card script is fine. Perhaps it would be more specific (ie efficient - or handled earlier in the message path anyway) to have it in the card script, if there is no reason to have the same handler applied on a different card.
As to the totalling function, it seems like you have the right idea but need to check the syntax.
Code: Select all
function addList groupName
--firstly the groupName parameter is not referenced in this function
repeat with x = 1 to the number of items in groupList
--you need to reference the groupName parameter passed to the function
--which holds the name of the group to total
--also, "items" are chunks of data in an expression
--you need to reference the controls you are looking to total
--ie fields, and identify them to the script
add item x of groupList to sumValue
--item is a "chunk" (usually in a commas separated list) of data, not
--the value held in the field you are trying to reference
end repeat
return sumValue
end addList
If you try:
Code: Select all
function addList pGroupName
-- calling the parameter pGroupName is a convention I've adopted
-- whatever the name, it must be the parameter you reference in the function
local tLoop, tSumValue
-- purely subjective preference, I always declare variables explicitly
repeat with tLoop = 1 to the number of fields in group pGroupName
-- loop through the number of fields, and identify the target
-- it isn't enough to count the "number of fields in pGroupName" (to my knowledge)
-- you should identify that pGroupName is a "group" in the syntax
if the text of field tLoop of group pGroupName is a number then
-- rather than "item" you need to retrieve the value of the control you have as the target
-- ie the text of the field (numbered tLoop in the "group" pGroupName)
-- after checking that it's a number, you can add the text (ie the value of the field) to the total
add the text of field tLoop of group pGroupName to tSumValue
end if
end repeat
return tSumValue
end addList
you should get a better result.
Rather than handling a keyDown message, I put a closeField handler on each of the fields in the group which called the function.
Hope that helps