No procedure possible when using "Any Button.Click"?

I created an app with many buttons. When I use the "Any Button.Click"-block I distinguish them with different background colours to give them various tasks. When a blue button is pressed, play a sound; when a red button is pressed, copy a word, and so on; whatever, just as an example.

Though the tasks are different, some of the code is repetitive after all. I realised I cannot just put that code into a procedure and call that procedure from within the Any Button. Click block. The components will become orphaned, and those error crosses appear on them.

Is there really no way to avoid repetitive coding within an Any Button. Click block ??

Show your relevant blocks.

There are various ways to distinguish buttons in an Any Button Click event:

  • Check if the component is in a predefined list of buttons with specific intent (keyboard, control, sound, etc.)
  • use the if NotAlreadyHandled test to avoid event overlap
  • Use the Any Button blocks to test button colors or text

Sample project:

Altogether I have got buttons with 8 different background colours. This Block is going to be very long ... and messy and cluttered ...

I see this text hardwired into your logic:
"the girl is tall"

You are missing some data structures behind the scenes to hold phrases like this so the words can be mapped onto buttons at run time.

Testing colors is also risky. I had one user who tried comparing two slightly different colors of green, meant to signify the same thing, but never getting a match.

Your Any Button Clicked event block is missing a test on notAlreadyHandled.
That is needed to allow extra button Click events for infrequent events not fitting the general mold.

Further speculation is useless without seeing specific intention for how the app would look and work.

Something similar happens to me.
I have several buttons that when I press, for example, Button 1 (white), it changes to blue without affecting the others and if I press the same Button 1 again (now blue) I need it to turn white.

1 Like

This should work for you:



Thank you very much brother.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.