【发布时间】:2013-01-23 13:43:10
【问题描述】:
我想在全球范围内声明类 这是我的例子:
我想使用看起来像这样的类 clsIEError:
Option Explicit
Public Sub m(msg As String, Optional title As String = "Title:")
'Attribute Value.VB_UserMemId = 0
'this method will be used as defualt method
'and here are attributes msg and title used to create some inteface
End Sub
这就是它的工作原理示例1:
Sub CATMain()
Dim ie As clsIEError
Set ie = New clsIEError
ie "test", "title"
Set ie = Nothing
End Sub
但我的问题是我想在全球范围内拥有它示例2:
Option Explicit
Public ie As clsIEError
Private Function Init()
Set ie = New clsIEError
End Function
Sub CATMain()
Call Init
' and to use it same as in example 1
ie "test", "title"
' but i am able to use it only like:
' ie.m "test", "title" 'works as expected
Set ie = Nothing
End Sub
为什么使用公共默认方法不起作用?
【问题讨论】:
-
为什么首先创建
classes? -
我认为不重要,但在这种情况下,我有一些自定义用户界面,我想在不同的模块中使用。
-
你能告诉我们你真正想使用的代码吗?
-
而不是' ie.m "test", "title" '我想用它作为' ie "test", "title" ',公开声明,仅此而已
-
我不知道 catia VBA 编辑器,但如果您在 MS office 中执行此操作或 Catia 类似,您不能仅在代码中提供属性 - 不幸的是,您需要导出类,使用 Attribute 行编辑文本文档,然后将其导入回来(该行隐藏在编辑器中) - 请参阅cpearson.com/excel/DefaultMember.aspx 虽然我同意示例一个也不应该工作......:-/