Looping thru buttons

Hi - can someone please guide me to correct method?
I have many buttons (say btn_01, btn_02 thru btn_20).
At some point in my blocking I have a variable that stores a number say varBtnNumber.
I’d like to set - say the background of btn_12 to RED when varBtnNumber is 12
I’d like to set - say the background of btn_13 to RED when varBtnNumber is 13. etc
Is there a method whereby I can loop thru the objects (btn’s) and stop when I get last 2 characters of any btnName = varBtnNumber. ?
ps: I know how to do this in VBA.(Right(btn_name, 2) = varBtnNumber. )
Many thx…

Hi,

You need to carefully study the components located on the “Any components” tab. Then you will see that with their help you can easily solve your problem - "Any Component" Blocks - ✕ Docs

Best regards, Alex
ACtech demo project
Thunkable X Basic Programming Course
Block Reference
Component Reference
Bug tracker

thx Alex - I did see that one - but I still can’t see how I can harness that buttonName (ps: not button text).
Also the varBtnNumber is not generated from clicking any button.

Hey Alex - do you think there may be a better way than this below?:
Make a new list of all buttons (1 thru 20) where 1 represents btn_01, 2 represents btn_02 etc.
then use
For each item in J in list
If j = varBtnNumber and j =1 then do the background thing (using btn_01) else nothing
If j = varBtnNumber and j =2 then do the background thing (using btn_02) else nothing
If j = varBtnNumber and j =3 then do the background thing (using btn_03) else nothing
etcetc. thru to all 20 (bit inefficient but it would trap the one button matching the varBtnNumber )

Open the project by the link, click the Recursion button, and then click any buttons with Button 1 text. Have you been looking for this?

https://x.thunkable.com/projects/5db93ebab8e0fc9c685b3477/project/properties/designer/
Best regards, Alex
ACtech demo project
Thunkable X Basic Programming Course
Block Reference
Component Reference
Bug tracker

yr demo helped me thx Alex.
the way I was trying to do stuff was a little lack of knowledge.
So yr content certainly does help us newbies get onto a better line.
very much appreciated.

1 Like

Hi @townythunk,

Can you share your solution? I am also trying to do the same but wasn’t able to understand. Absolute newbie here.
So I have buttons 1-36. I have a variable being set in another screen.
In the current screen, if button number < variable, set background color of button to green else white.
For ex, say variable has been set to 5 in the previous screen. When current screen opens, buttons 1-4 will be green, button 5 will be blue and 6-36 will be white.
Please help.

SusovanUntitled
Edit: So I have managed to do this. But not sure how I can change the button name to show i-th button. I mean when the loop is 1, i want to change color of button 1, when loop is at 2, I want to change color of button 2.
Is this possible???

Ok so I found the solution. Its working as per my requirement now.

Untitled

1 Like

Great work! @thestrengthinstitute