[Gambas-user] how to place code into events of an array of buttons?

Bruce Steers bsteers4 at gmail.com
Tue Feb 1 18:56:45 CET 2022


On Tue, 1 Feb 2022 at 17:51, <roberto.premoli at tiscali.it> wrote:

> > Change Form_Open like this
> > ' ...
> > matrice_testo[0] = "A"
> > matrice_testo[1] = "B"
> > matrice_testo[2] = "C"
> > matrice_testo[3] = "D"
> > matrice_testo[4] = "E"
> >
> > For n = 0 To 4
> > With btns[n] = New Button(FMain) As "btns"
> > .Name = matrice_testo[n]
> > End With
> > Next
> > ' ...
> >
> > Public Sub btns_Click()
> > Print Last.name
> > End
> >
> > Regards
> > Gianluigi
>
> Thanks Gianluigi!
> there is a way to take also the index of button pressed?
> because to have the index of button is necessary in other part of the
> program,
> I tried - naively - to do "variabile = Last.index" bot of course it
> does not work.
>
> If it is not possible, i can populate ".tag = n" and read it but it
> will appear
> to me more "clean" to use ".index" or similar, if available.
> Roberto
>
> PS: i miss so much to have "indexed objects" in Gambas graphical
> interface as it
> is available in VB.
>
>
> Con Tiscali Mobile Smart 70 hai 70 GB in 4G, minuti illimitati e 100
> SMS a soli 7,99€ al mese http://tisca.li/Smart70
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>


This will work if your buttons are all in one parent container


Public Sub GetButtonIndex(btn As Button) As Integer

Dim b As Button, i As Integer
For i = 0 To btn.Parent.Children.Count - 1
  if btn.Parent.Children[i] = btn Then Return i
Next

End
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220201/4a85857e/attachment.htm>


More information about the User mailing list