Page 1 of 2

Sort of "concatination" question

Posted: Monday 13th December 2021 11:38pm
by firstsolo
I hope someone can point me in the right direction with this attempt at concatenation.
I control a number of radios. Each radio has a container to hold the display parameters for that radio. For example:
Tbfrequencyradio1, textbox to hold the frequency the radio is tuned to
Tbstationnameradio1, textbox to hold the station name
Group is gradio1

And so on for radio2 and radio3.
To alter the radio parameters, I can click on the wanted textbox and alter it. This approach means the same code repeated for each radio.
Instead I would like to call a subroutine
changeradioinfo("radio1")
so I can do:
Changeradioinfo(whichradio as string)
And then in someway....
tbfrequencywhichradio.text = "123•456"

This way I have only one set of code to deal with.

I have tried:
tbfrequency&whichradio ......error
Tbfrequency[whichradio] ......error
Even tried "!"
Tbfrequency!whichradio.....error
Is there a way to do this "concatination"? Or am I going about this the wrong way?
Thanks for any help
M

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 2:29am
by BruceSteers
I think i get your problem, if it is getting an object/control from a string then you can address an object/control via a string using a forms control array, just use the name of the form the textbox is in or "Me" if coding in that form.

Ie..

Dim tBox As TextBox = Me["tbfrequency" & whichradio]
tBox.Text = "123•456" 

' or''

Dim tBox As TextBox = fMain["tbfrequency" & whichradio]
tBox.Text = "123•456" 

if whichradio = "Radio1" then it will get the textbox called tbfrequencyRadio1

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 10:42am
by firstsolo
Thanks very much ....works... now to reduce the size of my source file!
Interesting that this form of construct is case sensitive.
I had a problem initially as I had named the control "Radio1" (notice upercase R) but passed the name "radio1" lower case R, just cause I am lazy! It works for the "normal" construct:

Fmain.tbfrequencyradio1.text is the same as Fmain.tbfrequencyRadio1.text (the R is either UC or LC)
Anyway sorted, stops me being lazy!

On last question if I may:
is there a form of[highlight=] fmain["tbfrequency" & whichradio].text [/highlight]that works. If I try this I get an error.

This is one of my learning issues with Gambas, I find it hard to generalise the information I get, or even to find the info in the first place:roll:
Is there a hidden Gambas repository that contains this knowledge!

Thanks M

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 11:15am
by cogier
firstsolo wrote: Tuesday 14th December 2021 10:42am
On last question if I may:
is there a form of[highlight=].text [/highlight]that works. If I try this I get an error.
You can change the Font, Bold, Background and Foreground.
With  fmain["tbfrequency" & whichradio]
   .Font.Bold = True
   .Font.Size = 14
   .Background = Color.Yellow
   .Foreground = Color.Red
End With

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 12:07pm
by firstsolo
Hi Cogier Tried this
 With FMain["tbfrequency" & whichradio]
    .Font.bold = True
    .tag = "tag"
    .text = "Test"
  End With
Font works, as does tag,
but text returns "unknown Symbol "text" in class "control" in......
When I "debug" FMain["tbfrequency" & whichradio] Then the resultant debug display shows "text" as on of the entries for the control.
Still I have a working solution that saves me a lot of duplicate code, so I am very happy.
The issues with trying to do something like..
temp =  FMain["tbfrequency" & whichradio].tab 
temp =  FMain["tbfrequency" & whichradio].text
it just seemed more "elegant"! I guess I am just missing some fundamental Gambas concepts..

Thanks for your ideas, filed for the future

M

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 2:40pm
by BruceSteers
Using the fMain[] method get a "Control" the Control.class does not have .Text etc.
you must do it like this...

Dim tb as TextBox = fMain["CotrolName"]

then you can...

tb.Text

fMain["CotrolName"].Text will not work

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 2:43pm
by BruceSteers
if you type fMain["controlName"].
(notice the dot)

once pressing the dot a completion list listing all available properties/methods for the control pops up.


your code will work like this...
Dim tb As TextBox = FMain["tbfrequency" & whichradio]
  With tb
   .Font.bold = True
   .tag = "tag"
   .text = "Test"
 End With

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 3:13pm
by firstsolo
Hi Bruce, thanks for the info, I do know about the "." but did not use it! I assumed that if ".tag" worked then ".text" would or should... Anyway your original post has me re-doing all my code to be simpler, so a great result.
As to why ".text" does not work but ".tag" does, I will leave for another day!

Thanks to all for the help
M

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 3:25pm
by BruceSteers
I'll try to make it make sense...
It's the way controls/objects are made.

Control.class is the parent class of all controls like TextBox.class

the TextBox.class Inherits Control.class and adds things like the .Text property

So a TextBox is a control with added extras.

the Control.class has things like .Font and .Background so you can access a TextBox font using the control array but to access the additional things like .Text you must use the TextBox identifier.

Hope that helps

Re: Sort of "concatination" question

Posted: Tuesday 14th December 2021 7:48pm
by firstsolo
It does help.
I have seen references to inheritance but skip over them as "difficult" to understand. Your explanation may well have opened the door to getting past the "baby stage" in Gambas programming and allow me to grow.

Many thanks
M