As Constant As The Wind

I had an odd problem with VBA today.

I used a table driven menu builder (don’t we all), and I define the column numbers of that table in an enumerated list.  This is that list

Private Enum CB_COLUMNS
    CB_LEVEL_COL = 1
    CB_TAG_COL = 4
    CB_TYPE_COL = 12
    CB_DEBUG_COL = 13
End Enum

I was making some changes to the application today, and I suddenly got an error where the values in this list were being used, an error suggesting that a constant expression was required (sic!).

Very odd. How did I fix it? I changed the enum scope from Private to Public, and then my application compiled fine. I set it back to Private and it still compiled fine, and is working okay again.

Anyone else ever seen this?

8 thoughts on “As Constant As The Wind

  1. I code clean my apps every build, so I like to think my apps are healthy. But of course, I cannot tell as I cannot reproduce it at will. Odd though.

  2. @Jan Karel, how do you know Code Cleaner did not suffice? Was a continuation of odd problems like the one I describe?

    As it happens, this is a problem I do get quite often, but normally in my procedures where I declare a constant with the procedure name. I get this same error and have to remove the constant completely, and re-enter it.

  3. Bob that sounds like a name registration conflict. It sounds like the compiled version of your code is not getting fully updated – leaving in the old scope version.
    Does it go away if you comment out all the option explicits compile and uncomment and recompile? (thats to best way I know of forcing a full compile)

  4. @Simon, it is hard to say as I cannot force the issue, it just happens. I will try what you say, but I am not sure what it will prove if t does work thereafter, my approach works already (although I don’t know how or why – maybe I am forcing a full re-compile).

    If I am going to strip out all the Option Explicits and then put them back again I am going to have to write code to do thsi .

Leave a Reply

Your email address will not be published. Required fields are marked *