[Gambas-user] Disable controls by Tag
Jesus Guardon
jguardon at ...2035...
Fri May 29 12:27:35 CEST 2009
Ron_1st escribió:
> On Thursday 28 May 2009, Jorge Carrión wrote:
>> ¿Perhaps trying sonething like this?
>>
>> PUBLIC SUB btnQuick_Click() 'toggle button
>>
>> DIM hCtl AS Control
>>
>> IF btnQuick.Value = TRUE THEN
>> FOR EACH hCtl IN FMain.Controls
>> TRY hCtl.Enabled = (hCtl.Tag <> "exclude")
>> NEXT
>>
>> it Is not very elegant but it works, I guess.
>> Regards
>> Jorge
>>
>
>
> I'n happy it works now at Jesus Guardon's box.
>
> The TRY is also a nice way. You can try it to get more
> speed in the loop and it gives a more nice text layout.
>
> Against that way is you forget why you use the trick
> and now it is good help to know a method to prevent
> the error.
> Any way if you start using the TRY method add a remark
> why it is used.
>
>
>
> Best regards,
>
> Ron_1st
>
I agree with Ron_1st. I don't like to use TRY if there's not a good
reason to. Anyway, Jorge's code looks pretty and short. Here is another
approach without 'TRY':
FOR EACH hCtl IN FMain.Controls
IF hCtl IS TextBox OR hCtl IS ComboBox THEN 'etc
IF hCtl.Tag = "exclude" THEN
IF btnQuick.Value = TRUE THEN
hCtl.Enabled = FALSE
ELSE
hCtl.Enabled = TRUE
ENDIF
ENDIF
ENDIF
NEXT
But it could be slower because it checks button state in each loop.
Regards
Jesus
More information about the User
mailing list