Names of TextLabels (and other form elements) as variables
Posted
#1
(In Topic #1392)
Regular

Can I have TextLabels (or any other form elements) referred to with variable names?
To be precise, is it acceptable in Gambas3 to write a code somewhat like the following - after I named the TextLabels appropriately on the Form.form (starting from TextLabel1 / ending with TextLabel10)?
(Tried it, doesn't function.)
Posted
Guru

Ie…
The Form array
or the Form.Controls array
Posted
Regular

Posted
Regular

Posted
Guru

Only Control.class properties can be accessed directly.
All controls inherit Control.class but all added properties (like .Text) have to be accessed another way.
Use either Object.class or the specific class you want like this…
Dim o As Object = Me.Controls["TextLabel" & ii]
o.Text = some-string-out-of an-array[ii]
or this…
Dim tl As TextLabel = Me.Controls["TextLabel" & ii]
tl.Text = some-string-out-of an-array[ii]
Posted
Regular

Posted
Guru

Many of my programs have a simple function to treat a Control as an Object so i can easily access it's properties,
So with that function I can simply use it to set any property of a Control.class return type
like this…
ControlObject(Me.Controls["TextLabel" & ii]).Text = some-string-out-of-an-array[ii]
ControlObject(Me.Controls["CheckBox" & ii]).Value = some-boolean-value-array[ii]
1 guest and 0 members have just viewed this.


