Variable Case issue

J

J Streger

I have a sheet where I originally created a global const as:

Global Const RAMPUP = "RU"

Well I decided that rather than that I wanted to do an enumeration. So I
deleted the global const and created:

Public enum TestTypes
RampUp
end enum

Except that after typing VBA gave me this:

Public enum TestTypes
RAMPUP
end enum

In fact, everytime I type rampup in the code it becomes capitalized. I did a
search and it exists nowhere in my code. Excel doesn't show it in the object
browser, and I restarted Excel, but it seems to have a die hard memory that
rampup = RAMPUP. It's done this with 3 other variables I made Global
constants and then deleted. Is there a way to stop this from happening?


--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003
 
C

Chip Pearson

It is a known flaw in the VBA Editor (VB6 also) that when you type the name
of an enum member, the enum declaration is changed to match what you typed
rather than the opposite (correct) behavior.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 
B

Bob Phillips

.... and what a pain it is !!!!!

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
R

Rick Rothstein \(MVP - VB\)

It's a bug in the Enum function and it's very annoying (we have the same
sort of problem over in the compiled VB world, but it's a little bit worse
over there). Unlike other dimensioning statements in VBA (or compiled VB)
which force the casing used to dimension the variable's name, Enum variable
names take the casing of the last time their variable name was declared
anywhere else (in the compiled VB world, the casing changes to the last time
the Enum's variable was typed, whether inside a dimensioning statement or
not). You can see this with your own situation. Put this code in any code
window...

Sub Test()
Dim RaMpUp as String
End Sub

but make sure you type the variable name (don't just copy it). Now go look
at the variable name in the Enum block. Notice that the casing of the Enum's
variable name has become what was used in the Dim statement of the Test
subroutine. Go back to the Test subroutine and change RaMpUp to rampup this
time; now look at what happened to the variable name in the Enum block.
There is no way to stop this from happening. However, as you can see, you
can "fix" your Enum's variable name casing by putting a Dim statement with
the correct casing somewhere and then deleting it.

Rick
 
R

Rick Rothstein \(MVP - VB\)

It is a known flaw in the VBA Editor (VB6 also) that when you type the
name of an enum member, the enum declaration is changed to match what you
typed rather than the opposite (correct) behavior.

It seems to work a little bit differently in my copy of XL2003. Yes, in VB6,
the last time you type the Enum's member name in any statement, the casing
in the Enum changes to match it; however, in my copy of Excel, that only
seems to happen when I type the Enum's member's name in a dimensioning
statement (such as Dim)... using the member's name in a plain
(non-dimensioning) statement seems to always adopt the Enum's casing.

Rick
 
J

J Streger

Thank you all. And I agree, it is quite a pain.

But at least I can work around it.
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003
 
A

Andy Pope

Hi,

The problem is more subtle than just the toggling of case whenever you type
the enum member.

Try this example;
Enter the following at the top of a code module.

'-----------
Const hElLo = 1
Enum XX
hElLo
End Enum
'-----------

Then delete the const and try changing the text to HELLO. It remembers the
const case structure.

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top