ReneMiner
10-09-2016, 13:16
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
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