我想在这里声明类globaly是我的例子:
我想使用看起来完全像这样的类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
这就是它的工作原理example1:
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
为什么公共默认方法不起作用?
2 回答
我可以确认这不像你描述的那样有用 . 我在运行时得到“预期的过程,而不是变量”,但没有编译错误 . 它必须是VB解析器中的一个错误,但这是我能想到的唯一解释 .
我一直认为该属性必须与元素名称匹配 . 你在哪里
我以为你应该有
但它似乎工作(使用本地声明的变量)两种方式 . 这是一个可怕的答案,但答案是明确地调用该方法 . 抱歉 .
我不确定它会明确地回答你的问题,但是,对于我来说,我想创建一个可以在我的项目中访问的类的实例 . 基本上我需要创建静态类或单例 . 我发现这个post非常有用 .