Referring controls with $variables

Post your Gambas programming questions here.
Post Reply
01McAc
Posts: 75
Joined: Sunday 24th January 2021 8:25pm

Referring controls with $variables

Post by 01McAc »

The situation:
I placed a textbox control in the main form. The Tag of the textbox gets the name of another control in the same form.
--> TextBox.Tag="DataComboView1"

When I try the following commands the compiler throws an error:
--> Print Me(TextBox.Tag).Table
--> Print ("DataComboView1").Table

Any idea how to refer to a control when I just have the name of a control in a string variable?

I know that MS-Acces supports it, e.g. Me($var).visible = True.
01McAc
Posts: 75
Joined: Sunday 24th January 2021 8:25pm

Re: Referring controls with $variables

Post by 01McAc »

Just found by chance on the internet https://lists.gambas-basic.org/pipermai ... 56722.html the answer. The correct command is:
--> FMain.Controls["DataComboView1"].Table

Obviously Me doesn't support this.
User avatar
BruceSteers
Posts: 1559
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Referring controls with $variables

Post by BruceSteers »

01McAc wrote: Tuesday 26th January 2021 2:35pm Just found by chance on the internet https://lists.gambas-basic.org/pipermai ... 56722.html the answer. The correct command is:
--> FMain.Controls["DataComboView1"].Table

Obviously Me doesn't support this.
Me just stands for the class or module file in use

for a normal Form (FMain) it refers to the form and class file of the same name.
so Me.Controls["DataComboView1"].Table would work.

the IDE gives great clues as you type.
Pressing a bracket after your object Ie . FMain.Controls( would show nothing , but using an angle bracket [ will show there are options using the angle brackets.

you can skip a whole lot of searching for answers just by trying different combinations of brackets ( , angle brackets [ , full stops . and seeing what gives you options and what options you get :)

Bruce
If at first you don't succeed , try doing something differently.
BruceS
Post Reply