Skip to first unread message

Aliaa Fakhri

unread,
Jun 20, 2019, 10:15:44 PM6/20/19
to MIT App Inventor Forum

button.PNG

Dear all, I am currently doing a small project for counter counting.
I got confuse with my logic error.

The situation are  (for Increment part )
1. when we click the colorful button, the value of the button will increment
2. in the same time, the value for Output box will also increment and appear in the textbox.

For the undo button,
how can I undo the value of the selected button and in the same time the output box will also decrease its value?

Thank you, please help me :)

Chris Ward

unread,
Jun 20, 2019, 10:45:57 PM6/20/19
to MIT App Inventor Forum
Hello Aliaa

To enable undo, you need to record all the associated actions - you can add them to a List.

For example - User Clicks a Red Button. The Red Button value is incremented and the Output Box is Incremented:

Record:
Red_ButtonID, increment

User then Clicks a Blue Button:

Record:
Red_ButtonID, increment
Blue_ButtonID, increment

User then Clicks a Green Button:

Record:
Red_ButtonID, increment
Blue_ButtonID, increment
Green_ButtonID, increment


When the User clicks Undo:
Green Button Value and Output Value are reduced by the amount recorded. Record is removed.

When the User clicks Undo again:
Blue Button Value and Output Value are reduced by the amount recorded. Record is removed.

When the User clicks Undo again:
Red Button Value and Output Value are reduced by the amount recorded. Record is removed

When the User clicks Undo again:
Nothing happens because the Undo Record is empty.






ABG

unread,
Jun 21, 2019, 11:25:16 AM6/21/19
to MIT App Inventor Forum
Your button .Text values look to have 2 or 3 parts.
Do you only want to increment the last part?
Abg

Aliaa Fakhri

unread,
Jun 24, 2019, 1:54:17 AM6/24/19
to MIT App Inventor Forum
okey, I understand but still figuring it out. thanks!

Aliaa Fakhri

unread,
Jun 24, 2019, 1:59:02 AM6/24/19
to MIT App Inventor Forum

Capture.PNG


to simplify about the counter, here the example.
I need to count the quantity of the size and display the output in the text box, but I still got stuck with the logic.
let's say we have a bundle of shirts, so we want to track the quantity of each size S, M,L and XL.
so, I need to click one by one the size to calculate the output. 

ABG

unread,
Jun 24, 2019, 9:23:15 AM6/24/19
to MIT App Inventor Forum
The logic to this is similar to that of the Fruit Stand sample at
ABG

Ghica

unread,
Jun 24, 2019, 3:24:57 PM6/24/19
to MIT App Inventor Forum
This would be a nice example for using the when... any blocks. Therefore here an example:

blocks (23).png


There are several lists to handle:

  • a list with thetext on the buttons (the sizes: S,M,L,XL)
  • totals for each of these sizes. For example, M has index 2 in the sizes list, therefore its total will be found at index 2 in the totals list.
  • An undo list. This just records the clicks you make on the buttons, in reverse order. If you click S,S,M,XL then the list will look XL,M,S,S. This makes the list easier to handle: you always insert or remove the first element.

The when any button clicked event is called when you click any button. There are specific events for Undo and Reset, so they have their own event logic,

The setTotals procedure gets as parameter the text on the button or the character in the undo list. And an indication whether the total should be increased (if the S,M,L or XL button was pressed) or decreased (if Undo was pressed).
The show procedure is a bit primitive, it is just to show that it works.
The ListView is there to show the undo list, handy for debugging. Make it invisible or remove it when finished debugging.

For your convenience I also attached the .aia

Cheers, Ghica
addSMLXL.aia

TimAI2

unread,
Jun 24, 2019, 4:41:05 PM6/24/19
to MIT App Inventor Forum

icon_thumbs.gif @ Ghica


Aliaa Fakhri

unread,
Jun 26, 2019, 8:54:16 PM6/26/19
to MIT App Inventor Forum
Thanks Ghica, you're the best!
Reply all
Reply to author
Forward
0 new messages