Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default programmatic generation of Enum To String functions

I have the problem right now that i wish i had a function to convert a
number of a particular enum to string (e.g.,
ADODB.DataTypeEnum.adDBTimeStamp to "adDBTimeStamp"). It should be
possible to automatically generate these conversion functions.

I know it is possible using some complicated object library that i
forget the name to scan a type library and programmatically iterate
over interfaces, methods of interfaces, etc, and i believe can read
enums. Therefore, a perfect application of this object library would
be to create the functionality that I discussed above. All i would
have to do is pass the path of the DLL or TLB file, and the name of the
enum, and the function would return the conversion functions.

Has anyone done this? Any help would be appreciated.


For example, it should automatically accept an Enum like this:


Public Enum cbfPhase
cbfNotAPhase
cbfNotStarted
cbfParsed
cbfBeta
cbfData
cbfDone
End Enum

And turn it into these:

Public Function cbfPhaseToString(ByVal Value As cbfPhase) As String
' Method for converting cbfPhase values into a String.
Select Case Value
Case cbfNotAPhase
cbfPhaseToString = "NotAPhase"
Case cbfNotStarted
cbfPhaseToString = "NotStarted"
Case cbfParsed
cbfPhaseToString = "Parsed"
Case cbfBeta
cbfPhaseToString = "Beta"
Case cbfData
cbfPhaseToString = "Data"
Case cbfDone
cbfPhaseToString = "Done"
End Select
End Function


Public Function StringTocbfPhase(ByVal Value As String) As cbfPhase
' Method for converting a String into cbfPhase.
Select Case Value
Case "NotAPhase"
StringTocbfPhase = cbfNotAPhase
Case "NotStarted"
StringTocbfPhase = cbfNotStarted
Case "Parsed"
StringTocbfPhase = cbfParsed
Case "Beta"
StringTocbfPhase = cbfBeta
Case "Data"
StringTocbfPhase = cbfData
Case "Done"
StringTocbfPhase = cbfDone
End Select
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default programmatic generation of Enum To String functions

Hi,
I notice that in your example of the Enum type you did not declare any
values to the members. Thus, Enum will automatically assign values such as 0
or 1. Perhaps using the Type Statement will be more helpful in doing what
you want. Refer to the Help in the Macro design.

Emilie

"R Avery" wrote:

I have the problem right now that i wish i had a function to convert a
number of a particular enum to string (e.g.,
ADODB.DataTypeEnum.adDBTimeStamp to "adDBTimeStamp"). It should be
possible to automatically generate these conversion functions.

I know it is possible using some complicated object library that i
forget the name to scan a type library and programmatically iterate
over interfaces, methods of interfaces, etc, and i believe can read
enums. Therefore, a perfect application of this object library would
be to create the functionality that I discussed above. All i would
have to do is pass the path of the DLL or TLB file, and the name of the
enum, and the function would return the conversion functions.

Has anyone done this? Any help would be appreciated.


For example, it should automatically accept an Enum like this:


Public Enum cbfPhase
cbfNotAPhase
cbfNotStarted
cbfParsed
cbfBeta
cbfData
cbfDone
End Enum

And turn it into these:

Public Function cbfPhaseToString(ByVal Value As cbfPhase) As String
' Method for converting cbfPhase values into a String.
Select Case Value
Case cbfNotAPhase
cbfPhaseToString = "NotAPhase"
Case cbfNotStarted
cbfPhaseToString = "NotStarted"
Case cbfParsed
cbfPhaseToString = "Parsed"
Case cbfBeta
cbfPhaseToString = "Beta"
Case cbfData
cbfPhaseToString = "Data"
Case cbfDone
cbfPhaseToString = "Done"
End Select
End Function


Public Function StringTocbfPhase(ByVal Value As String) As cbfPhase
' Method for converting a String into cbfPhase.
Select Case Value
Case "NotAPhase"
StringTocbfPhase = cbfNotAPhase
Case "NotStarted"
StringTocbfPhase = cbfNotStarted
Case "Parsed"
StringTocbfPhase = cbfParsed
Case "Beta"
StringTocbfPhase = cbfBeta
Case "Data"
StringTocbfPhase = cbfData
Case "Done"
StringTocbfPhase = cbfDone
End Select
End Function


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default programmatic generation of Enum To String functions

Hi R Avery,

Not sure if this is what you're looking for, but here's some code that will
output the list of data type enums (names and values) for the ADO library:

Sub test()
Dim tl As TLI.TypeLibInfo
Dim mi As TLI.MemberInfo


Set tl = New TypeLibInfo

tl.ContainingFile = "C:\Program Files\Common " & _
"Files\System\ado\msado15.dll"

For Each mi In tl.GetTypeInfo("DataTypeEnum").Members
Debug.Print mi.Name & ": " & mi.Value
Next mi
End Sub


The reference you're looking for is called "TypeLib Information".

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


R Avery wrote:
I have the problem right now that i wish i had a function to convert a
number of a particular enum to string (e.g.,
ADODB.DataTypeEnum.adDBTimeStamp to "adDBTimeStamp"). It should be
possible to automatically generate these conversion functions.

I know it is possible using some complicated object library that i
forget the name to scan a type library and programmatically iterate
over interfaces, methods of interfaces, etc, and i believe can read
enums. Therefore, a perfect application of this object library would
be to create the functionality that I discussed above. All i would
have to do is pass the path of the DLL or TLB file, and the name of
the enum, and the function would return the conversion functions.

Has anyone done this? Any help would be appreciated.


For example, it should automatically accept an Enum like this:


Public Enum cbfPhase
cbfNotAPhase
cbfNotStarted
cbfParsed
cbfBeta
cbfData
cbfDone
End Enum

And turn it into these:

Public Function cbfPhaseToString(ByVal Value As cbfPhase) As String
' Method for converting cbfPhase values into a String.
Select Case Value
Case cbfNotAPhase
cbfPhaseToString = "NotAPhase"
Case cbfNotStarted
cbfPhaseToString = "NotStarted"
Case cbfParsed
cbfPhaseToString = "Parsed"
Case cbfBeta
cbfPhaseToString = "Beta"
Case cbfData
cbfPhaseToString = "Data"
Case cbfDone
cbfPhaseToString = "Done"
End Select
End Function


Public Function StringTocbfPhase(ByVal Value As String) As cbfPhase
' Method for converting a String into cbfPhase.
Select Case Value
Case "NotAPhase"
StringTocbfPhase = cbfNotAPhase
Case "NotStarted"
StringTocbfPhase = cbfNotStarted
Case "Parsed"
StringTocbfPhase = cbfParsed
Case "Beta"
StringTocbfPhase = cbfBeta
Case "Data"
StringTocbfPhase = cbfData
Case "Done"
StringTocbfPhase = cbfDone
End Select
End Function


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default programmatic generation of Enum To String functions

Thanks Jake. Using this would enable the automatic generation of the
functions above for Enums in DLLs. This is precisely what i need.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
STRING functions anar_baku Excel Worksheet Functions 4 November 8th 05 05:05 PM
Enum Daniel[_4_] Excel Programming 3 December 22nd 03 12:30 AM
Enum in Excel 97 Rob Bovey Excel Programming 0 September 26th 03 11:02 PM
Enum in Excel 97 Chip Pearson Excel Programming 0 September 26th 03 10:03 PM


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"