The Power of B4X

LucaMs

Expert
Licensed User
Using a code module that "acts as Enum" is a great idea, I hadn't thought about it.
Another (not perfect) idea: that kind of code modules, "Enum code modules", might provide an AsList method.
You can guess why and how it might be useful.

It has a drawback: the list would contain editable values, the values of the constants. On the other hand, there would also be advantages, such as using the methods of Lists, mainly IndeOf, I think.

And... a comment like: "You shouldn't change the values in this List" might be enough for a shrewd programmer.
 
Last edited:

William Lancee

Active Member
Licensed User
If one wants to use the enumX.property construct for grouped constants there is always this:


B4X:
Sub Process_Globals
    Type enumA(goAHead As Boolean, firstThree() As Int, myName As String)
End Sub

Sub AppStart (Args() As String)
    Dim enum As enumA = newEnumA(True, Array As Int(1, 2, 3), "William")
    Log(enum.myname)
End Sub

'this is automatically created by hovering over enumA - I always rename to "newXXXX"
Public Sub newEnumA (goAHead As Boolean, firstthree() As Int, myName As String) As enumA
    Dim t1 As enumA
    t1.Initialize
    t1.goAHead = goAHead
    t1.firstthree = firstthree
    t1.myName = myName
    Return t1
End Sub
 
Top