Android Question Enum

Terradrones

Active Member
Hi All

I have this in VB.net:

[
Public Enum UTMDatum
WGS84
NAD83
GRS80
WGS72
Australian1965
Krasovsky1940
NorthAmerican1927
International1924
Hayford1909
Clarke1880
Clarke1866
Airy1830
Bessel1841
Everest1830
End Enum
]

Which I wrote in B4A as:

[

Public Enum UTMDatum(WGS84,NAD83,GRS80, WGS72,Australian1965,Krasovsky1940,NorthAmerican1927,International1924,Hayford1909,Clarke1880,Clarke1866,Airy1830,Bessel1841,Everest1830)

]

But it is not working. Any hints please?
 

LucaMs

Expert
Licensed User
Longtime User
Use a code module and declare all that "fields" as public constants.

UTMDatum - Code module:
Public Const WGS84 As Int = 1
Public Const NAD83 As Int = 2
Public Const GRS80 As Int = 3
Public Const WGS72 As Int = 4
Public Const Australian1965 As Int = 5
Public Const Krasovsky1940 As Int = 6
Public Const NorthAmerican1927 As Int = 7
Public Const International1924 As Int = 8
Public Const Hayford1909 As Int = 9
Public Const Clarke1880 As Int = 10
Public Const Clarke1866 As Int = 11
Public Const Airy1830 As Int = 12
Public Const Bessel1841 As Int = 13
Public Const Everest1830 As Int = 14

B4X:
If MyVariable = UTMDatum.Krasovsky1940 Then
...

B4X:
Select MyVariable

    Case UTMDatum.GRS80
        '...
    Case UTMDatum.Everest1830
        '...
End Select
 
Last edited:
Upvote 1

ddk1

Member
Licensed User
This thread suggests that Enum function (per VisualBasic) has been implemented in B4A.
If I try the code above, Enum is highlighted in red and doesn't appear to work as expected.
I cannot find any documentation that suggests Enum is now implemented.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This thread suggests that Enum function (per VisualBasic) has been implemented in B4A.
If I try the code above, Enum is highlighted in red and doesn't appear to work as expected.
I cannot find any documentation that suggests Enum is now implemented.
Enum was not implemented.

In the example above, it was suggested to use a code module (I confirm that in my opinion it is the best way) named UTMDatum (obviously it is the suggested name for the needs of the OP).
 
Upvote 0

emexes

Expert
Licensed User
Any hints please?

This is a bit of a long-shot hint, but... depending on how the enum is used, a Map might work too:

B4X:
Dim Datums() As String = Array As String( _
    "WGS84", _                '0
    "NAD83", _                '1
    "GRS80", _                '2
    "WGS72", _                '3
    "Australian1965", _       '4
    "Krasovsky1940", _        '5
    "NorthAmerican1927", _    '6
    "International1924", _    '7
    "Hayford1909", _          '8
    "Clarke1880", _           '9
    "Clarke1866", _           '10
    "Airy1830", _             '11  https://en.wikipedia.org/wiki/George_Biddell_Airy#Reference_geoid
    "Bessel1841", _           '12
    "Everest1830" _           '13
)

Dim dm As Map
dm.Initialize

For I = 0 To Datums.Length - 1
    dm.Put(Datums(I), I)
Next

Log(dm.Get("Airy1830"))
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This is a bit of a long-shot hint, but... depending on how the enum is used, a Map might work too:

B4X:
Dim Datums() As String = Array As String( _
    "WGS84", _                '0
    "NAD83", _                '1
    "GRS80", _                '2
    "WGS72", _                '3
    "Australian1965", _       '4
    "Krasovsky1940", _        '5
    "NorthAmerican1927", _    '6
    "International1924", _    '7
    "Hayford1909", _          '8
    "Clarke1880", _           '9
    "Clarke1866", _           '10
    "Airy1830", _             '11  https://en.wikipedia.org/wiki/George_Biddell_Airy#Reference_geoid
    "Bessel1841", _           '12
    "Everest1830" _           '13
)

Dim dm As Map
dm.Initialize

For I = 0 To Datums.Length - 1
    dm.Put(Datums(I), I)
Next

Log(dm.Get("Airy1830"))
That code cannot replace Enums.
The names of the constants that are part of an Enum must be visible and easily written (listed by the IDE) in a project.
In a previous post:
B4X:
If MyVariable = UTMDatum.Krasovsky1940 Then
 
Upvote 0
Top