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

T Lee Davidson t.lee.davidson at gmail.com
Tue Feb 1 19:46:19 CET 2022


On 2/1/22 12:50, 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 your matrice_testo and btns arrays are always kept in sync, you could use the String[].Find method; eg.
iIndex = matrice_testo.Find(Last.Name)

Personally, I think I'd simply populate the button's Tag with its index.


-- 
Lee


More information about the User mailing list