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_DESCRIPTOR = (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
LVL 1
KhrisEAsked:
Who is Participating?
 
gwgawConnect With a Mentor Commented:
You can make a type library and set a reference to it in the project
references. If it doesn't show up in the References dialog click the
Browse button and search for it on your system.

To make the type library, paste the code below into Notepad and save
it as "Regconst.odl" or whatever name you want to give it. The
extension must be odl. You may want to use GUIDGEN.EXE to create
your own guid. This can be found in your
Program Files\Microsoft Visual Studio\Common\Tools folder. Copy and paste
the guid from GUIDGEN between the parnes. Be sure to remove the braces.

Use MKTYPLIB.EXE to compile the odl file. Which is in the same folder
as GUIDGEN.EXE. To make this easy copy MKTYPLIB.EXE to your C: drive.
Then click Sart\Run and enter C:\mktyplib /nocpp Regconst.odl in
the Run dialog and click OK. If you want, copy Regconst.tlb to your
C:\Windows\System folder since this is the first place the References dialog
checks for type librarys, dlls, ect.

Once a reference has been set to Regconst.tlb, remove or comment your
Public Enums and your code should function as normal.


Paste this into Notepad...

[uuid(CADDCA84-A0F0-4292-88D7-EAC195358C32),
helpstring("Registry Constants Type Library"),
version(1.0)] library Regconst
{
typedef
[helpstring("Root key constants")]
enum
   {
   [helpstring("HKEY_CLASSES_ROOT")]
      HKEY_CLASSES_ROOT = 2147483648,
   [helpstring("HKEY_CURRENT_USER")]
      HKEY_CURRENT_USER = 2147483649,
   [helpstring("HKEY_LOCAL_MACHINE")]
      HKEY_LOCAL_MACHINE = 2147483650,
   [helpstring("HKEY_USERS")]
      HKEY_USERS = 2147483651,
   [helpstring("HKEY_PERFORMANCE_DATA")]
      HKEY_PERFORMANCE_DATA = 2147483652,
   [helpstring("HKEY_CURRENT_CONFIG")]
      HKEY_CURRENT_CONFIG = 2147483653,
   [helpstring("HKEY_DYN_DATA")]
      HKEY_DYN_DATA = 2147483654,
   } ERegistryClassConstants;

typedef
[helpstring("Registry value type constants")]
enum
   {
   [helpstring("No value type")]
       REG_NONE = (0),
   [helpstring("Unicode nul terminated string")]
       REG_SZ = 1,
   [helpstring("Unicode nul terminated string w/enviornment var")]
      REG_EXPAND_SZ = 2,
   [helpstring("Free form binary")]
      REG_BINARY = 3,
   [helpstring("32-bit number")]
      REG_DWORD = 4,
   [helpstring("32-bit number (same as REG_DWORD)")]
      REG_DWORD_LITTLE_ENDIAN = 4,
   [helpstring("32-bit number")]
       REG_DWORD_BIG_ENDIAN = 5,
   [helpstring("Symbolic Link (unicode)")]
      REG_LINK = (6),
   [helpstring("Multiple Unicode strings")]
      REG_MULTI_SZ = 7,
   [helpstring("Resource list in the resource map")]
      REG_RESOURCE_LIST = 8,
   [helpstring("Resource list in the hardware description")]
      REG_FULL_RESOURCE_DESCRIPTOR = 9,
   [helpstring("REG_RESOURCE_REQUIREMENTS_LIST")]
      REG_RESOURCE_REQUIREMENTS_LIST = 10,
   } ERegistryValueTypes;

};

0
 
q2eddieCommented:
Hi, 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
0
 
KhrisEAuthor Commented:
thanks for your comments ... I have a feeling that its simply not compatible - see how we go

KhrisE
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sharmonCommented:
Can you give a little more detail.  Worked fine for me with Excel 2k.
0
 
KhrisEAuthor Commented:
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
0
 
criCommented:
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_DESCRIPTOR 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
0
 
blakeh1Commented:
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
0
 
KhrisEAuthor Commented:
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
0
All Courses

From novice to tech pro — start learning today.