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 - https://docs.thunkable.com/any-component-blocks

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