Sort of "concatination" question
Posted
#1
(In Topic #784)
Trainee
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
Posted
Guru

Ie..
if whichradio = "Radio1" then it will get the textbox called tbfrequencyRadio1
Posted
Trainee
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 fmain["tbfrequency" & whichradio].text 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
Posted
Guru

firstsolo said
On last question if I may:
is there a form of.text that works. If I try this I get an error.
You can change the Font, Bold, Background and Foreground.
Posted
Trainee
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..
Code (gambas)
- 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
Posted
Guru

you must do it like this…
Dim tb as TextBox = fMain["CotrolName"]
then you can…
tb.Text
fMain["CotrolName"].Text will not work
Posted
Guru

(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…
Posted
Trainee
As to why ".text" does not work but ".tag" does, I will leave for another day!
Thanks to all for the help
M
Posted
Guru

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
Posted
Trainee
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
Posted
Guru

firstsolo said
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
Inheritance is easier than you'd think.
Here's a simple example…
Consider this class file, I'll call it TextBoxT.class …
now you have a TextBoxT that does everything a TextBox does but also has an extra Tag property TextBoxT.Tag2
You can add Public functions and other properties to the class all accessible using TextBoxT like any textbox.
PS.
To see the Tag2 property (or any others you make) in the IDE form designer you'd need to add them to the _Properties const..
Public Const _Properties As String = "*,Tag2"
(using * states all textbox properties)
this way if you want it in the form designer …
Code (gambas)
- ' Gambas class file
- Export ' need this to be visible in the form designer
- '
Posted
Guru

Class name RadioTextBox.class
Code (gambas)
- '
- ' Gambas class file
- '' Get or set the radio name, auto inserts the frequency text.
- ' build the collection adding radio frequency data to the corresponding radio names.
- $RadioFreqs.Add("123*456", "Radio1")
- $RadioFreqs.Add("135*632", "Radio2")
- ' this function is used when reading RadioTextbox1.RadioName
- Return $sRadio
- ' this function is used when writing RadioTextbox1.RadioName
- ' this is where we adjust things due to the change.
- $sRadio = Value
- '
there I have a Textbox that i can do the following…
Code (gambas)
- '
- RadioTextBox1.RadioName = "Radio2"
- '
the frequency is chosen using a collection of the RadioNames as keys by setting .RadioName the textbox auto updates itself.
Hopefully that will help get you started
All the best
Posted
Trainee
Spent today re-doing my software with your information and it has resulted in much better readability and a big reduction in lines of code! I like that!!
BIG THANKS!
I wonder if the forum would support "tagging" post like yours with "tutorial", sort of like what Steve Dee has done with some of his later "Did You Know" posts
<COLOR color="#FF0080">
level: Beginner
Type: Tutorial
category: Editor
subject: the TAB key
</COLOR>
Then indexing the post (I assume its a SQL DB of some sort) so it would be possible to get to find these sorts of really useful bits of teaching. The original question may have to be re-done, as like mine I did not know the right question to ask!
As I went through a large number of posts to look for an answer, I did try and copy many of the "snippets" but it got too much! There is so much great teaching here on the forum, one could write the definitive "Dummies guide to Gambas" with it!
Anyway onwards and upwards.
M
1 guest and 0 members have just viewed this.



