[Gambas-user] Disable controls by Tag (Solved)
Jesus Guardon
jguardon at ...2035...
Thu May 28 18:13:00 CEST 2009
Ron_1st escribió:
> On Thursday 28 May 2009, Jesus Guardon wrote:
>> Hi all
>>
>> It seems a basic question, but I'm unable to get it to work.
>> I need to enable/disable a group of mixed controls in the Main Form, but
>> instead of doing individually, I'd prefer to do so by iterating.
>>
>> Following is the code I'm using and it gives an error "Wanted string,
>> date or integer, got function instead"
>>
>> What I'm doing wrong?
>>
>> PUBLIC SUB btnQuick_Click() 'toggle button
>>
>> DIM hCtl AS Control
>>
>> IF btnQuick.Value = TRUE THEN
>> FOR EACH hCtl IN FMain.Controls
>> IF hCtl.Tag = "exclude" THEN hCtl.Enabled = FALSE
>> 'DEBUG hCtl.Tag
>> NEXT
>> ELSE
>> FOR EACH hCtl IN FMain.Controls
>> IF hCtl.Tag = "exclude" THEN hCtl.Enabled = TRUE
>> NEXT
>> ENDIF
>>
>> END
>>
>> Regards
>>
>> Jesus
>>
>
> Not every control will have a .Tag property could be one of the problems.
> Same can be for the .Enabled property
> Also using Tag for other purpose could do something bad.
> Best would be to print the object type and .ID property for the control under test
> to see wich control has the problem.
>
> Controls written in gambas could be suspected I think.
> Basicly spoken the method used does not look strange to me
> and I did long time ago something like this the same way.
> I found also a problem and had the exclude a few object by type
> checking. As far I remember I was also using the .Tag property.
>
>
>
> Best regards,
>
> Ron_1st
>
Thanks, Ron_1st
As you stated, checking the type of the controls is needed. Now, it
works as expected.
PUBLIC SUB btnQuick_Click() 'toggle button
DIM hCtl AS Control
IF btnQuick.Value = TRUE THEN
FOR EACH hCtl IN FMain.Controls
IF hCtl IS TextBox OR hCtl IS ComboBox OR hCtl IS CheckBox
OR hCtl IS ValueBox OR hCtl IS Button THEN
IF hCtl.Tag = "exclude" THEN hCtl.Enabled = FALSE
'PRINT hCtl.Name, hCtl.Tag
ENDIF
NEXT
ELSE
FOR EACH hCtl IN FMain.Controls
IF hCtl IS TextBox OR hCtl IS ComboBox OR hCtl IS CheckBox
OR hCtl IS ValueBox OR hCtl IS Button THEN
IF hCtl.Tag = "exclude" THEN hCtl.Enabled = TRUE
ENDIF
NEXT
ENDIF
END
Best regards
Jesus
More information about the User
mailing list