Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enum entries text 2

Status
Not open for further replies.

nigelrivett

IS-IT--Management
Sep 8, 2003
1,774
GB
I want to be able to get the entries from an enum and display them to the user.
specifically those from
adodb.SchemaEnum

I want to be able to display things like

adSchemaTables
adSchemaProcedures
adSchemaFunctions
...

from the enum and get the values associated.

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Sure. No problem. You'll need to add a reference to the TypeLib Information library to your project - then this function should do the trick:
Code:
Public Function GetADOEnumMemberName(strEnumName As String, Optional varVal As Variant) As Variant

    Dim TLIApp As TLIApplication
    Dim myConstant As ConstantInfo
    Dim EnumMember As MemberInfo
    Dim ADOTLI As TypeLibInfo

    Set TLIApp = New TLIApplication
    
    'If Not IsMissing(varVal) Then lVal = varVal

    ' Get our type library info from the relevant file
    ' This is the line that makes this example specific to the ADO object library
    Set ADOTLI = TLI.TypeLibInfoFromFile("c:\program files\common files\system\ado\msado15.dll") '(TLInfo.Guid, TLInfo.MajorVersion, TLInfo.MinorVersion, 1024)
 
    ' Loop through members of libraries constants
    For Each myConstant In ADOTLI.Constants
        If myConstant.TypeKind = TKIND_ENUM And myConstant.Name = strEnumName Then
            For Each EnumMember In myConstant.Members
                If Not IsMissing(varVal) Then
                    Select Case TypeName(varVal)
                        Case "String"
                            If EnumMember.Name = varVal Then GetADOEnumMemberName = EnumMember.Value
                    'If EnumMember.Value = lVal Then
                    '    GetADOEnumMemberName = EnumMember.Name
                    'End If
                        Case "Integer"
                            If EnumMember.Value = varVal Then GetADOEnumMemberName = EnumMember.Name
                    End Select
                Else
                ' List all members of this enum in debug window if you like
                ' it is left as an exercise to the reader to determine a nice way of returning this info to the calling procedure...
                 Debug.Print EnumMember.Name, EnumMember.Value
                End If
            Next
        End If
    Next
End Function
It can be invoked in a number of ways:

GetADOEnumMemberName("SchemaEnum", 20)

returns name of member of SchemaEnum enumeration with value of 20

GetADOEnumMemberName("SchemaEnum", "adSchemaTables")

returns value of member of SchemaEnum enumeration with name of adSchemaTables

GetADOEnumMemberName("SchemaEnum")

displays complete list of members of the named enumeration with their values in the IDE's immediate window

Obviously, instead of SchemaEnum you can use the name of any ADODB enumeration (and careful study of the code should give you enough info to start examining enumerations for any COM library instead of just ADODB)
 
Thanks a lot. Useful to ave a general routine.
What I have at the moment to test is this and seems to do the job.
Was hoping for something simpler than TLIApplication but it will do.

Dim TLIApp As TLIApplication
Dim ADOTLI As TypeLibInfo
Dim i As Integer
Dim j As Integer
Set TLIApp = New TLIApplication
Set ADOTLI = TLI.TypeLibInfoFromFile("c:\program files\common files\system\ado\msado15.dll") '(TLInfo.Guid, TLInfo.MajorVersion, TLInfo.MinorVersion, 1024)
For i = 1 To ADOTLI.Constants.Count
If ADOTLI.Constants(i).Name = "SchemaEnum" Then
Exit For
End If
Next
For j = 1 To ADOTLI.Constants(i).Members.Count
Debug.Print ADOTLI.Constants(i).Members(j).Name; ADOTLI.Constants(i).Members(j).Value
Next


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
just spoken to a friend who says this is simple in delphi - you can just get the members from the enum. Is there support for that in VB.net - I will be converting this to .net anyway, just writing in VB at the moment because it's quicker to prototype and I need a demo for Monday.


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
>Is there support for that in VB.net

Yes. Enums have a GetName (and GetNames) method and a GetValues method in VB.NET, which should do what you want
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top