Accessing buttons created in for-next loop

dagnabitboy

Active Member
Licensed User
Longtime User
The code below is from the tutorial. It creates several buttons and has a single handler. My question: Is there a way to talk with those buttons outside of the handler? For example, let's say I want to change the color of the 2nd button. Is it possible?


Sub Activity_Create(FirstTime As Boolean)
For i = 0 To 9 'create 10 buttons
Dim Btn As Button
Btn.Initialize("Btn")
Activity.AddView(Btn, 10dip, 10dip + 60dip * i, 200dip, 50dip)
Next
End Sub

Sub Btn_Click
Dim b As Button
b = Sender
b.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
End Sub
 

gjoisa

Active Member
Licensed User
Longtime User
when ever 10 buttons having same id you can't access them separately . Rather you should declare array of buttons ;
Sub Activity_Create(FirstTime As Boolean)
Dim Btn(9) As Button
For i = 0 To 9 'create 10 buttons
Activity.AddView(Btn(i), 10dip, 10dip + 60dip * i, 200dip, 50dip)

Next
End Sub
I think this may work .
 
Upvote 0

dagnabitboy

Active Member
Licensed User
Longtime User
Thank you all.. I suspected I might be able to do something with an array.. just didn't know where to look.
 
Upvote 0
Top