Re: Enumerated types
- From: Scott McDaniel <scott@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 02 May 2007 13:57:24 -0400
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
.
- Follow-Ups:
- Re: Enumerated types
- From: Peter Hallett
- Re: Enumerated types
- Prev by Date: Re: Possible Form Corruption?
- Next by Date: RE: DLookup Default Value in form?
- Previous by thread: Re: Possible Form Corruption?
- Next by thread: Re: Enumerated types
- Index(es):
Relevant Pages
|