Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

Enumerated types

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Hallett - 02 May 2007 18:35 GMT
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.

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?

Signature

Peter Hallett

Scott McDaniel - 02 May 2007 18:57 GMT
>I have clearly failed to understand the syntax of enumerated types.  Having
>declared :-
[quoted text clipped - 9 lines]
>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.
[quoted text clipped - 4 lines]
>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@takemeout_infotrakker.com
www.infotrakker.com
Peter Hallett - 02 May 2007 19:33 GMT
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.
Signature

Peter Hallett

> >I have clearly failed to understand the syntax of enumerated types.  Having
> >declared :-
[quoted text clipped - 52 lines]
> scott@takemeout_infotrakker.com
> www.infotrakker.com
Klatuu - 02 May 2007 19:36 GMT
One of two ways.  One of which you touched on.
1.  Create an Array and use a numeric counter retrieve the values (I prefer
to use a Long data type for counter varialbes because they align on a word
boundry.

Dim varLetters as Variant
Dim lngCtr As Long
Dim strOneLetter as String

   varLetters = Array("A","B","C","D")

   strOneLetter = varLetters(lngCtr)

2. Create a string with the letters and use a counter variable and the Mid
function to retrive a value:

Dim strAllLetters as String
Dim lngCtr As Long
Dim strOneLetter as String

   strAllLetters = "ABCD"

   strOneLetter = Mid(strAllLetters, lngCtr,1)
   
Signature

Dave Hargis, Microsoft Access MVP

> I have clearly failed to understand the syntax of enumerated types.  Having
> declared :-
[quoted text clipped - 18 lines]
> surprisingly, VBA was having none of it.  Would anyone be kind enough to
> clarify the situation for me?
Peter Hallett - 02 May 2007 20:21 GMT
Dave,
Having concluded, from the earlier reply, that the magic '4-liner' was
unlikely to emerge, I have done something similar to your first suggestion.  
Your method of initialising the array is, however, much neater than mine.  
That will allow me to tidy things up a bit.  Your second suggestion is also
an interesting one.  I might yet try that.
Signature

Peter Hallett

> One of two ways.  One of which you touched on.
> 1.  Create an Array and use a numeric counter retrieve the values (I prefer
[quoted text clipped - 43 lines]
> > surprisingly, VBA was having none of it.  Would anyone be kind enough to
> > clarify the situation for me?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.