Results 1 to 2 of 2

Thread: grouped Enumeration as other languages have

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,528
    Rep Power
    170

    grouped Enumeration as other languages have

    many other programming languages offer the user to group enumerations. It's very helpful especially if there is an autocomplete-feature within the IDE if you type the groups name followed by a dot and then it shows you the possible values you may use to select one of it.
    Visual Basic has Enum...End Enum-blocks, pureBasic has Enumerate...End Enumerate-blocks - others have others and we can have it too. And it's not so difficult to realize i think. I wrote about this before but it seems never anyone read it...

    Enumerations can be used for flags, colors, names or any kind of values that are {const|static} for the duration of the script execution.

    Lets have a look how i would start using current thinBasic-possibilities:

    ' create some udt:
     Type tFontFlags 
      ' all subelements are the same to "all" variables of this udt
      ' and so i use Static
      ' also all subelements are the same type, in this case Long
    
      Static None          As Long
      Static Bold          As Long 
      Static Italics       As Long 
      Static Underline     As Long  
      Static Strikethrough As Long 
    ' ---------------------------------------------------------------------
      Function _Create()
    ' ---------------------------------------------------------------------
        ' initialize values on creation, 
        ' same to all variables of this type
        Me.None          = 0 
        Me.Bold          = 1
        Me.Italics       = 2
        Me.Underline     = 4 
        Me.Strikethrough = 8
      End Function
    
    End Type
    
    ' and there is only one global variable of this type needed:
    Global FontFlags As tFontFlags  ' this will call tFontFlags._Create() where the values get assigned to FontFlags
    
    a usage-example of the above
    ' lets have a few fonts:
    Type tFont
      sName As String
      lSize As Long
      lFlags As Long
    ' ---------------------------------------------------------------------
      
      Function Init( ByVal sName As String, 
                     ByVal lSize As Long, 
            Optional ByVal lFlags As Long )
    ' ---------------------------------------------------------------------
        Me.sName  = sName
        Me.lSize  = lSize
        Me.lFlags = lFlags
        ' somehow load the file and install, i omit this here...
      End Function
                     
    End Type
    
    Dim myFont(4) As tFont
    
    myFont(1).Init( "Arial", 12 )
    myFont(2).Init( "Courier New", 14, FontFlags.Bold )
    myFont(3).Init( "Courier New", 20, FontFlags.Italics + FontFlags.Underline )
    ' ...
    ' assume the fonts are ready to use now...
    
    Now with some mixture of Begin Const + Begin Type - lets call it Begin Enumeration,
    we could create our grouped enumerations for whatever we need. I imagine somehow like

    ' now Alias "Type + Const" As "Enumeration"-Idea
    
    ' all the steps from first code-example above in these few lines: 
    
    ' dim global udt-variable "FontFlags" 
    '    subelements are ALL Long-variables :
    
    Enumeration FontFlags As Long                               
    
    ' define subelement-names and fill in values:
    
        None            ' =  0  first would be zero automatic if Enumeration ... As <numeric type>
        Bold            ' =  1  it would increase the above
                        '       automatic as "Begin Const"-block works
        Italics        ' this would be 2 then...
        Underline       << 1 ' shift the above 1 bit left
        Strikethrough   << 1
    
    End Enumeration
    
    Last edited by ReneMiner; 10-09-2016 at 13:28.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Ciao René,

    I will think how to implement but, your idea to have a Type with static members and a constructor is great

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Logical Languages
    By LanceGary in forum Shout Box Area
    Replies: 2
    Last Post: 10-01-2012, 02:05
  2. Enumeration
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 18-03-2009, 10:04
  3. Other programming languages
    By ErosOlmi in forum Other languages
    Replies: 0
    Last Post: 16-05-2007, 23:18
  4. Most used development languages ?
    By ErosOlmi in forum Development
    Replies: 1
    Last Post: 21-12-2006, 20:50

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •