[Gambas-user] How to Enable/Disable 55 buttons in a few string of code?

Tobias Boege taboege at ...626...
Sun Aug 25 13:09:51 CEST 2013


On Sun, 25 Aug 2013, Kende Kriszti??n wrote:
> > Hi,
> > 
> > Something like this:
> > 
> > For i = 1 To 55 
> >      Button & i &.Enable = True
> > Next
> > 
> > Of course, this does not work. 
> > So what the way?
> > 
> > Thanks
> > 
> 
> For example:
> 
> Dim ctrl As Control
> 
> For Each ctrl In FMain.Controls
> 
>   If InStr(ctrl.Name, "Button") = 1 Then ctrl.Enabled = True
> 
> Next
> 

One other possibility is to use the Action class:

	Action["thebuttons"].Enabled = True

As a supplement to Kende's answer, you can also have the Form search the
exact names for you:

	FMain.Controls["Button" & Str$(i)].Enabled = True

Also, if they are all in the same container (and are the only ones in the
container), you can initially set only the container to Enabled = False
which would also disable its children. Reenabling the container will
reenable all the children, too.

Regards,
Tobi




More information about the User mailing list