If it's working then it seems like you have got the right idea. You will, no doubt be issuing the command "TheCalc" from the button script or your menupick script.
A word of advice though, while you have done nothing wrong*, you should get into the habit of using field operations as little as possible. Get a value from a field into a variable and do any validation and processing with the variable, and then write back into a field with the results only once. Field operations are exponentially longer than operations on variables, as there are so many more overheads in validation, message generation, etc.
*except for the "or" instead of "and" in the test for number
I would change your script to
Code: Select all
Global roomsens
command TheCalc
put field "Length" into tLength
put field "Width" into tWidth
put field "Height" into tHeight
if tLength is a number and tWidth is a number and tHeight is a number then
put tLength * tWidth * tHeight * roomsens into field "Result"
end if
end TheCalc
It won't make a lot of difference here, but it can, and probably will bite you at some point when you have a big repeat loop that updates values.
I was also under the impression that you are doing something in particular with the menuPick handler beyond simply setting the label. If that is the whole handler, and every case puts 0.80 into roomsens then you needn't make a case statement for each one. Just have a case statement for "Other" and a default for the rest, if they are all the same. You can also put multiple case statements together and have the same action for any one of them in the manner:
Code: Select all
switch pItemName
case "Living Room"
case "Lounge"
case "Billiard Room"
case "Study"
put "Colonel Mustard" into theSuspect
break
case "Kitchen"
case "Conservatory"
put "Miss Scarlet" into theSuspect
break
default
put "Professor Plum" into theSuspect
end switch
When any of the cases "Living Room", "Lounge", "Billiard Room" or "Study" are matched, then the action to put Colonel Mustard into theSuspect will be taken, and so on.