Sort of "concatination" question

New to Gambas? Post your questions here. No question is too silly or too simple.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Sort of "concatination" question

Post by BruceSteers »

firstsolo wrote: Tuesday 14th December 2021 7:48pm 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 ...
' Gambas class file

Inherits TextBox

Property Tag2 As Variant Use $vTag2
'
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 ...

' Gambas class file
Export  ' need this to be visible in the form designer
Inherits TextBox

Public Const _Properties As String = "*,Tag2" ' only do this if you need the properties in the form designer
Public Const _DrawWith As String = "TextBox" ' the form designer render it like a textbox
Public Const _Similar As String = "TextBox" ' with this in the form designer you can change a textbox into a textboxt with right click

Property Tag2 As Variant Use $vTag2
'
Last edited by BruceSteers on Tuesday 14th December 2021 8:54pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Sort of "concatination" question

Post by BruceSteers »

How's this..
Class name RadioTextBox.class
'
' Gambas class file
Export
Inherits TextBox

Public Const _Properties As String = "*,RadioName" 
Public Const _DrawWith As String = "TextBox" 
Public Const _Similar As String = "TextBox"

'' Get or set the radio name, auto inserts the frequency text.
Property RadioName As String

Private $sRadio As String

Static Private $RadioFreqs As New Collection  ' the list of frequencies matching radio names.


Static Public Sub _init()
  
  If $RadioFreqs.Count Then Return ' if static collection is already built then return

' build the collection adding radio frequency data to the corresponding radio names.
  $RadioFreqs.Add("123*456", "Radio1")
  $RadioFreqs.Add("135*632", "Radio2")
  
End

' this function is used when reading RadioTextbox1.RadioName
Private Function RadioName_Read() As String

  Return $sRadio

End

' this function is used when writing RadioTextbox1.RadioName
' this is where we adjust things due to the change.
Private Sub RadioName_Write(Value As String)

  If Not $RadioFreqs.Exist(Value) Then
    Message.Error("Radio name " & Value & " does not exist!")
    Return
  Endif

  $sRadio = Value
  Me.Text = $RadioFreqs[$sRadio]

End
'
there I have a Textbox that i can do the following...
'
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
If at first you don't succeed , try doing something differently.
BruceS
firstsolo
Posts: 8
Joined: Thursday 4th November 2021 5:44pm

Re: Sort of "concatination" question

Post by firstsolo »

OK, wow thanks for the "tutorial" its very useful and adds to the previous explanation of yours.
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

level: Beginner
Type: Tutorial
category: Editor
subject: the TAB key

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
Post Reply