RE: Enumerated types



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)

--
Dave Hargis, Microsoft Access MVP


"Peter Hallett" 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.

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?

--
Peter Hallett
.



Relevant Pages

  • RE: Follow up question. Get value of closed file.
    ... You havve to access each member of the array ... Dim ReturnData as Variant ... SourceSheet As String, _ ... Dim rsData As Object ...
    (microsoft.public.excel.programming)
  • Re: Need help with SeriesCollection Object Please !
    ... Why did you use 4 Elements in your Array and then the use of the Exit ... Function GetSourceSheet(sFmla As String, sWSname, sFile As String) As ... Dim i As Long ... ran my code on certain other charts sometimes it would return ...
    (microsoft.public.excel.programming)
  • Re: Searching for best matches in string query
    ... looped through my recordset as an array counting the matches. ... 'Receives an array to be searched and the string value containing all the ... Dim arrData() ' As String ... Dim iLeftcur, iRightCur, iPivot, iTemp As Long ...
    (microsoft.public.access.queries)
  • RE: ReDim Preserve code almost working
    ... specifying beginning and ending elements. ... SegList will, however, accept a zero-based array (because Option Base 1 does ... Optional iEnd As Long = -1) As String() ... Dim tmp() As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Sorting a variant array
    ... Dim tempList As Variant ... Dim testerList() As String ... Function sortTesters(rangeName As String) ... column range--but even that ends up as a x-rows by 1 column array. ...
    (microsoft.public.excel.programming)