Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB to VBA conversion Help

Posted on 2001-06-17
8
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 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