Thread: Enum bug?
View Single Post
  #5   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 14:34:58 -0700 (PDT), Dave Unger wrote:

I think you mis-understood my point in this post. In the macro below
I have an un-declared variable "nam3". I would expect to get a
compile error , but I don't. It thinks I'm referencing List2.nam3.
On a large application this could be a real nuisance to locate.

Public Enum List2
nam1 = 11
nam3 = 33
End Enum

Sub Test()
Debug.Print nam3
End Sub

regards,

Dave U


I see what you mean. But this is not unique to user declared Enum's. It can also happen with other constants that are part of the system, but not explicitly declared. You don't get a compile error because the compiler can interpret the constant. One purpose behind Enum is so that you can set up your own set of constants. But neither these nor the vb constants are "reserved words", so if you use Dim them within a module, that will take precedence; and if you don't VB thinks you are calling a constant that has already been defined.

For example:

--------------------------------
Sub test()
debug.print xlErrNA
End Sub

-----------------------------
Sub test()
Dim xlErrNA As String

xlErrNA = "foobar"
Debug.Print xlErrNA
Debug.Print XlCVError.xlErrNA
End Sub

--------------------------------------------