[Wish] Enum type

NeoTechni

Well-Known Member
Licensed User
Longtime User
ie:

I'm making a program where an array holds the element types I'm going to draw

This is how I do it now:
Dim LCAR_Button As Int,LCAR_Elbow As Int,LCAR_Textbox As Int, LCAR_Slider As Int
LCAR_Button=0:LCAR_Elbow=1:LCAR_Textbox=2:LCAR_Slider=3

I'd like to have it:
enum( LCAR_Button,LCAR_Elbow,LCAR_Textbox, LCAR_Slider)
And like VB, have B4A automatically assigns them values starting from 0
though in VB we can set a value if we want to, ie:
enum( LCAR_Button,LCAR_Elbow,LCAR_Textbox=99, LCAR_Slider)
enums are automatically longs in VB, but I guess INT would be fine in B4A

This is particularly useful for intellisense in VB, when entering a parameter in a function, or entering a select case, it'll pop up with a list of the enum values for us to click.

ie:
sub test(temp as boolean)
select case temp

if we were to type "case " (or get to that parameter in a function) a drop down would appear with true and false in it

This makes it easier to keep track of acceptable/expected values and results in neater code
 

Derek Johnson

Active Member
Licensed User
Longtime User
It's a while since you enquired but someone else might find this useful

Try this, add a code module called LCAR.

Put this in it:

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
Dim Const _
    Button=0, _
    Elbow=1, _
    Textbox=2, _
    Slider=3 As Int  'or whatever type you like

Now in any other module type lcar, and you will get the "Intellisense" dropdowns. The values are constants and have type Int, (though they could be any type).

upload_2015-2-20_15-35-50.png


There is no particular overhead in adding code modules of this type, and you can copy them from one project to another. Using this method you won't get the auto-increment of the values, but you only have to enter the values once and you do get the benefit of "Intellisense".

You could easily generate the lcar.bas file automatically if there were hundreds of values needed.
 
Top