[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 704
  • Last Modified:

Iteration through predefined enumerations

The enumeration vbVarType includes a list of constants such as vbInteger, vbLong, vbSingle, vbDouble, vbArray with values 2, 3, 4, 5, and 8192 respectively.  I want to iterate through the enumeration as have both the names of the constant and the value of the constant.
I found an example that I thought might work that uses the code:

Dim items as array
items = System.Enum.GetValues(GetType(FirstDayOfWeek))

However, this doesn't work for me.  Is there another way to do this?
1 Solution
Jeffrey CoachmanMIS LiasonCommented:

I can only help you with the syntax, you will have to investigate the Object names on your own.

If you have a form with some controls on it, you can run code like this:

Private Sub Command5_Click()

Dim strHeaders As String
Dim ctl As Control
Dim strAccumulator As String

strHeaders = "ControlName   ControlLeftLocation" & vbCrLf
    For Each ctl In Me.Controls
        strAccumulator = strAccumulator & ctl.Name & "        " & ctl.Left & vbCrLf
    Next ctl
    Debug.Print strHeaders & strAccumulator

End Sub

This code will produce output similar to this:
ControlName   ControlLeftLocation
Command1        4800
Command2        5940
Label3            1440
Label4            2880
Command5        6840

Hope this helps.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
AFAIK, there is no way to get the values out of an Enum at runtime in VB 6 or VBA. The code you have is from a .NET application, which can do this. You can do something like this in the IDE, but it's not a good idea.

Best bet it so examine the Enum and include constants in your code during development (or a list of some sort, depending on your needs).
drjoeusaAuthor Commented:
It's good to learn that it's not possible to do what you're trying to do.  I'll do it manually until I move to .NEt.  Thanks.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now