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.
Dim btn As Button
btn = Sender
GetTagValue=btn.Tag
I came across this over the weekend myself, and I'm using Tag for now.
But why don't we have a Name/id attribute?
Dim Map1 As Map
Map1.Initialize
...
Dim b As Button
name = "aname"
b.Initialise(name)
Map1.Put(name, b) ' key can be whatever you want
...
Dim b2 As Button
b2 = Map1.Get("name")
You could stick them in a Map and get them that way. It would be far more efficient.
B4X:Dim Map1 As Map Map1.Initialize ... Dim b As Button name = "aname" b.Initialise(name) Map1.Put(name, b) ' key can be whatever you want ... Dim b2 As Button b2 = Map1.Get("name")
What you need to do is to set the event name of all the buttons to be the same (eg HandleButtons), and the tag to be the individual panel nameA few interesting options it seems - utlimately here is what I am trying to accomplish:
I have 25 buttons (each one on a separate page/view in designer) - each button is named similar (buttonV1, buttonV2 ... etc.)
I have 25 Subs each very much identical - the button simply moves to the next panel...
Sub buttonV1_Click
Load PageV2
End Sub
Sub buttonV2_Click
Load PageV3
End Sub
and so on...
everything works fine as it is - my number of panels with buttons may grow - so I'm looking to (efficiently) consolidate all the subs into a single sub by somehow making a single variable that can identify which button was clicked and pass the variable to the sub by building a string for example - that way it will call the appropriate next panel in the series.
Dim btn As Button
btn = Sender
GetTagValue=btn.Tag
Load GetTagValue
That is not valid B4A syntax. Assuming you have writen a Sub called LoadLoad GetTagValue
Yes, I see how this could work. I'm playing around with it as suggested and getting:
Compiling code. Error
Error parsing program.
Error description: Undeclared variable 'load' is used before it was assigned any value.
Occurred on line: 130
Load GetTagValue
Sub buttonV2_Click
Load PageV3
End Sub
Dim btn As Button
btn = Sender
GetTagValue=btn.Tag
CallSub("",GetTagValue)
Success! Thanks so much!
Now to consolidate those panel subs - a new question thread coming soon I'm sure!
OK, try this:
set the event name of all the buttons to be the same (eg HandleButtons)