Re: Enumerated types



On Wed, 2 May 2007 10:35:01 -0700, Peter Hallett <PeterHallett@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

I have clearly failed to understand the syntax of enumerated types. Having
declared :-

Enum ACGroup
A = 1
B
C
D
End Enum

I cannot then access the members of the group. With J as a variable byte,
the compiler baulks at ACGroup.J or ACGroup(J). I simply wish to return A?D
for values of J between 1 and 4, respectively.

Be defintion an "enumeration" would return only numeric values. AFAIK, there is no way to have an Enum return Text
values. You could build a class or function for this, as you probably know, but there is no way to do this:

ACGroup(1)

and have that return "A"



There are other ways of doing this, of course, and, in this trivial example,
probably better ways, but it would be nice to have this option available.

One alternative I could try, in the mean time, is to declare a string array
and access its members using J as an index. As an old (=elderly) ?C?
programmer, I also tried ?For stString = ?A? To ?D? ?, but, hardly
surprisingly, VBA was having none of it. Would anyone be kind enough to
clarify the situation for me?

Don't believe you can use the For-Next or For Each syntax with an array, unless you work with the Ubound or LBound of
the array (although I could be wrong about that). You could do this in a Standard Module:

[General Declaration]
dim arr() As String
Dim i as integer

Function LoadArray() As Boolean
'/redim and load the array
redim arr(3)
arr(0)="A"
arr(1)="B"
arr(2)="C"
arr(3)="D"
End Function

Function GetArrayValue(ArrayIndex as Integer) as String
If ArrayIndex <= ubound(arr) Then GetArrayValue= arr(ArrayIndex)
End If

You'd have to call LoadArray when the app started, then anywhere you needed a value from the array just call
GetArrayValue(xx)





Scott McDaniel
scott@xxxxxxxxxxxxxxxxxxxxxxxxx
www.infotrakker.com
.



Relevant Pages

  • Re: what type would this array be?
    ... It depends on how you declare you array. ... If you declare it as: YourEnumTypetheArray, ... >would be interpreted as enum values, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using sparse to catch invalid RCU dereferences?
    ... RCU-protected pointers directly, and all of these would need to be ... RCU-protected array. ... sparse doesn't have the ability to declare ... members instead of the array. ...
    (Linux-Kernel)
  • Re: Enumerations And Random Numbers
    ... > range of the enumeration. ... As Herfried shows, the best solution is to add the members to an array, and ... pick some random value out of the array. ... It may be that the values in the Enum ...
    (microsoft.public.dotnet.languages.vb)
  • Re: C# Array question
    ... How do I declare this kind of array in C#? ... an array of either struct or class with those two members. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)