2014-08-01:
When a digit is entered after equals buton is pressed, the result is cleared before displaying the digit.
This fixes the bug where the digit was appended to the result.
2013-11-23:
Added C (clear) button explanation.
---
Now we can add a call to this reusable procedure in each of our digit button blocks.
Here is what the OneBTN.Click block looks like with a call to AddDigit. Do this for ZeroBTN.Click to NineBTN.Click as well.
At this point the user can type digits into the display.
We now need to be able to perform an arithmetic calculation based on two operands and an operator.
The user touches the digit buttons (ZeroBTN to NineBTN) for Operand1 first, then touches an Operator button(AddBTN,SubtractBTN,MulitplyBTN,DivideBTN), then digit buttons for Operand2, and finally the EqualsBTN.
Create three global variables:
Operand1, Operator, Operand2
Set their default values to Empty Text.
Suppose the user has typed in a number for Operand1, then touched an Operator button.
We need to save the typed number in DisplayLBL.Text in Operand1, clear the text in DisplayLBL.Text and remember what Operator was touched.
After the user has typed in Operand2 into DisplayLBL then pressed the EqualsBTN button we can determine what arithmetic operation to perform by looking at the saved Operator.
Create a procedure called SetOperator with an argument operator.
When this procedure is called from one of the four operator Click blocks (AddBTN.Click,SubtractBTN.Click,MultiplyBTN.Click,DivideBTN.Click):
Here is a call to SetOperator from the SubtractBTN.Click block. Repeat this for the AddBTN.Click, MultiplyBTN.Click and DivideBTN.Click blocks:
Finally, when the user touches the = symbol button, the EqualsBTN.Click block is triggered.
At this point we need to store the contents of DisplayLBL.Text in global Operand2.
Next we need to determine what operation to perform based on the symbol stored in global Operator.
This is accomplished with 'if then else blocks' that return the calculated value to DisplayLBL.Text
The blocks to do this are as follows:
The initial blocks in EqualsBTN.Click make sure that there are numbers in the operand and operator variables. This is one example of error handling.
Finally, the C (clear) button clears the display and resets the variables:
At this point you can test your project. If there are errors, compare it to the attached project.
---
END
<iframe width="560" height="315" src="https://www.youtube.com/embed/8OZQrm9kuAo" frameborder="0" allowfullscreen></iframe>
Watch itWatch my good vedios
Pls give your feed back through your LIKES. & COMMENTS
do SUBSCRIBE for more informative vedio
https://www.youtube.com/playlist?list=PLkx_Oenh09_5_7DJf9FJmRKsDUa5QV-fe
--
(you have received this message from the App Inventor Developers Library)
---
You received this message because you are subscribed to the Google Groups "App Inventor Developers Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-develope...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-developers-library+unsubscribe@googlegroups.com.
But not to sofisticated.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-develope...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
(you have received this message from the App Inventor Developers Library)
---
You received this message because you are subscribed to the Google Groups "App Inventor Developers Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-develope...@googlegroups.com.
But not to sofisticated.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-developers-library+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
(you have received this message from the App Inventor Developers Library)
---
You received this message because you are subscribed to the Google Groups "App Inventor Developers Library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to app-inventor-developers-library+unsubscribe@googlegroups.com.