Re: VB6 compile error "constant expression required" with enum - solution



"David Carr" <David_Carr@xxxxxxxxxxxxxxxx>'s wild thoughts
were released on Mon, 10 Jul 2006 19:21:51 -0700 bearing the
following fruit:

Dredging newsgroups on Google, it would seem that this is a bug in the VB
IDE. Rather than lose your breakpoints/bookmarks, consider Jeff Ashley's
posting back on 2000.Apr.12, as it seems to do the trick:

When this happens: Put the cursor on the highlighted value, Shift f2.
On the enum line, put the cursor after 'enum', spacebar, arrow down.
(Any other edit of the line works too.) VB will insist on starting the
compile over, but you will be under way in 10 seconds or less. No need
to shut down the app!

Posting for future reference and to keep this thread around.

I've got a better way, it also solves the problem of VB
ajusting the case of you enumerations

#If 1 = 2 Then
Private Const item1 = 0
Private Const item2 = 1
Private Const item3 = 2
#End If

Private Enum enumBlahBlah
item1 = 0
item2 = 1
item3 = 2
End Enum

Since the first block of code will never be compiled you
don't have to worry about it, but it tricks VB and stops the
error your refering to from happening.

J



"David Carr" <David_Carr@xxxxxxxxxxxxxxxx> wrote in message
news:unz9Z7IpGHA.4032@xxxxxxxxxxxxxxxxxxxxxxx
In my VB6 sp6 application I have an enumeration defined:

Public Enum MyEnum
eVal1 = 0
eVal2
End Enum

And this is used in the code in a select statement:

Select Case mScenType
Case MyEnum.eVal2

All is fine and the program compiles. After some time (e.g. an hour or a
few hours) of debugging, I end up having a VB compile error "constant
expression required", where the IDE highlights the 'eVal2' part of the
Case statement above. There does not appear to be any consistency in this
behaviour. Shutting down VB6 and restarting seems to solve the problem -
unfortunate as this means losing your breakpoints and bookmarks.

Any ideas?

David




Jan Hyde (VB MVP)

--
Too many youngsters between the ages of 12 and 20 are in their
nico-teens. (Lloyd Clark)

.



Relevant Pages

  • Re: passing enum value as an argument
    ... >> safety at all (at compile time) when you've got option strict turned ... the whole point of enums - because that dismisses type safety as being ... For you to get the benefits of an Enum, ... > Dim SomeVariable as Juan ...
    (microsoft.public.dotnet.general)
  • 3 .class files generated for 1 .java file
    ... I wrote the following code to get more type-safe C++-equivalent enum in Java. ... Whenever I compile this code, 3 class files are generated. ...
    (comp.unix.solaris)
  • 3 .class files generated for 1 .java file
    ... I wrote the following code to get more type-safe C++-equivalent enum in Java. ... Whenever I compile this code, 3 class files are generated. ...
    (comp.lang.java.programmer)
  • "Error reflecting type" message in custom class.
    ... enum vary from class to class, but the enum is used for the same ... When I compile this class along with the rest of my solution in debug ... 'MMIT.Applications.GUS.Common.Address.ReferenceIDType' both use the XML ... specify a unique XML name and/or namespace for the type. ...
    (microsoft.public.dotnet.framework)
  • Re: Does anybody have a listing of the MS constants such as WM_KEYDOWN and WM_SYSKEYDOWN
    ... Private Enum WindowsMessage ... | If you have Visual Studio 6 there is an API viewer which lists all the ... Here's the list from the API Viewer: ...
    (microsoft.public.dotnet.languages.vb)