Android Question Constants in sub

Duque

Active Member
Licensed User
Longtime User
Can I use b4a to generate a list of options in a function, as is done here?
 

Duque

Active Member
Licensed User
Longtime User
This is what I have been doing, but when the application grows, the number of variables and functions also grows.
I think this is closer since the function will return only the necessary group of variables


B4X:
Sub Process_Globals
    'tipo de alertas
    Type tpa (Alerta As Int, Confirmacion As Int, Informacion As Int, Error As Int)

End Sub


Public Sub TpAlerta As tpa
    Dim x As tpa
    x.Initialize
    x.Alerta          =1
    x.Confirmacion=2
    x.Informacion =3
    x.Error           =4
    Return x
End Sub

'from other modules called
vari.TpAlerta.Alerta
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The type gets compiled to a Static class, so you are not really saving anything over creating a code module for each variable type, and it's easier to access.
Code module Name = CAlerta

B4X:
Sub Process_Globals
    'tipo de alertas
    Public Const Alerta As int = 1
    Public Const Confirmacion As int = 2
    Public Const Informacion As int = 3
    Public Const Error As int = 4
End Sub


'Usage
CAlerta.Alerta

If you name them all carefully, you can get them to appear where you want in the intellisense menu. If you are writing a suite of apps, you can compile them to a library.
 
Last edited:
Upvote 0

Similar Threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…