Solved

VB to VBA conversion Help

Posted on 2001-06-17
8
245 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:KhrisE
8 Comments
 
LVL 7

Expert Comment

by:q2eddie
ID: 6199520
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
 
LVL 1

Author Comment

by:KhrisE
ID: 6199538
thanks for your comments ... I have a feeling that its simply not compatible - see how we go

KhrisE
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6199539
Can you give a little more detail.  Worked fine for me with Excel 2k.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:KhrisE
ID: 6199596
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
 
LVL 5

Accepted Solution

by:
gwgaw earned 100 total points
ID: 6199932
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
 
LVL 13

Expert Comment

by:cri
ID: 6200239
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
 
LVL 6

Expert Comment

by:blakeh1
ID: 6202879
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
 
LVL 1

Author Comment

by:KhrisE
ID: 6363813
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question