Re: Enumerated types



Thanks for the prompt reply, Scott. I now understand enumerated types rather
better. It seems as if accessing an array by index is, after all, the best
way of going about the job but I have to initialize the thing and it all
looks clumsy. It would be almost as easy to forget the For...Next loop and
set the required values in four sequential explicit statements. That, too,
doesn't look too elegant but it would be much worse with 40 values to set,
instead of 4.

Come back Kernighan & Ritchie. All is forgiven. I must be getting old.
--
Peter Hallett


"Scott McDaniel" wrote:

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

  • rs232...
    ... Hello Scott and everyone else who will read this post. ... //immediatelly assigned to this array. ... // from the rs232 port), ... I thank Scott and all members of the news groups that have helped me on the ...
    (microsoft.public.vc.language)
  • Re: SQL query... is there a better way?
    ... Scott ... > data types, you can understand how data is stored, and what exactly it is. ... and exposed them as public string properties. ... Of course, an array is of fixed length, so you need to either ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [Question:]How to split one file into 3/4 using fortran?
    ... "Gary L. Scott" wrote: ... I don't know how to open the array to store the ... > Now if you know the EXACT format (exact number of comments, ... > Liberty is a well armed sheep contesting the vote. ...
    (comp.lang.fortran)
  • Re: Parsing between a character and sysmbol
    ... Scott M. wrote: ... when you can immediately split the string at its location and throw away the ... And then populate each member of the array with a copy of the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Passing arrays ByVal vs ByRef
    ... If you pass a reference type (such as an Array), you get a copy of the reference, not the type and this explains why your original array is modified when you modify the passed parameter. ... Thanks for the information, Scott. ... So I just assumed that the array that I was passing was using pass-by-value. ...
    (microsoft.public.dotnet.languages.vb)