Wish Enum Type

Knoppi

Active Member
Licensed User
Longtime User
difficult to maintain
BAD
B4X:
Public Const Red As Int = 0
Public Const Green As Int = 1
Public Const Blue As Int = 2

This code is much easier to maintain.
GOOD
B4X:
' VB.NET sample:
Public Enum Color
  Red
  Green
  Blue
End Enum

This wish exists since 2012 https://www.b4x.com/android/forum/threads/wish-enum-type.17768/

Please implement
 

aeric

Expert
Licensed User
Longtime User
I never use Enum.
To enable intellisense, I will use custom type.

B4X:
Sub Process_Globals
    Type Color ( _
        Red As Int, _
        Green As Int, _
        Blue As Int)
    Private Color As Color
End Sub

Sub AppStart (Args() As String)
    Color = CreateColor(0xFFFF0000, 0xFF00FF00, 0xFF0000FF)  
    LogColor("Red", Color.Red)
    LogColor("Green", Color.Green)
    LogColor("Blue", Color.Blue)
End Sub

Public Sub CreateColor (Red As Int, Green As Int, Blue As Int) As Color
    Dim t1 As Color
    t1.Initialize
    t1.Red = Red
    t1.Green = Green
    t1.Blue = Blue
    Return t1
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
I never use Enum.
To enable intellisense,




Color - Code module:
Sub Process_Globals
    Public Const RED As Int = 1
    Public Const GREEN As Int = 2
    Public Const BLUE As Int = 3
End Sub


However, having to create a code module for each Enum is a pain, it increases the number of modules.
I don't know why Erel doesn't implement Enums, but there must be a reason.
 

aeric

Expert
Licensed User
Longtime User
Yes Const is automatically intellisense enabled.
I write like this:
B4X:
Public Const COLOR_RED  As Int = -65536
Public Const COLOR_BLUE As Int = -16776961

But sometimes we may want to group some variables as same type.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…