KhrisE
asked on
VB to VBA conversion Help
I copied some code from this vb forum in the hope it was useful in some VBA code - all coding works fine except the following :
Public Enum ERegistryClassConstants
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum
Public Enum ERegistryValueTypes
' *** Predefined Value Types
REG_NONE = (0) ' *** No value type
REG_SZ = (1) ' *** Unicode nul terminated string
REG_EXPAND_SZ = (2) ' *** Unicode nul terminated string w/enviornment var
REG_BINARY = (3) ' *** Free form binary
REG_DWORD = (4) ' *** 32-bit number
REG_DWORD_LITTLE_ENDIAN = (4) ' *** 32-bit number (same as REG_DWORD)
REG_DWORD_BIG_ENDIAN = (5) ' *** 32-bit number
REG_LINK = (6) ' *** Symbolic Link (unicode)
REG_MULTI_SZ = (7) ' *** Multiple Unicode strings
REG_RESOURCE_LIST = (8) ' *** Resource list in the resource map
REG_FULL_RESOURCE_DESCRIPT OR = (9) ' *** Resource list in the hardware description
REG_RESOURCE_REQUIREMENTS_ LIST = (10)
End Enum
Why wont this compile in VBA ??
How can I fix it so that the code sompiles for functionally the same type (ie an enumerated type)
KhrisE
Public Enum ERegistryClassConstants
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum
Public Enum ERegistryValueTypes
' *** Predefined Value Types
REG_NONE = (0) ' *** No value type
REG_SZ = (1) ' *** Unicode nul terminated string
REG_EXPAND_SZ = (2) ' *** Unicode nul terminated string w/enviornment var
REG_BINARY = (3) ' *** Free form binary
REG_DWORD = (4) ' *** 32-bit number
REG_DWORD_LITTLE_ENDIAN = (4) ' *** 32-bit number (same as REG_DWORD)
REG_DWORD_BIG_ENDIAN = (5) ' *** 32-bit number
REG_LINK = (6) ' *** Symbolic Link (unicode)
REG_MULTI_SZ = (7) ' *** Multiple Unicode strings
REG_RESOURCE_LIST = (8) ' *** Resource list in the resource map
REG_FULL_RESOURCE_DESCRIPT
REG_RESOURCE_REQUIREMENTS_
End Enum
Why wont this compile in VBA ??
How can I fix it so that the code sompiles for functionally the same type (ie an enumerated type)
KhrisE
ASKER
thanks for your comments ... I have a feeling that its simply not compatible - see how we go
KhrisE
KhrisE
Can you give a little more detail. Worked fine for me with Excel 2k.
ASKER
I'm using this in a Word 97 document - it compiles fine in VB5 and 6 but not vb4 - so I think it is version related - press f1 and tell me what the help file says - mine says the topic does not exist (when I sit the cursor in the word "enum")
KhrisE
KhrisE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is declaring them as Public Constants of any use ?
Option Explicit
'Enum not used as introduced with VBA 6, i.e. code would fail for Word 97...
'ERegistryClassConstants
Public Const HKEY_CLASSES_ROOT As String = "&H80000000"
Public Const HKEY_CURRENT_USER As String = "&H80000001"
Public Const HKEY_LOCAL_MACHINE As String = "&H80000002"
Public Const HKEY_USERS As String = "&H80000003"
Public Const HKEY_PERFORMANCE_DATA As String = "&H80000004"
Public Const HKEY_CURRENT_CONFIG As String = "&H80000005"
Public Const HKEY_DYN_DATA As String = "&H80000006"
'ERegistryValueTypes
' *** Predefined Value Types
Public Const REG_NONE As Integer = 0 ' *** No value type
Public Const REG_SZ As Integer = 1 ' *** Unicode nul terminated string
Public Const REG_EXPAND_SZ As Integer = 2 ' *** Unicode nul terminated string w/enviornment var
Public Const REG_BINARY As Integer = 3 ' *** Free form binary
Public Const REG_DWORD As Integer = 4 ' *** 32-bit number
Public Const REG_DWORD_LITTLE_ENDIAN As Integer = 4 ' *** 32-bit number (same as REG_DWORD)
Public Const REG_DWORD_BIG_ENDIAN As Integer = 5 ' *** 32-bit number
Public Const REG_LINK As Integer = 6 ' *** Symbolic Link (unicode)
Public Const REG_MULTI_SZ As Integer = 7 ' *** Multiple Unicode strings
Public Const REG_RESOURCE_LIST As Integer = 8 ' *** Resource list in the resource map
Public Const REG_FULL_RESOURCE_DESCRIPT OR As Integer = 9 ' *** Resource list in the hardware description
Public Const REG_RESOURCE_REQUIREMENTS_ LIST As Integer = 10
Sub test()
MsgBox REG_NONE
End Sub
Option Explicit
'Enum not used as introduced with VBA 6, i.e. code would fail for Word 97...
'ERegistryClassConstants
Public Const HKEY_CLASSES_ROOT As String = "&H80000000"
Public Const HKEY_CURRENT_USER As String = "&H80000001"
Public Const HKEY_LOCAL_MACHINE As String = "&H80000002"
Public Const HKEY_USERS As String = "&H80000003"
Public Const HKEY_PERFORMANCE_DATA As String = "&H80000004"
Public Const HKEY_CURRENT_CONFIG As String = "&H80000005"
Public Const HKEY_DYN_DATA As String = "&H80000006"
'ERegistryValueTypes
' *** Predefined Value Types
Public Const REG_NONE As Integer = 0 ' *** No value type
Public Const REG_SZ As Integer = 1 ' *** Unicode nul terminated string
Public Const REG_EXPAND_SZ As Integer = 2 ' *** Unicode nul terminated string w/enviornment var
Public Const REG_BINARY As Integer = 3 ' *** Free form binary
Public Const REG_DWORD As Integer = 4 ' *** 32-bit number
Public Const REG_DWORD_LITTLE_ENDIAN As Integer = 4 ' *** 32-bit number (same as REG_DWORD)
Public Const REG_DWORD_BIG_ENDIAN As Integer = 5 ' *** 32-bit number
Public Const REG_LINK As Integer = 6 ' *** Symbolic Link (unicode)
Public Const REG_MULTI_SZ As Integer = 7 ' *** Multiple Unicode strings
Public Const REG_RESOURCE_LIST As Integer = 8 ' *** Resource list in the resource map
Public Const REG_FULL_RESOURCE_DESCRIPT
Public Const REG_RESOURCE_REQUIREMENTS_
Sub test()
MsgBox REG_NONE
End Sub
FYI, If declaring as public constant will also have to go thru the code and change any dim statements that ref those enums, such as
Dim a As ERegistryClassConstants
a = HKEY_CLASSES_ROOT
will have to be changed to
Dim a long
a = HKEY_CLASSES_ROOT
Dim a As ERegistryClassConstants
a = HKEY_CLASSES_ROOT
will have to be changed to
Dim a long
a = HKEY_CLASSES_ROOT
ASKER
gwgaw : Sorry totake so long to come back
Do I need to distribute the compiled file with the setup ? If so do I simply place it in the windows\system directory
KhrisE
Do I need to distribute the compiled file with the setup ? If so do I simply place it in the windows\system directory
KhrisE
I noticed that nowhere in this page does it mention the enum keyword. I tried it in Excel 97 and found that the enum keyword was not recognized in the VB Editor. It didn't matter where I put it: Workbook, Module, or Class Module.
You should keep this question open for a while so that other experts may find it tomorrow. Also, you could post a zero-point question in the MS Office topic area with a link leading back to this question.
#Links
1. "Public Statement" (Office 97 Reference)
http://msdn.microsoft.com/library/default.asp?URL=/library/officedev/office97/output/F1/D6/S5B28E.HTM
Bye. -e2