How to link created buttons to individual functions?

We are working on a project that contains two buttons. When the user clicked the yes button, we would create a label said "You clicked yes” and when the user clicked the no button, “You clicked no” would show up. But no matter which button is pressed, the answer is “You clicked yes”.
Could anyone help us? Thank you so much!
Here is our code:

And our project link:

So “component” is the name of the button that was clicked. In your “when any button is clicked” block, you’ve said that component = component for both parts of that if statement. So you’re going to get ‘yes’ every time, because the first if is true, so it never gets to the else if.

Here’s one solution:
Read the /text/ on the button and use that to decide what they clicked. Here’s a simplified example:
image - you could use some joins to make it do exactly what you wanted.

Some other thoughts:

Do you really want to do cloning in this case? You only have two buttons. If this is a simplified example of where a bunch of other different stuff is going to happen depending on which button was clicked, you might just want to have two separate "when button no clicked’ and ‘when button yes clicked’ blocks.
Do you really want to clone the label, as opposed to making a single label that you change the visibility and text of after clicking? It depends on what you’re doing, of course, but this strikes me as a complicated approach if the problem is not actually more complicated that what you’re presenting.


Hello, thank you so much for your reply. Yes, It is a simplified example. But how could we separate these two buttons, because the only block that I found in any components is “When ‘Any Button’ ‘Click’”.

See my example above. If the text on the buttons is different, you could use the block I showed to compare the value of the text (yes or no?) to a string containing ‘yes’ or ‘no’. Alternately, you could record the “component” value (a big alphanumeric string) for each button as you clone it, and store each one in a variable, to compare to the component value when you use the “any button click” block.

1 Like

I tried to store them in two variables, but now it only shows “Label”. Also, we are making a calendar, so we want every button to lead to a separate function. Is there a way that we could accomplish that? Thank you.
The code we have now:

1 Like

Your nested “any button click” has a component and then another component. I’m not quite sure how that’s getting parsed. The label and the button have different component names, but which “component” block is which in your example?


In your code, you created 2 buttons and gave them different captions. You have not created any label therefore the “Label” in your if statement should refer to a label you placed in the screen at design time and you refer to at as a normal label [set Label1's Text to].

This change should get the result you are looking for.

Thank you very very much! We solved it! It turns out we can’t nest components, but we could separate them using if statement. It works perfectly now!


Super. Please mark the post as the solution if it is! :slight_smile: Oh, you did. Nevermind! :slight_smile: