Getting the name of a control on a form

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
pusherman
Posts: 16
Joined: Sunday 5th November 2023 11:45am

Getting the name of a control on a form

Post by pusherman »

Hello all,

I'm new to Gambas so I am still finding my way around. I have a question that I hope someone can answer for me.

I have a form with a TabStrip on it that contains five tabs. Each tab has a TextArea on it, 1 through 5. If I want to copy text into the TextArea of one of the tabs I have to find out what tab has been selected and then copy or paste into the TextArea;

If TabStrip.Index = 0 then TextArea1.Cut
If TabStrip.Index = 1 then TextArea2.Cut
and so on...

Is there a more elegant way of achieving this?

What I would like is;

Get the name of the TextArea on currently active Tab and put that into variable tArea
and instead of TextArea1.Cut use tArea.Cut

Any suggestions are welcome.

Thanks for reading
Pusherman
User avatar
BruceSteers
Posts: 1578
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Getting the name of a control on a form

Post by BruceSteers »

If a textarea is all that is on each tab you could do this...


Dim tArea As TextArea = TabStrip1[TabStrip1.Index].Children[0]

tArea.Cut



Or access it by name this way ...

Dim tArea As TextArea = Me.Controls("TextArea" & Str(TabStrip1.Index + 1))

tArea.Cut



Or this..
Dim tArea As TextArea = Me["TextArea" & Str(TabStrip1.Index + 1)]

tArea.Cut

If at first you don't succeed , try doing something differently.
BruceS
pusherman
Posts: 16
Joined: Sunday 5th November 2023 11:45am

Re: Getting the name of a control on a form

Post by pusherman »

That works perfectly, thank you.
:D :D :D
Post Reply