Wish [BANano] [SOLVED]- 1.21 Enumeration Initialization Assignments

Mashiane

Expert
Licensed User
Longtime User
Hi there

I have defined a class to hold some enumeration values, below is one of them

B4X:
#IgnoreWarnings:12
    'create a COLOR class
Sub Class_Globals
    Public AMBER As String
    Public BLACK As String
    Public BLUE As String
    Public BLUEGREY As String
    Public BROWN As String
    Public CYAN As String
    Public DEEPORANGE As String
    Public DEEPPURPLE As String
    Public GREEN As String
    Public GREY As String
    Public INDIGO As String
    Public LIGHTBLUE As String
    Public LIGHTGREEN As String
    Public LIME As String
    Public ORANGE As String
    Public PINK As String
    Public PURPLE As String
    Public RED As String
    Public TEAL As String
    Public TRANSPARENT As String
    Public WHITE As String
    Public NORMAL As String
    Public YELLOW As String
End Sub

'Initializes COLOR object
Sub Initialize() As BANanoMaterialColor
    AMBER = "amber"
    BLACK = "black"
    BLUE = "blue"
    BLUEGREY = "blue-grey"
    BROWN = "brown"
    CYAN = "cyan"
    DEEPORANGE = "deep-orange"
    DEEPPURPLE = "deep-purple"
    GREEN = "green"
    GREY = "grey"
    INDIGO = "indigo"
    LIGHTBLUE = "light-blue"
    LIGHTGREEN = "light-green"
    LIME = "lime"
    ORANGE = "orange"
    PINK = "pink"
    PURPLE = "purple"
    RED = "red"
    TEAL = "teal"
    TRANSPARENT = "transparent"
    WHITE = "white"
    NORMAL = ""
    YELLOW = "yellow"
    Return Me
End Sub

In a master class I have defined..

B4X:
Dim EnumColor as BANanoMaterialColor
EnumColor.Initialize

However calling

B4X:
Log(EnumColor.GREEN)

in the main module writes blank in the console.log. I could be doing this wrongly however assumed that it would work or rather its not assigning the values or something. Please have a peek!

Ta!
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Hi, it´s works for me.

B4X:
Log(EnumColor.GREEN)
'result - green
Try clean your project.
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Please, why don´t you use this way? (More simple)
B4X:
Sub Class_Globals
    Public AMBER As String = "amber"
   'Or Public Const AMBER As String ="amber"
    Public BLACK As String = "black"
    Public BLUE As String = "blue"
End Sub

Public Sub Initialize
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
Please, why don´t you use this way? (More simple)
B4X:
Sub Class_Globals
    Public AMBER As String = "amber"
   'Or Public Const AMBER As String ="amber"
    Public BLACK As String = "black"
    Public BLUE As String = "blue"
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
End Sub
The reason is, I want to perhaps do other things on Initialization besides just assigning values but I have also already implemented your suggestion. At times the compiler complains when assigning values in Class_Globals.

Fact is, due to Initialize is assigning values to the properties, it should work, unless its a design issue inside BANano, if that is the case then, its a learning curve.
 

alwaysbusy

Expert
Licensed User
Longtime User

Mashiane

Expert
Licensed User
Longtime User
Just tested it with v1.21 and it works. My only guess is that, just like you do wrongly in the BANanoMaterial library source code you gave in another topic, you don't do the EnumColor.Initialize in BANano_Ready but in AppStart, which is ignored as stated in this post: https://www.b4x.com/android/forum/threads/banano-progressive-web-app-library.99740/#post-627669

If this is not the case, impossible to track more without a (small) project demonstrating the bug.
Thank you for the positive response. Please note that as people who are new to BANano we are bound to make mistakes and need all the guidance and help we can get to create beautiful things for both the forum and ourselves. Erel has also on numerous occasions referred people back to their code to fix their own errors, its only natural and you also do the same and thanks for your patience and understanding also, it is very much needed.
 
Top