[Gambas-user] User Defined DataTypes and User Defined Enum?
Ron Onstenk
ronstk at ...239...
Sun Apr 27 23:54:09 CEST 2008
On Sunday 27 April 2008 21:23, Nisse Nordlund wrote:
> Hi,
>
> In VB You can define datatypes 'User Defined Type" and 'User Defined Enum'
>
> Type:
> Syntax in VB (in vb modul), sample:
> *Private Type *ngnOwnTyp
> BytVal As Byte
> StrVal As String
> IntVal As Integer
> LngVal As Long
> SngVal As Single
> DblVal As Double
> *End Type*
>
> Enum:
> Syntax i VB (in vb modul), sample:
> *Private Enum* NGN_DATA_FORMAT
> m_BYTE = 1
> m_STRING = 2
> m_SHORT = 3
> m_LONG = 4
> m_RATIONAL = 5
> m_SBYTE = 6
> m_UNDEFINED = 7
> m_SSHORT = 8
> m_SLONG = 9
> m_SRATIONAL = 10
> m_SINGLE = 11
> m_DOUBLE = 12
> *End Enum*
>
> Is there any solution for this in gambas?
>
> Another procedure?
>
> A How to?
>
> The documentation in this lack.
>
> Regards
>
> N-G Nordlund
The best one I know is making a class which replace the 'Type' definition.
For every variable use you need the full line syntax as
PUBLIC YourVarName As WishType and ommit the Private Type' and 'End Type'
classfile: ngnOwnTyp.class
----------------------------------
' *Private Type *ngnOwnTyp
PUBLIC BytVal As Byte
PUBLIC StrVal As String
PUBLIC IntVal As Integer
PUBLIC LngVal As Long
PUBLIC SngVal As Single
PUBLIC DblVal As Double
' *End Type*
----------------------------------
Where you need the User def. variable you can do
DIM MyVarType as ngnOwnTyp
and
MyVarType = New ngnOwnTyp
-=-=-=-=-
Same can be done with the Enum and for each constant
classfile: NGN_DATA_FORMAT.class
----------------------------------
' *Private Enum* NGN_DATA_FORMAT
public m_BYTE As Integer = 1
public m_STRING As Integer = 2
public m_SHORT As Integer = 3
...
' *End Enum*
----------------------------------
usage as:
dim myselection as integer
myselection = NGN_DATA_FORMAT.m_SHORT
Pro is you can use this enum file in more projects without cut and past
from your other code. I did use the enum with a symlink to the file
outside the project in the past. (gambas0.xx till 1.9.39)
The 'Type' as class is more or less logic while a variable of that type
is also a class on his own in VB but internal in the *.cls or *.mod file.
Ron
More information about the User
mailing list