Starwatcher
Starwatcher

Reputation: 842

VB6 IDE is changing the case of my enumeration names

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?

Upvotes: 6

Views: 1188

Answers (3)

Guillermo Phillips
Guillermo Phillips

Reputation: 2216

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.

Upvotes: 1

Kev
Kev

Reputation: 119856

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.

Upvotes: 1

Cyberherbalist
Cyberherbalist

Reputation: 12329

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.

Upvotes: 14

Related Questions