Add. & Sub. Error - Operators -: error in left operand
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Add. & Sub. Error - Operators -: error in left operand
Hi, All
I am having some difficulty getting a button to work that adds the result of two text entry field sections, and then subtracts the addition of the two sections from an original text entry field. I am including the code below and explain the throughout process along the way. Still new at this so forgive me if the answer is straight forward.
on mouseUp
local A1, A2
put the text of field "IncomeEntryField" into A1 -- this is the text entry field where an amount is entered
put field "LongTerm1Amt" + field "LongTerm2Amt" into field "LongSubTotal" -- This adds two text entry fields into a label
put field "ShortTerm1Amt" + field "ShortTerm2Amt" into field "ShortSubTotal" -- This adds two text entry fields into a label
put the text of field "LongSubTotal" + the text of field "ShortSubTotal" into field "StageField" -- This adds the label values together
put the text of field "StageField" into A2
put A1 - A2 into field "IncomeAfterDebtLabel"
end mouseup
It applies correctly however when I run the application I get the error:
Button "LongShortCalculate" error Operators -: error in left operand
It is rather strange if I substitute "IncomeEntryField" with "LongSubTotal" for example it works, but the moment I use the other field it fails.
Hope you can help, appreciate the assistance.
I am having some difficulty getting a button to work that adds the result of two text entry field sections, and then subtracts the addition of the two sections from an original text entry field. I am including the code below and explain the throughout process along the way. Still new at this so forgive me if the answer is straight forward.
on mouseUp
local A1, A2
put the text of field "IncomeEntryField" into A1 -- this is the text entry field where an amount is entered
put field "LongTerm1Amt" + field "LongTerm2Amt" into field "LongSubTotal" -- This adds two text entry fields into a label
put field "ShortTerm1Amt" + field "ShortTerm2Amt" into field "ShortSubTotal" -- This adds two text entry fields into a label
put the text of field "LongSubTotal" + the text of field "ShortSubTotal" into field "StageField" -- This adds the label values together
put the text of field "StageField" into A2
put A1 - A2 into field "IncomeAfterDebtLabel"
end mouseup
It applies correctly however when I run the application I get the error:
Button "LongShortCalculate" error Operators -: error in left operand
It is rather strange if I substitute "IncomeEntryField" with "LongSubTotal" for example it works, but the moment I use the other field it fails.
Hope you can help, appreciate the assistance.
Re: Add. & Sub. Error - Operators -: error in left operand
Hi.
It "applies" (compiles) correctly because the code looks good to the parser.
But you are getting a runtime error, because something in your data is not a number. LC will not know what to do with:
So try this. Put the following handler in the card script:
Now run your stuff, but apply as follows:
This will validate user input, in case they add something untoward, including invisible characters that you may not find by inspection.
Craig Newman
It "applies" (compiles) correctly because the code looks good to the parser.
But you are getting a runtime error, because something in your data is not a number. LC will not know what to do with:
Code: Select all
add 25 to 50Q
Code: Select all
function goodNumber tText
repeat for each char theChar in tText
if theChar is in ".0123456789" then put theChar after temp
end repeat
return temp
end goodNumber
Code: Select all
put goodNumber(field "LongTerm1Amt") + goodNumber(field "LongTerm2Amt") ...
Craig Newman
Re: Add. & Sub. Error - Operators -: error in left operand
Craig, I take my hat off to you. This worked perfectly! Plus more importantly very important lesson learned. Thank you!




Re: Add. & Sub. Error - Operators -: error in left operand
How does one ensure only numeric input when user enters data into a field?
Re: Add. & Sub. Error - Operators -: error in left operand
errr... what Craig posted?
Or are you after at time of input?
Simon
Or are you after at time of input?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Add. & Sub. Error - Operators -: error in left operand
Oh ho, you want to validate at the front, not at the rear. Actually better.
Your field script ought to check what the user is typing, eh? And only pass characters that you intend, eh?
There is a message, "keyDown", and control structures "if" and "pass". Can you write a one-line handler that will allow only numeric input into a field?
One line, I said. Get going...
Craig
EDIT: There is one tiny issue with that one liner. Resolving that issue in that same line is possible, but woud be excessive. Anyway, write back when you find it.
Your field script ought to check what the user is typing, eh? And only pass characters that you intend, eh?
There is a message, "keyDown", and control structures "if" and "pass". Can you write a one-line handler that will allow only numeric input into a field?
One line, I said. Get going...
Craig
EDIT: There is one tiny issue with that one liner. Resolving that issue in that same line is possible, but woud be excessive. Anyway, write back when you find it.
Re: Add. & Sub. Error - Operators -: error in left operand
Thanks for the keyDown and pass suggestion.dunbarx wrote:Oh ho, you want to validate at the front, not at the rear. Actually better.
Your field script ought to check what the user is typing, eh? And only pass characters that you intend, eh?
There is a message, "keyDown", and control structures "if" and "pass". Can you write a one-line handler that will allow only numeric input into a field?
One line, I said. Get going...
Craig
EDIT: There is one tiny issue with that one liner. Resolving that issue in that same line is possible, but woud be excessive. Anyway, write back when you find it.
Code: Select all
on keyDown tCharacter
if tCharacter is in "0123456789."then pass keyDown
end keyDown

Re: Add. & Sub. Error - Operators -: error in left operand
Right on.
But what about that little issue I mentioned? Do you know what it is? Do you know how to, er, handle it?
Hint: You can certainly have several "5's" in your data, but can you have several....
Craig
But what about that little issue I mentioned? Do you know what it is? Do you know how to, er, handle it?
Hint: You can certainly have several "5's" in your data, but can you have several....
Craig
Re: Add. & Sub. Error - Operators -: error in left operand
OIC, more than one dotdunbarx wrote:Right on.
But what about that little issue I mentioned? Do you know what it is? Do you know how to, er, handle it?
Hint: You can certainly have several "5's" in your data, but can you have several....
Craig

This works:
Code: Select all
on keyDown tCharacter
switch
case "." is in tCharacter and "." is in fld "fldNumberOnly"
break
case tCharacter is in "0123456789."
pass keyDown
break
end switch
end keyDown