如何获得枚举中各元素的名称和UDT中各元素的名称、值
下面两段是我的代码,为了列出枚举的名称,以及UDT(用户自定义类型)中的各元素名称及值,每次都写一大段代码,如果遇到元素很多,简直是要命!!!
我的问题是:如何实现给定的枚举变量(指针),或UDT变量(指针),然后列举出各元素名称,如果 是UDT再列出其值。
就是实现 VBE 中的 IntelliSense 下拉式属性或方法列表。 --------------------编程问答-------------------- 下面两段代码,是我写的
代码1,获得指定枚举的元素名称
Public Function GetDAODataTypeName(ByVal DAOType As DAO.DataTypeEnum) As String
Select Case DAOType
Case dbBoolean
GetDAODataTypeName = "dbBoolean"
Case dbByte
GetDAODataTypeName = "dbByte"
Case dbLong
GetDAODataTypeName = "dbLong"
Case dbInteger
GetDAODataTypeName = "dbInteger" 'SMALLINT SHORT
Case dbCurrency
GetDAODataTypeName = "dbCurrency"
Case dbSingle
GetDAODataTypeName = "dbSingle"
Case dbDouble
GetDAODataTypeName = "dbDouble"
Case dbDate
GetDAODataTypeName = "dbDate"
Case dbText
GetDAODataTypeName = "dbText"
Case dbMemo
GetDAODataTypeName = "dbMemo"
Case dbDecimal
GetDAODataTypeName = "dbDecimal"
Case dbGUID
GetDAODataTypeName = "dbGUID"
Case dbBinary
GetDAODataTypeName = "dbBinary"
Case dbLongBinary
GetDAODataTypeName = "dbLongBinary"
Case vbEmpty '值未初始化 '这种对象不支持该操作
GetDAODataTypeName = "值未初始化"
Case Else '为空时,不被支持的或未知的数据类型
'GetDAODataTypeName = ""
Err.Raise vbObjectError + 100, "GetDAODataTypeName", ""
End Select
End Function
代码2,获得UDT中各元素名称和其值
Public Type DEVMODE
strDeviceName(1 To CCHDEVICENAME) As Byte
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intYResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName(1 To CCHFORMNAME) As Byte
lngLogPixels As Long
lngBitsPerPel As Long
lngPelsWidth As Long
lngPelsHeight As Long
lngDisplayFlags As Long
lngdmNup As Long
lngDisplayFrequency As Long
End Type
Private Function PrintPrtDevMode(FormOrReportName As String, DevModeType As DEVMODE) As String
Dim strRet As String
strRet = "With " & FormOrReportName & ".PrtDevMode"
With DevModeType
strRet = strRet & vbNewLine & vbTab & ".strDeviceName=" & StrConv(.strDeviceName, vbUnicode)
strRet = strRet & vbNewLine & vbTab & ".intSpecVersion=" & .intSpecVersion
strRet = strRet & vbNewLine & vbTab & ".intDriverVersion=" & .intDriverVersion
strRet = strRet & vbNewLine & vbTab & ".intSize=" & .intSize
strRet = strRet & vbNewLine & vbTab & ".intDriverExtra=" & .intDriverExtra
strRet = strRet & vbNewLine & vbTab & ".lngFields=" & .lngFields
strRet = strRet & vbNewLine & vbTab & ".intOrientation=" & .intOrientation
strRet = strRet & vbNewLine & vbTab & ".intPaperSize=" & .intPaperSize
strRet = strRet & vbNewLine & vbTab & ".intPaperLength=" & .intPaperLength
strRet = strRet & vbNewLine & vbTab & ".intPaperWidth=" & .intPaperWidth
strRet = strRet & vbNewLine & vbTab & ".intScale=" & .intScale
strRet = strRet & vbNewLine & vbTab & ".intCopies=" & .intCopies
strRet = strRet & vbNewLine & vbTab & ".intDefaultSource=" & .intDefaultSource
strRet = strRet & vbNewLine & vbTab & ".intPrintQuality=" & .intPrintQuality
strRet = strRet & vbNewLine & vbTab & ".intColor=" & .intColor
strRet = strRet & vbNewLine & vbTab & ".intDuplex=" & .intDuplex
strRet = strRet & vbNewLine & vbTab & ".intYResolution=" & .intYResolution
strRet = strRet & vbNewLine & vbTab & ".intTTOption=" & .intTTOption
strRet = strRet & vbNewLine & vbTab & ".intCollate=" & .intCollate
strRet = strRet & vbNewLine & vbTab & ".strFormName=" & StrConv(.strFormName, vbUnicode)
strRet = strRet & vbNewLine & vbTab & ".lngLogPixels=" & .lngLogPixels
strRet = strRet & vbNewLine & vbTab & ".lngBitsPerPel=" & .lngBitsPerPel
strRet = strRet & vbNewLine & vbTab & ".lngPelsWidth=" & .lngPelsWidth
strRet = strRet & vbNewLine & vbTab & ".lngPelsHeight=" & .lngPelsHeight
strRet = strRet & vbNewLine & vbTab & ".lngDisplayFlags=" & .lngDisplayFlags
strRet = strRet & vbNewLine & vbTab & ".lngdmNup=" & .lngdmNup
strRet = strRet & vbNewLine & vbTab & ".lngDisplayFrequency=" & .lngDisplayFrequency
End With
PrintPrtDevMode = strRet & vbNewLine & "End With"
End Function
全是手动,要人命!
补充:VB , COM/DCOM/COM+