tags:

views:

253

answers:

3

I'm required to maintain a few VB6 apps, and I have run into a weird problem when it comes to enumeration names. The way Intellisense in VB6 is supposed to work is that if my variable name is defined as, say, Dim Abraxis as String, and I type abraxis while coding, the IDE changes it to Abraxis on the fly as I leave the word. However, I have found that if I have an enumeration set up like this, for example:

Public Enum tiErrorEnum
  tiNone = 0
  tiWarning
  tiError
  tiDupDoc
End Enum

and I use one of the enums in a statement, such as

ErrorNum = tinone

expecting the casing to be fixed by the IDE, it doesn't change tinone to tiNone, but it does change the def of the enum member to tinone! Exactly backwards!

Is there a workaround?

+9  A: 

Yes, there is. It's kind of odd-looking, and you probably want to comment on why you're doing it in your code so future devs don't get perplexed about it, but here's what you want to do. Add the enumerations as Public items inside a compiler directive code block (so the compiler can't see it, of course). You should do this preferably right below the enumeration declaration, like this:

Public Enum tiErrorEnum
  tiNone = 0
  tiWarning
  tiError
  tiDupDoc
End Enum
#If False Then
  Public tiNone
  Public tiWarning
  Public tiError
  Public tiDupDoc
#End If

Simple. The IDE will recognize and hold the enumeration names correctly, and the compiler will ignore the block.

Cyberherbalist
+1 - Wish I'd thought about that all them years ago
Kev
I saw that happening and could never understand how to work around it. Love your solution, very hackish.
Manuel Ferreria
+1  A: 

This is a bug in the editor. I seem to remember that if you type the name of an enum rather than use the intellisense it changes the case of the enum value name in the declaration.

Kev
+1  A: 

The trick is to always qualify your enumerations:

tiErrorEnum.tiDupDoc

Intellisense will then correctly list the enumeration after pressing dot. I think this will also aid code readability if you enumeration is well named.

Jonathan Swift