[Webinar] Streamline your web hosting managementRegister Today

x
  • 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?
0
drjoeusa
Asked:
drjoeusa
1 Solution
 
Jeffrey CoachmanMIS LiasonCommented:
drjoeusa,

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.

JeffCoachman
0
 
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).
0
 
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.
0

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