We see this question as well as very similar ones every so often:
"I want to be able to have users pick values by name from a list of Enum value names. Is there a way to do this without manually creating my own lists?"
I'm not sure we've seen many good responses to these, and I don't see one here so I thought I'd post one.
The only place your programs might look to find this information is inside type libraries. And we have a nice tool for doing this without a ton of effort.
The TLI
Quoting its help file:
The TypeLib Information object library (TLI for short, implemented in TlbInf32.dll) is a set of COM objects designed to make type library browsing functionality easily accessible to both Visual Basic and C++ programmers.
Of course using it can take some study. But there is a wealth of functionality there, probably more than most programmers will ever need.
Requirements
You need the TLI, but since the VB6 IDE uses it you certainly have it. You may or may not have the help file for it, which was once distributed as TlbInf32.exe (a self-extractor). I don't have a current Microsoft link for that file though.
You also need type libraries for the Enums you want to do lookups on. These are often embedded within DLLs and OCXs, or may be in separate TLB files. In many cases it can be more conventient to access these by type library ID (GUID values), version, and locale (since there are such things as localized type libraries).
How To
So here is an example:
Image may be NSFW.
Clik here to view.![Name: sshot1.png
Views: 39
Size: 13.2 KB]()
Image may be NSFW.
Clik here to view.![Name: sshot2.png
Views: 31
Size: 9.1 KB]()
Image may be NSFW.
Clik here to view.![Name: sshot3.png
Views: 29
Size: 19.0 KB]()
"I want to be able to have users pick values by name from a list of Enum value names. Is there a way to do this without manually creating my own lists?"
I'm not sure we've seen many good responses to these, and I don't see one here so I thought I'd post one.
The only place your programs might look to find this information is inside type libraries. And we have a nice tool for doing this without a ton of effort.
The TLI
Quoting its help file:
Quote:
The TypeLib Information object library (TLI for short, implemented in TlbInf32.dll) is a set of COM objects designed to make type library browsing functionality easily accessible to both Visual Basic and C++ programmers.
Requirements
You need the TLI, but since the VB6 IDE uses it you certainly have it. You may or may not have the help file for it, which was once distributed as TlbInf32.exe (a self-extractor). I don't have a current Microsoft link for that file though.
You also need type libraries for the Enums you want to do lookups on. These are often embedded within DLLs and OCXs, or may be in separate TLB files. In many cases it can be more conventient to access these by type library ID (GUID values), version, and locale (since there are such things as localized type libraries).
How To
So here is an example:
Code:
Option Explicit
Private Sub cboAdoTypes_Click()
With cboAdoTypes
lblDataType.Caption = CStr(.ItemData(.ListIndex))
MsgBox .List(.ListIndex) & " = " & lblDataType.Caption
End With
End Sub
Private Sub cboSysColors_Click()
With cboSysColors
BackColor = .ItemData(.ListIndex)
End With
End Sub
Private Sub Form_Load()
Const ADO_GUID As String = "{00000205-0000-0010-8000-00AA006D2EA4}"
Dim DataTypeEnums As TLI.Members
Dim SystemColorConsts As TLI.Members
Dim Item As TLI.MemberInfo
With New TLI.TLIApplication
With .TypeLibInfoFromRegistry(ADO_GUID, 2, 5, 0).Constants
Set DataTypeEnums = .NamedItem("DataTypeEnum").Members
End With
With .TypeLibInfoFromFile("msvbvm60.dll\3").Constants
Set SystemColorConsts = .NamedItem("SystemColorConstants").Members
End With
End With
With cboAdoTypes
For Each Item In DataTypeEnums
.AddItem Item.Name
.ItemData(.NewIndex) = Item.Value
Next
End With
With cboSysColors
For Each Item In SystemColorConsts
.AddItem Item.Name
.ItemData(.NewIndex) = Item.Value
Next
End With
End Sub
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.