Thread: Enum bug?
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron Rosenfeld[_2_] Ron Rosenfeld[_2_] is offline
external usenet poster
 
Posts: 1,045
Default Enum bug?

On Wed, 13 Apr 2011 12:32:00 -0700 (PDT), Dave Unger wrote:

Hello,

I’m just wondering if anyone else has come across this Enum “quirk”.
Tested on XL2003 & 2010.

Option Explicit

Public Enum List1
nam1 = 11
nam2 = 22
End Enum

Public Enum List2
nam1 = 11
nam3 = 33
End Enum

Scenario 1:
Sub Test ()
Debug.Print nam1
End Sub
Do a compile. I was expecting a “Compile error: Variable not defined”
message, but got “Compile error: Ambiguous name detected: nam1”
message instead.

Scenario 2:
Sub Test()
Debug.Print nam3
End Sub

This did NOT generate a compile error, but printed “33” when executed.

Scenario 3:
Sub Test()
Dim nam3 As Long
nam3 = 99
Debug.Print nam3
End Sub

Of course, this one compiled without error and printed “99” on
execution.

In the past I’ve depended on the compiler to pick up missed
declarations, but it seems this can’t be relied on when Enums are
involved.

Any comments appreciated.

Regards,

Dave U



It also works the same way on 2007.

With the ambiguous name issue, you would need to refer to the Enum you want:

debug.print List1.nam1

I don't understand what you mean be a "missed declaration".