Ok guys, well i'd like to achieve an effect of nested enumeration for easy grouping some constant strings. Something like the pseudo code bellow:
Enum gKS
Colby = "Hello"
Hays = "World"
end Enum
Enum gMA
Dodge = "Seven"
Muscatine = "Ports"
end Enum
Enum gCountry
north as gMA
south as gKS
end Enum
Public USA as gCountry
So the code bellow should output a "Seven" message:
开发者_如何学Csub dol()
msgbox USA.north.Dodge
end sub
I don't want use types or classes because no initialisation is needed since all values are know (constants as i said).
Any suggestions?
thx.
Classes are the way to go on this. Enums are simply long values, where limited selection is needed. This will allow for the greatest flexibility with your objects, in case you need these objects to have other function/subs.
Here is a simple layout:
gCountry Class:
Public North As gMA
Public South As gKS
Private Sub Class_Initialize()
Set North = New gMA
Set South = New gKS
End Sub
gKS Class:
Public Property Get Colby() As String
Colby = "Hello"
End Property
Public Property Get Hays() As String
Hays = "World"
End Property
gMA Class:
Public Property Get Dodge() As String
Dodge = "Seven"
End Property
Public Property Get Muscatine() As String
Muscatine = "Ports"
End Property
Testing It:
Public Sub TestIt()
Dim USA As New gCountry
MsgBox USA.North.Dodge
End Sub
I don't believe you're going to be able to do embedded enums the way you are hoping, because enums are considered primitives in the CLR (source). You may as well try to embed ints within ints.
I realize you said you didn't want to use classes, but this is the sort of situation static classes are meant to fill in the .NET world. It will be easily and arbitrarily accessible with no initialization and quick when compiled. This page has more information on statics if you're not familiar with them. You should be able to do whatever you need to do to get the information set up the way you want within that class, be it multiple static classes, a hash table, a multi-dimensional array, or whatever have you.
THX,
So. i've decided to solve that issue using types:
Public Type fCAOCC
itRGI As String
...
End Type
Public Type fCAOBF
itRGI As String
ibEnviar As String
...
End Type
Public Type gTELAS
CAOBF As fCAOBF
CAOCC As fCAOCC
...
End Type
Public CSI As gTELAS
Sub iniGLOBALS()
CSI.CAOBF.itRGI = "DIVNRRGILIG"
CSI.CAOBF.ibEnviar = "DUMMYNAME1"
CSI.CAOCC.itRGI = "Hello"
...
End Sub
And thats ready for later use on code...
cya
精彩评论