在VBA自定义类模块中(并通过扩展VB6?),如果在同一个类中有一个定义为公共枚举的私有实例变量,那么它是否应该是限定的。。?如果是,怎么。。?
我经常有相同类型的项目引用。例如,Excel和Word都有
Range
反对。因此,我在声明变量时总是尽可能具体,比如
Excel.Range
或
Word.Range
,而不仅仅是
Dim R As Range
.
但是计数呢。。?如何具体说明这些。。?我试图将变量限定为枚举,但总是会得到一个错误。我尝试将枚举定义移动到另一个自定义类,但这没有帮助。我不经常为VBA创建类,所以我可能用这个错误的树。
如果我符合
Me.
关键字,我得到错误:
"Compile error: Expected New or type name."
如果我符合自定义类名的条件,就会得到错误:
"Compile error: User-defined type not defined"
下面是一个完整的例子:
'Custom class module.
Option Explicit
Public Enum ImageAspect
ImageAspectHorizontal
ImageAspectVertical
End Enum
' Example 1:
' Qualified to use built-in Excel enumeration. This works.
Private logoAspect1 As Excel.XlOrientation
' Example 2:
' Uses the enum defined in this class. This works, but...
' Can this be qualified..? How..? Is it even necessary?
Private logoAspect2 As ImageAspect
' Example 3:
' This does not work.
Private logoAspect3 As Me.ImageAspect
' Example 4:
' This does not work.
Private logoAspect4 As ThisClass.ImageAspect
Public Property Let Aspect(ByVal pAspect As ImageAspect)
logoAspect2 = pAspect
End Property
Public Property Get Aspect() As ImageAspect
Set Aspect = logoAspect2
End Property