catching a button_click as variable/string

MDEnt

Member
Licensed User
Longtime User
If I were to have a number of buttons spread throughout my app - across different panels for example. Is there an easy way to catch the button name that was clicked as a variable/string?

Thanks to all for a great support on a great product.
 

klaus

Expert
Licensed User
Longtime User
In the Designer you have following properties:
Name: the view name
EventName: the name for the view's events.
Tag: an independant property that can hold any object

If you have 10 buttons called btnTest1, btnTest2 to btnTest10 you can set the EventName property to btnTest for all Buttons and set their Tag property to 1, 2, to 10. The Tag property is used to know what Button raised the event.

Then in the code you need:
B4X:
Sub btnTest_Click
  Dim btn as Button

  btn = Sender
  Select btn.Tag
  Case 1
  Case 2
  .
  .
  Case 10
  End Select
End Sub
You'll find an example in the SecondProgram in the Beginner's Guide.

Best regards.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…