Link to home
Start Free TrialLog in
Avatar of awink
awinkFlag for Singapore

asked on

Loop through an Enum Statement

The solution includes use of an Enum Statement. I looked for a way to loop through the members and found this code on Microsoft's website:

Public Enum flavorEnum
  salty
  sweet
  sour
  bitter
End Enum

Private Sub TestMethod()
  MsgBox ("The strings in the flavorEnum are:")
  Dim i As String
  For Each i In [Enum].GetNames(GetType(flavorEnum))
      MsgBox (i)
  Next
End Sub

That looks easy enough, but my computer complains that GetType isn't declared as a variable. On the off-chance that it makes sense I looked for mscorlib.dll but didn't find it among my system files. I found that mscorlib.dll belongs to .NET. So, perhaps that is a dead end.
Now, whether or not mscorlib.dll can run on my computer (Windows 2000 SP4) and whether or not it contains the GetType function isn't really my primary concern. What would be very useful to me is a way to iterate through the members of an Enum Statement - perhaps just in the way the above code promises to do.
Any advice any one? :-)
awink
Avatar of DerSpinner
DerSpinner
Flag of Malta image

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of awink

ASKER

I am just learning to use Enum. So, iterating through its members seems to be on everybody's mind at that stage. Until such time that I upgrade to .NET I will just do without.
Thank you.